Skip to content

Commit ebd1093

Browse files
author
The TensorFlow Datasets Authors
committed
Fix DatasetBuilder.code_path for when epath.resource_path returns MultiplexedPath.
PiperOrigin-RevId: 618133345
1 parent 2b575b8 commit ebd1093

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tensorflow_datasets/core/dataset_builder.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from absl import logging
3232
from etils import epath
33+
import importlib_resources
3334
from tensorflow_datasets.core import constants
3435
from tensorflow_datasets.core import dataset_info
3536
from tensorflow_datasets.core import dataset_metadata
@@ -310,8 +311,14 @@ def code_path(cls) -> Optional[epath.Path]:
310311
# For dynamically added modules, `importlib.resources` returns
311312
# `pathlib.Path('.')` rather than the real path, so filter those by
312313
# checking for `parts`.
313-
# Check for `zipfile.Path` (`ResourcePath`) as it does not have `.parts`
314-
if isinstance(path, epath.resource_utils.ResourcePath) or path.parts:
314+
# Check for `zipfile.Path` (`ResourcePath`) or
315+
# `importlib_resources.abc.Traversable` (e.g. `MultiplexedPath`) as they
316+
# do not have `.parts`.
317+
if (
318+
isinstance(path, epath.resource_utils.ResourcePath)
319+
or isinstance(path, importlib_resources.abc.Traversable)
320+
or path.parts
321+
):
315322
modules[-1] += ".py"
316323
return path.joinpath(*modules[1:])
317324
# Otherwise, fallback to `pathlib.Path`. For non-zipapp, it should be

0 commit comments

Comments
 (0)