Skip to content
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
7 changes: 7 additions & 0 deletions darwin/dataset/remote_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ def pull(
annotations_dir.mkdir(parents=True, exist_ok=False)
stems: dict = {}

# If properties were exported, move the metadata.json file to the annotations folder
if (tmp_dir / ".v7").exists():
metadata_file = tmp_dir / ".v7" / "metadata.json"
metadata_dir = annotations_dir / ".v7"
metadata_dir.mkdir(parents=True, exist_ok=True)
shutil.move(str(metadata_file), str(metadata_dir / "metadata.json"))

# Move the annotations into the right folder and rename them to have the image
# original filename as contained in the json
for annotation_path in tmp_dir.glob("*.json"):
Expand Down
38 changes: 38 additions & 0 deletions tests/darwin/dataset/remote_dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,44 @@ def test_raises_if_release_format_is_not_json(
with pytest.raises(UnsupportedExportFormat):
remote_dataset.pull(release=a_release)

@patch("platform.system", return_value="Linux")
def test_moves_properties_metadata_file(
self, system_mock: MagicMock, remote_dataset: RemoteDataset
):
stub_release_response = Release(
"dataset-slug",
"team-slug",
"0.1.0",
"release-name",
"http://darwin-fake-url.com",
datetime.now(),
None,
None,
True,
True,
"json",
)

def fake_download_zip(self, path):
zip: Path = Path("tests/dataset_with_properties.zip")
shutil.copy(zip, path)
return path

with patch.object(
RemoteDataset, "get_release", return_value=stub_release_response
) as get_release_stub:
with patch.object(Release, "download_zip", new=fake_download_zip):
remote_dataset.pull(only_annotations=True)
metadata_path = (
remote_dataset.local_path
/ "releases"
/ "latest"
/ "annotations"
/ ".v7"
/ "metadata.json"
)
assert metadata_path.exists()


@pytest.fixture
def dataset_item(dataset_slug: str) -> DatasetItem:
Expand Down
Binary file added tests/dataset_with_properties.zip
Binary file not shown.