8000 gh-105540: Show source files relative to root (#106927) · python/cpython@1218910 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1218910

Browse files
authored
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.
1 parent 60e8396 commit 1218910

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Tools/cases_generator/generate_cases.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import parser
1818
from parser import StackEffect
1919

20+
2021
HERE = os.path.dirname(__file__)
2122
ROOT = os.path.join(HERE, "../..")
2223
THIS = os.path.relpath(__file__, ROOT).replace(os.path.sep, posixpath.sep)
@@ -1153,10 +1154,15 @@ def write_function(
11531154
self.out.emit("")
11541155

11551156
def from_source_files(self) -> str:
1156-
paths = f"\n{self.out.comment} ".join(
1157-
prettify_filename(filename)
1158-
for filename in self.input_filenames
1159-
)
1157+
filenames = []
1158+
for filename in self.input_filenames:
1159+
try:
1160+
filename = os.path.relpath(filename, ROOT)
1161+
except ValueError:
1162+
# May happen on Windows 5C80 if root and temp on different volumes
1163+
pass
1164+
filenames.append(filename)
1165+
paths = f"\n{self.out.comment} ".join(filenames)
11601166
return f"{self.out.comment} from:\n{self.out.comment} {paths}\n"
11611167

11621168
def write_provenance_header(self):

0 commit comments

Comments
 (0)
0