Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dandi download dandi://…/dandiset.yaml now downloads dandiset.yaml #1384

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions dandi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
from . import get_logger
from .consts import RETRY_STATUSES, dandiset_metadata_file
from .dandiapi import AssetType, BaseRemoteZarrAsset, RemoteDandiset
from .dandiarchive import DandisetURL, ParsedDandiURL, SingleAssetURL, parse_dandi_url
from .dandiarchive import (
AssetItemURL,
DandisetURL,
ParsedDandiURL,
SingleAssetURL,
parse_dandi_url,
)
from .dandiset import Dandiset
from .exceptions import NotFoundError
from .files import LocalAsset, find_dandi_files
Expand Down Expand Up @@ -227,7 +233,13 @@ def download_generator(self) -> Iterator[dict]:
"""

with self.url.navigate(strict=True) as (client, dandiset, assets):
if isinstance(self.url, DandisetURL) and self.get_metadata:
if (
isinstance(self.url, DandisetURL)
or (
isinstance(self.url, AssetItemURL)
and self.url.path == "dandiset.yaml"
)
) and self.get_metadata:
assert dandiset is not None
for resp in _populate_dandiset_yaml(
self.output_path, dandiset, self.existing
Expand All @@ -236,6 +248,8 @@ def download_generator(self) -> Iterator[dict]:
"path": str(self.output_prefix / dandiset_metadata_file),
**resp,
}
if isinstance(self.url, AssetItemURL):
return

# TODO: do analysis of assets for early detection of needed renames
# etc to avoid any need for late treatment of existing and also for
Expand Down
14 changes: 13 additions & 1 deletion dandi/tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)
from ..exceptions import NotFoundError
from ..support.digests import Digester
from ..utils import list_paths
from ..utils import list_paths, yaml_load


# both urls point to 000027 (lean test dataset), and both draft and "released"
Expand Down Expand Up @@ -182,6 +182,18 @@ def test_download_item(text_dandiset: SampleDandiset, tmp_path: Path) -> None:
assert (tmp_path / "coconut.txt").read_text() == "Coconut\n"


def test_download_dandiset_yaml(text_dandiset: SampleDandiset, tmp_path: Path) -> None:
dandiset_id = text_dandiset.dandiset_id
download(
f"dandi://{text_dandiset.api.instance_id}/{dandiset_id}/dandiset.yaml",
tmp_path,
)
assert list_paths(tmp_path, dirs=True) == [tmp_path / dandiset_metadata_file]
with (tmp_path / dandiset_metadata_file).open(encoding="utf-8") as fp:
metadata = yaml_load(fp)
assert metadata["id"] == f"DANDI:{dandiset_id}/draft"


def test_download_asset_id(text_dandiset: SampleDandiset, tmp_path: Path) -> None:
asset = text_dandiset.dandiset.get_asset_by_path("subdir2/coconut.txt")
download(asset.download_url, tmp_path)
Expand Down