]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105540: Show source files relative to root (#106927)
authorGuido van Rossum <guido@python.org>
Thu, 20 Jul 2023 23:08:52 +0000 (16:08 -0700)
committerGitHub <noreply@github.com>
Thu, 20 Jul 2023 23:08:52 +0000 (23:08 +0000)
This restores a corner case: when the generator is run with working directory set to Tools/cases_generator, the source filenames listed in the generated provenance header should be relative to the repo root directory.

Tools/cases_generator/generate_cases.py

index a18229a57143b8b08f8c64b9c605045bd000d4ba..3a679b2090f19beffb45575539090e6309034eef 100644 (file)
@@ -17,6 +17,7 @@ import lexer as lx
 import parser
 from parser import StackEffect
 
+
 HERE = os.path.dirname(__file__)
 ROOT = os.path.join(HERE, "../..")
 THIS = os.path.relpath(__file__, ROOT).replace(os.path.sep, posixpath.sep)
@@ -1153,10 +1154,15 @@ class Analyzer:
         self.out.emit("")
 
     def from_source_files(self) -> str:
-        paths = f"\n{self.out.comment}   ".join(
-            prettify_filename(filename)
-            for filename in self.input_filenames
-        )
+        filenames = []
+        for filename in self.input_filenames:
+            try:
+                filename = os.path.relpath(filename, ROOT)
+            except ValueError:
+            # May happen on Windows if root and temp on different volumes
+                pass
+            filenames.append(filename)
+        paths = f"\n{self.out.comment}   ".join(filenames)
         return f"{self.out.comment} from:\n{self.out.comment}   {paths}\n"
 
     def write_provenance_header(self):