Skip to content

Commit 4a347ce

Browse files
authored
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
1 parent b616b97 commit 4a347ce

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Tools/scripts/patchcheck.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@
1111
import untabify
1212

1313

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

23+
1624
def n_files_str(count):
1725
"""Return 'N file(s)' with the proper plurality on 'file'."""
1826
return "{} file{}".format(count, "s" if count != 1 else "")
@@ -98,7 +106,7 @@ def changed_files(base_branch=None):
98106
if mq_patches_applied():
99107
cmd += ' --rev qparent'
100108
with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st:
101-
return [x.decode().rstrip() for x in st.stdout]
109+
filenames = [x.decode().rstrip() for x in st.stdout]
102110
elif os.path.exists(os.path.join(SRCDIR, '.git')):
103111
# We just use an existence check here as:
104112
# directory = normal git checkout/clone
@@ -120,10 +128,20 @@ def changed_files(base_branch=None):
120128
# file is renamed
121129
filename = filename.split(' -> ', 2)[1].strip()
122130
filenames.append(filename)
123-
return filenames
124131
else:
125132
sys.exit('need a Mercurial or git checkout to get modified files')
126133

134+
filenames2 = []
135+
for filename in filenames:
136+
# Normalize the path to be able to match using .startswith()
137+
filename = os.path.normpath(filename)
138+
if any(filename.startswith(path) for path in EXCLUDE_DIRS):
139+
# Exclude the file
140+
continue
141+
filenames2.append(filename)
142+
143+
return filenames2
144+
127145

128146
def report_modified_files(file_paths):
129147
count = len(file_paths)

0 commit comments

Comments
 (0)