Use absolute path path.resolve() -> path.absolute() (#129409)

Changes:

1. Always explicit `.absolute()`: `Path(__file__)` -> `Path(__file__).absolute()`
2. Replace `path.resolve()` with `path.absolute()` if the code is resolving the PyTorch repo root directory.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/129409
Approved by: https://github.com/albanD
This commit is contained in:
Xuehai Pan
2025-01-03 20:03:16 +08:00
committed by PyTorch MergeBot
parent e9e18a9617
commit 45411d1fc9
83 changed files with 127 additions and 123 deletions

View File

@ -86,7 +86,7 @@ def write_decomposition_util_file(path: str) -> None:
def main() -> None:
pytorch_dir = Path(__file__).resolve().parents[3]
pytorch_dir = Path(__file__).absolute().parents[3]
upgrader_path = pytorch_dir / "torch" / "csrc" / "jit" / "runtime"
write_decomposition_util_file(str(upgrader_path))

View File

@ -2752,7 +2752,7 @@ def get_torchgen_root() -> Path:
If you're depending on torchgen out-of-tree, you can use the root to figure
out the path to native_functions.yaml
"""
return Path(__file__).parent.resolve()
return Path(__file__).absolute().parent
def main() -> None:
@ -3043,7 +3043,7 @@ def main() -> None:
gen_declarations_yaml(native_functions=native_functions, cpu_fm=cpu_fm)
if options.output_dependencies:
depfile_path = Path(options.output_dependencies).resolve()
depfile_path = Path(options.output_dependencies).absolute()
depfile_name = depfile_path.name
depfile_stem = depfile_path.stem

View File

@ -984,7 +984,7 @@ def main() -> None:
)
if options.output_dependencies:
depfile_path = Path(options.output_dependencies).resolve()
depfile_path = Path(options.output_dependencies).absolute()
depfile_name = depfile_path.name
depfile_stem = depfile_path.stem

View File

@ -380,7 +380,7 @@ def main() -> None:
for up in sorted_upgrader_list:
print("after sort upgrader : ", next(iter(up)))
pytorch_dir = Path(__file__).resolve().parents[2]
pytorch_dir = Path(__file__).absolute().parents[2]
upgrader_path = pytorch_dir / "torch" / "csrc" / "jit" / "mobile"
write_cpp(str(upgrader_path), sorted_upgrader_list)

View File

@ -173,7 +173,7 @@ def write_decomposition_util_file(path: str) -> None:
def main() -> None:
pytorch_dir = Path(__file__).resolve().parents[2]
pytorch_dir = Path(__file__).absolute().parents[2]
upgrader_path = pytorch_dir / "torch" / "csrc" / "jit" / "runtime"
write_decomposition_util_file(str(upgrader_path))