Skip to content

Commit

Permalink
[DAR-1609][External] pull() never creates the properties metadata fil…
Browse files Browse the repository at this point in the history
…e in the annotations directory (#816)

* Added logic to correctly move the properties metadata file if it's included in the export

* Small fix to mkdir statement

* Update darwin/dataset/remote_dataset.py

Co-authored-by: saurbhc <[email protected]>

* Update darwin/dataset/remote_dataset.py

Co-authored-by: saurbhc <[email protected]>

* Added test case

---------

Co-authored-by: saurbhc <[email protected]>
  • Loading branch information
JBWilkie and saurbhc authored Apr 17, 2024
1 parent bc95d43 commit 01c7c90
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
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.

0 comments on commit 01c7c90

Please sign in to comment.