diff --git a/docs/source/cmdline/download.rst b/docs/source/cmdline/download.rst index 32bf11cfe..3e45838a7 100644 --- a/docs/source/cmdline/download.rst +++ b/docs/source/cmdline/download.rst @@ -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 diff --git a/lincbrain/cli/cmd_download.py b/lincbrain/cli/cmd_download.py index 5c0bc5f22..7f2b44e33 100644 --- a/lincbrain/cli/cmd_download.py +++ b/lincbrain/cli/cmd_download.py @@ -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`." ), ) diff --git a/lincbrain/download.py b/lincbrain/download.py index 2df711c78..7f4001f2f 100644 --- a/lincbrain/download.py +++ b/lincbrain/download.py @@ -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 ): diff --git a/lincbrain/tests/test_download.py b/lincbrain/tests/test_download.py index 2a8c044ce..cd74c1609 100644 --- a/lincbrain/tests/test_download.py +++ b/lincbrain/tests/test_download.py @@ -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: diff --git a/lincbrain/utils.py b/lincbrain/utils.py index 4230fd83b..073a9eebf 100644 --- a/lincbrain/utils.py +++ b/lincbrain/utils.py @@ -747,7 +747,7 @@ def check_dandi_version() -> None: try: etelemetry.check_available_version( - "linc/linc-cli", __version__, lgr=lgr, raise_exception=True + "lincbrain/linc-cli", __version__, lgr=lgr, raise_exception=True ) except etelemetry.client.BadVersionError: # note: SystemExit is based of BaseException, so is not Exception