gh-105540: Show source files relative to root (#106927)

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.
This commit is contained in:
Guido van Rossum 2023-07-20 16:08:52 -07:00 committed by GitHub
parent 60e83968d5
commit 1218910860
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,6 +17,7 @@
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 @@ def write_function(
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):