gh-125084: Resolve paths in generator common code (GH-125085)

In out of tree builds, the paths can contain `../ which needs to be
resolved for the relative path calculation to work.
This commit is contained in:
Cody Maloney 2024-10-08 10:16:02 -07:00 committed by GitHub
parent fca552993d
commit 7dca7322cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 3 deletions

View File

@ -43,13 +43,13 @@ class TokenIterator:
break
return self.look_ahead
ROOT = Path(__file__).parent.parent.parent
DEFAULT_INPUT = (ROOT / "Python/bytecodes.c").absolute().as_posix()
ROOT = Path(__file__).parent.parent.parent.resolve()
DEFAULT_INPUT = (ROOT / "Python/bytecodes.c").as_posix()
def root_relative_path(filename: str) -> str:
try:
return Path(filename).absolute().relative_to(ROOT).as_posix()
return Path(filename).resolve().relative_to(ROOT).as_posix()
except ValueError:
# Not relative to root, just return original path.
return filename