diff --git a/darwin/dataset/remote_dataset.py b/darwin/dataset/remote_dataset.py index b4e28e960..0be301c22 100644 --- a/darwin/dataset/remote_dataset.py +++ b/darwin/dataset/remote_dataset.py @@ -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"): diff --git a/tests/darwin/dataset/remote_dataset_test.py b/tests/darwin/dataset/remote_dataset_test.py index 7ae2625a9..3df57d8a5 100644 --- a/tests/darwin/dataset/remote_dataset_test.py +++ b/tests/darwin/dataset/remote_dataset_test.py @@ -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: diff --git a/tests/dataset_with_properties.zip b/tests/dataset_with_properties.zip new file mode 100644 index 000000000..f2877fa98 Binary files /dev/null and b/tests/dataset_with_properties.zip differ