[torchgen] Refactor torchgen.utils.FileManager to accept pathlib.Path (#150726)

This PR allows `FileManager` to accept `pathlib.Path` as arguments while keeping the original `str` path support.

This allows us to simplify the code such as:

1. `os.path.join(..., ...)` with `Path.__floordiv__(..., ...)`.

95a5958db4/torchgen/utils.py (L155)

95a5958db4/torchgen/utils.py (L176)

2. `os.path.basename(...)` with `Path(...).name`.
 95a5958db4/torchgen/utils.py (L161)

3. Manual file extension split with `Path(...).with_stem(new_stem)`

95a5958db4/torchgen/utils.py (L241-L256)

------

Pull Request resolved: https://github.com/pytorch/pytorch/pull/150726
Approved by: https://github.com/aorenste
This commit is contained in:
Xuehai Pan
2025-05-15 01:40:19 +08:00
committed by PyTorch MergeBot
parent 881a598a1e
commit 014726d9d3
12 changed files with 110 additions and 74 deletions

View File

@ -1,6 +1,7 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from typing_extensions import assert_never
from torchgen import local
from torchgen.api.types import (
@ -48,7 +49,6 @@ from torchgen.model import (
TensorOptionsArguments,
Type,
)
from torchgen.utils import assert_never
if TYPE_CHECKING:

View File

@ -2,6 +2,7 @@ from __future__ import annotations
import itertools
from typing import TYPE_CHECKING
from typing_extensions import assert_never
from torchgen.api import cpp
from torchgen.api.types import ArgName, Binding, CType, NamedCType
@ -13,7 +14,7 @@ from torchgen.model import (
TensorOptionsArguments,
Type,
)
from torchgen.utils import assert_never, concatMap
from torchgen.utils import concatMap
if TYPE_CHECKING:

View File

@ -1,6 +1,7 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from typing_extensions import assert_never
from torchgen import local
from torchgen.api import cpp
@ -29,7 +30,6 @@ from torchgen.model import (
TensorOptionsArguments,
Type,
)
from torchgen.utils import assert_never
if TYPE_CHECKING:

View File

@ -1,5 +1,7 @@
from __future__ import annotations
from typing_extensions import assert_never
from torchgen.api import cpp
from torchgen.api.types import (
ArgName,
@ -30,7 +32,6 @@ from torchgen.model import (
TensorOptionsArguments,
Type,
)
from torchgen.utils import assert_never
# This file describes the translation of JIT schema to the structured functions API.