Skip to content

Commit d45cb04

Browse files
authored
[2.7] bpo-31221: patchcheck ignores external libraries (#3109) (#3118)
* bpo-31221: patchcheck ignores external libraries (#3109) Tools/scripts/patchcheck.py now ignores changes in directories which are copies of external libraries: * Modules/_ctypes/libffi_msvc/ * Modules/_ctypes/libffi_osx/ * Modules/_decimal/libmpdec/ * Modules/expat/ * Modules/zlib/ Drop also support for Mercurial, since CPython migrated to Git. Exclude also libmpdec patchcheck: exclude also libffi_osx and libffi_msvc (cherry picked from commit 4a347ce) * Exclude also Modules/_ctypes/libffi on Python 2.7 * Remove _decimal/libmpdec, not in Python 2.7
1 parent 3cc46bb commit d45cb04

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Tools/scripts/patchcheck.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@
1010
import untabify
1111

1212

13+
# Excluded directories which are copies of external libraries:
14+
# don't check their coding style
15+
EXCLUDE_DIRS = [os.path.join('Modules', '_ctypes', 'libffi'),
16+
os.path.join('Modules', '_ctypes', 'libffi_osx'),
17+
os.path.join('Modules', '_ctypes', 'libffi_msvc'),
18+
os.path.join('Modules', 'expat'),
19+
os.path.join('Modules', 'zlib')]
1320
SRCDIR = sysconfig.get_config_var('srcdir')
1421

22+
1523
def n_files_str(count):
1624
"""Return 'N file(s)' with the proper plurality on 'file'."""
1725
return "{} file{}".format(count, "s" if count != 1 else "")
@@ -102,7 +110,7 @@ def changed_files(base_branch=None):
102110
cmd += ' --rev qparent'
103111
st = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
104112
try:
105-
return [x.decode().rstrip() for x in st.stdout]
113+
filenames = [x.decode().rstrip() for x in st.stdout]
106114
finally:
107115
st.stdout.close()
108116
elif os.path.exists(os.path.join(SRCDIR, '.git')):
@@ -129,9 +137,19 @@ def changed_files(base_branch=None):
129137
filenames.append(filename)
130138
finally:
131139
st.stdout.close()
132-
return filenames
133140
else:
134-
sys.exit('need a checkout to get modified files')
141+
sys.exit('need a Mercurial or git checkout to get modified files')
142+
143+
filenames2 = []
144+
for filename in filenames:
145+
# Normalize the path to be able to match using .startswith()
146+
filename = os.path.normpath(filename)
147+
if any(filename.startswith(path) for path in EXCLUDE_DIRS):
148+
# Exclude the file
149+
continue
150+
filenames2.append(filename)
151+
152+
return filenames2
135153

136154

137155
def report_modified_files(file_paths):

0 commit comments

Comments
 (0)