Skip to content

Commit

Permalink
Merge pull request #1476 from dandi/gh-1475
Browse files Browse the repository at this point in the history
Fix handling of `--preserve-tree` for asset ID-only URLs
  • Loading branch information
yarikoptic authored Aug 6, 2024
2 parents f71ce95 + 112777a commit 9ae6128
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion dandi/cli/cmd_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
is_flag=True,
help=(
"When downloading only part of a Dandiset, also download"
" `dandiset.yaml` and do not strip leading directories from asset"
" `dandiset.yaml` (unless downloading an asset URL that does not"
" include a Dandiset ID) and do not strip leading directories from asset"
" paths. Implies `--download all`."
),
)
Expand Down
13 changes: 8 additions & 5 deletions dandi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,14 @@ def download_generator(self) -> Iterator[dict]:

with self.url.navigate(strict=True) as (client, dandiset, assets):
if (
isinstance(self.url, DandisetURL)
or self.is_dandiset_yaml()
or self.preserve_tree
) and self.get_metadata:
assert dandiset is not None
(
isinstance(self.url, DandisetURL)
or self.is_dandiset_yaml()
or self.preserve_tree
)
and self.get_metadata
and dandiset is not None
):
for resp in _populate_dandiset_yaml(
self.output_path, dandiset, self.existing
):
Expand Down
9 changes: 9 additions & 0 deletions dandi/tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,15 @@ def test_download_asset_id_only(text_dandiset: SampleDandiset, tmp_path: Path) -
assert (tmp_path / "coconut.txt").read_text() == "Coconut\n"


def test_download_asset_id_only_preserve_tree(
text_dandiset: SampleDandiset, tmp_path: Path
) -> None:
asset = text_dandiset.dandiset.get_asset_by_path("subdir2/coconut.txt")
download(asset.base_download_url, tmp_path, preserve_tree=True)
assert list_paths(tmp_path, dirs=False) == [tmp_path / "subdir2" / "coconut.txt"]
assert (tmp_path / "subdir2" / "coconut.txt").read_text() == "Coconut\n"


def test_download_asset_by_equal_prefix(
text_dandiset: SampleDandiset, tmp_path: Path
) -> None:
Expand Down
3 changes: 2 additions & 1 deletion docs/source/cmdline/download.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ Options
.. option:: --preserve-tree

When downloading only part of a Dandiset, also download
:file:`dandiset.yaml` and do not strip leading directories from asset
:file:`dandiset.yaml` (unless downloading an asset URL that does not
include a Dandiset ID) and do not strip leading directories from asset
paths. Implies ``--download all``.

.. option:: --sync
Expand Down

0 comments on commit 9ae6128

Please sign in to comment.