diff options
author | Éric Araujo <merwok@netwok.org> | 2011-07-31 16:33:00 (GMT) |
---|---|---|
committer | Éric Araujo <merwok@netwok.org> | 2011-07-31 16:33:00 (GMT) |
commit | ad548b8534645ebb7590eb557c04d86814bde203 (patch) | |
tree | 054e0527512d7c6fcd59283d0a26a2b2173ef0ee /Tools | |
parent | 052c83cf058c0511810d96253d0d4c391d11be0a (diff) | |
parent | 548c054fb70c504150ec8bafa4503d6b4e74e535 (diff) | |
download | cpython-ad548b8534645ebb7590eb557c04d86814bde203.zip cpython-ad548b8534645ebb7590eb557c04d86814bde203.tar.gz cpython-ad548b8534645ebb7590eb557c04d86814bde203.tar.bz2 |
Merge fixes for #9860, #11104/#8688 and #12331 from 3.2
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/scripts/patchcheck.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Tools/scripts/patchcheck.py b/Tools/scripts/patchcheck.py index 8b0d3cd..b01f77c 100755 --- a/Tools/scripts/patchcheck.py +++ b/Tools/scripts/patchcheck.py @@ -4,11 +4,15 @@ import sys import shutil import os.path import subprocess +import sysconfig import reindent import untabify +SRCDIR = sysconfig.get_config_var('srcdir') + + def n_files_str(count): """Return 'N file(s)' with the proper plurality on 'file'.""" return "{} file{}".format(count, "s" if count != 1 else "") @@ -36,7 +40,7 @@ def status(message, modal=False, info=None): info=lambda x: n_files_str(len(x))) def changed_files(): """Get the list of changed or added files from the VCS.""" - if os.path.isdir('.hg'): + if os.path.isdir(os.path.join(SRCDIR, '.hg')): cmd = 'hg status --added --modified --no-status' else: sys.exit('need a checkout to get modified files') @@ -65,7 +69,7 @@ def normalize_whitespace(file_paths): """Make sure that the whitespace for .py files have been normalized.""" reindent.makebackup = False # No need to create backups. fixed = [path for path in file_paths if path.endswith('.py') and - reindent.check(path)] + reindent.check(os.path.join(SRCDIR, path))] return fixed @@ -74,10 +78,11 @@ def normalize_c_whitespace(file_paths): """Report if any C files """ fixed = [] for path in file_paths: - with open(path, 'r') as f: + abspath = os.path.join(SRCDIR, path) + with open(abspath, 'r') as f: if '\t' not in f.read(): continue - untabify.process(path, 8, verbose=False) + untabify.process(abspath, 8, verbose=False) fixed.append(path) return fixed @@ -88,13 +93,14 @@ ws_re = re.compile(br'\s+(\r?\n)$') def normalize_docs_whitespace(file_paths): fixed = [] for path in file_paths: + abspath = os.path.join(SRCDIR, path) try: - with open(path, 'rb') as f: + with open(abspath, 'rb') as f: lines = f.readlines() new_lines = [ws_re.sub(br'\1', line) for line in lines] if new_lines != lines: - shutil.copyfile(path, path + '.bak') - with open(path, 'wb') as f: + shutil.copyfile(abspath, abspath + '.bak') + with open(abspath, 'wb') as f: f.writelines(new_lines) fixed.append(path) except Exception as err: |