Skip to content

Commit

Permalink
Merge pull request #1331 from dandi/bf-1307
Browse files Browse the repository at this point in the history
Fix uploading Zarr within a BIDS dataset
  • Loading branch information
yarikoptic authored Sep 29, 2023
2 parents 697af7c + f6a9970 commit cb984e8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
5 changes: 4 additions & 1 deletion dandi/dandiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,10 @@ def get_content_url(
else:
break
except requests.HTTPError as e:
url = e.request.url
if e.request is not None and isinstance(e.request.url, str):
url = e.request.url
else:
raise # reraise since we need to figure out how to handle such a case
if strip_query:
url = urlunparse(urlparse(url)._replace(query=""))
return url
Expand Down
2 changes: 1 addition & 1 deletion dandi/files/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def get_metadata(
)


class ZarrBIDSAsset(BIDSAsset, ZarrAsset):
class ZarrBIDSAsset(ZarrAsset, BIDSAsset):
"""
.. versionadded:: 0.46.0
Expand Down
16 changes: 16 additions & 0 deletions dandi/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,22 @@ def bids_nwb_dandiset(
return new_dandiset


# TODO: refactor: avoid duplication and come up with some fixture helper which would
# just need specify bids example name
@pytest.fixture()
def bids_zarr_dandiset(
new_dandiset: SampleDandiset, bids_examples: Path
) -> SampleDandiset:
shutil.copytree(
bids_examples / "micr_SEMzarr",
new_dandiset.dspath,
dirs_exist_ok=True,
ignore=shutil.ignore_patterns(dandiset_metadata_file),
)
(new_dandiset.dspath / "CHANGES").write_text("0.1.0 2014-11-03\n")
return new_dandiset


@pytest.fixture()
def bids_dandiset_invalid(
new_dandiset: SampleDandiset, bids_error_examples: Path
Expand Down
13 changes: 13 additions & 0 deletions dandi/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,19 @@ def test_upload_zarr(new_dandiset: SampleDandiset) -> None:
new_dandiset.upload()


# identical to above, but different scenaior/fixture and path. TODO: avoid duplication
def test_upload_bids_zarr(bids_zarr_dandiset: SampleDandiset) -> None:
bids_zarr_dandiset.upload()
assets = list(bids_zarr_dandiset.dandiset.get_assets())
assert len(assets) > 10 # it is a bigish dataset
(asset,) = [a for a in assets if a.path.endswith(".zarr")]
assert isinstance(asset, RemoteZarrAsset)
assert asset.asset_type is AssetType.ZARR
assert asset.path.endswith(".zarr")
# Test that uploading again without any changes works:
bids_zarr_dandiset.upload()


def test_upload_different_zarr(tmp_path: Path, zarr_dandiset: SampleDandiset) -> None:
asset = zarr_dandiset.dandiset.get_asset_by_path("sample.zarr")
assert isinstance(asset, RemoteZarrAsset)
Expand Down

0 comments on commit cb984e8

Please sign in to comment.