Éric Araujo  committed bea11ce

Let “make patchcheck” work for out-of-dir builds (#9860)

  • Participants
  • Parent commits 5a248fc
  • Branches 2.7

Comments (0)

Files changed (1)

File Tools/scripts/

 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 "")
         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')):
         vcs = 'hg'
         cmd = 'hg status --added --modified --no-status'
     elif os.path.isdir('.svn'):
     reindent.makebackup = False  # No need to create backups.
     fixed = []
     for path in (x for x in file_paths if x.endswith('.py')):
-        if reindent.check(path):
+        if reindent.check(os.path.join(SRCDIR, path)):
     return fixed
     """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
-        untabify.process(path, 8, verbose=False)
+        untabify.process(abspath, 8, verbose=False)
     return fixed
 def normalize_docs_whitespace(file_paths):
     fixed = []
     for path in file_paths:
+        abspath = os.path.join(SRCDIR, path)
-            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:
         except Exception as err: