Skip to content

Commit 6682355

Browse files
fineguyThe TensorFlow Datasets Authors
authored andcommitted
Add relative_download_dir to Resource class.
PiperOrigin-RevId: 680463547
1 parent c37ca97 commit 6682355

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

tensorflow_datasets/core/download/download_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,10 @@ def downloaded_size(self) -> int:
318318
def _get_dl_path(
319319
self, resource: resource_lib.Resource, checksum: str | None = None
320320
) -> epath.Path:
321-
return self._download_dir / resource_lib.get_dl_fname(
322-
resource.url, checksum
321+
return (
322+
self._download_dir
323+
/ resource.relative_download_dir
324+
/ resource_lib.get_dl_fname(resource.url, checksum)
323325
)
324326

325327
@property

tensorflow_datasets/core/download/resource.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ def __init__(
285285
url: str | None = None,
286286
extract_method: ExtractMethod | None = None,
287287
path: epath.PathLike | None = None,
288+
relative_download_dir: epath.PathLike = '',
288289
):
289290
"""Resource constructor.
290291
@@ -294,10 +295,13 @@ def __init__(
294295
set, will be guessed from downloaded file name `original_fname`.
295296
path: Path of resource on local disk. Can be None if resource has not be
296297
downloaded yet. In such case, `url` must be set.
298+
relative_download_dir: Optional directory for downloading relative to
299+
`download_dir`.
297300
"""
298301
self.url = url
299302
self._extract_method = extract_method
300303
self.path: epath.Path = epath.Path(path) if path else None # pytype: disable=annotation-type-mismatch # attribute-variable-annotations
304+
self.relative_download_dir = relative_download_dir
301305

302306
@classmethod
303307
def exists_locally(cls, path: epath.Path) -> bool:

0 commit comments

Comments
 (0)