mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
[BE][Easy] use pathlib.Path
instead of dirname
/ ".."
/ pardir
(#129374)
Changes by apply order: 1. Replace all `".."` and `os.pardir` usage with `os.path.dirname(...)`. 2. Replace nested `os.path.dirname(os.path.dirname(...))` call with `str(Path(...).parent.parent)`. 3. Reorder `.absolute()` ~/ `.resolve()`~ and `.parent`: always resolve the path first. `.parent{...}.absolute()` -> `.absolute().parent{...}` 4. Replace chained `.parent x N` with `.parents[${N - 1}]`: the code is easier to read (see 5.) `.parent.parent.parent.parent` -> `.parents[3]` 5. ~Replace `.parents[${N - 1}]` with `.parents[${N} - 1]`: the code is easier to read and does not introduce any runtime overhead.~ ~`.parents[3]` -> `.parents[4 - 1]`~ 6. ~Replace `.parents[2 - 1]` with `.parent.parent`: because the code is shorter and easier to read.~ Pull Request resolved: https://github.com/pytorch/pytorch/pull/129374 Approved by: https://github.com/justinchuby, https://github.com/malfet
This commit is contained in:
committed by
PyTorch MergeBot
parent
7101b8ca35
commit
b6bdb67f82
2
.github/scripts/gitutils.py
vendored
2
.github/scripts/gitutils.py
vendored
@ -32,7 +32,7 @@ def get_git_remote_name() -> str:
|
||||
def get_git_repo_dir() -> str:
|
||||
from pathlib import Path
|
||||
|
||||
return os.getenv("GIT_REPO_DIR", str(Path(__file__).resolve().parent.parent.parent))
|
||||
return os.getenv("GIT_REPO_DIR", str(Path(__file__).resolve().parents[2]))
|
||||
|
||||
|
||||
def fuzzy_list_to_dict(items: List[Tuple[str, str]]) -> Dict[str, List[str]]:
|
||||
|
Reference in New Issue
Block a user