Skip to content

Commit b4c81e2

Browse files
tomvdwThe TensorFlow Datasets Authors
authored andcommitted
Use iterative joinpath instead of unpacking in TFDS paths.
PiperOrigin-RevId: 911899569
1 parent 56d8b40 commit b4c81e2

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

tensorflow_datasets/core/dataset_builder.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ def _get_builder_datadir_path(builder_cls: Type[Any]) -> epath.Path:
153153
"""
154154
pkg_names = builder_cls.__module__.split(".")
155155
# -1 to remove the xxx.py python file.
156-
return epath.resource_path(pkg_names[0]).joinpath(*pkg_names[1:-1])
156+
path = epath.resource_path(pkg_names[0])
157+
for pkg_name in pkg_names[1:-1]:
158+
path = path.joinpath(pkg_name)
159+
return path
157160

158161

159162
class DatasetBuilder(registered.RegisteredDataset):
@@ -343,7 +346,9 @@ def code_path(cls) -> epath.Path | None:
343346
or path.parts
344347
):
345348
modules[-1] += ".py"
346-
return path.joinpath(*modules[1:])
349+
for module in modules[1:]:
350+
path = path.joinpath(module)
351+
return path
347352
# Otherwise, fallback to `pathlib.Path`. For non-zipapp, it should be
348353
# equivalent to the above return.
349354
try:

tensorflow_datasets/core/utils/resource_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ def tfds_path(*relative_path: epath.PathLike) -> epath.Path:
4747
Returns:
4848
path: The root TFDS path.
4949
"""
50-
return root_tfds_path().joinpath(*relative_path)
50+
path = root_tfds_path()
51+
for pkg_name in relative_path:
52+
path = path.joinpath(pkg_name)
53+
return path
5154

5255

5356
def tfds_write_path(*relative_path: epath.PathLike) -> epath.Path:

0 commit comments

Comments
 (0)