mirror of
https://github.com/python/cpython
synced 2024-09-16 03:49:58 +00:00
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:
parent
60e83968d5
commit
1218910860
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue