Skip to content

Commit 4f830e4

Browse files
committed
Fix review comments
1 parent e68048a commit 4f830e4

7 files changed

Lines changed: 14 additions & 50 deletions

File tree

dagshub/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.6.10"
1+
__version__ = "0.6.9"
22
from .logger import DAGsHubLogger, dagshub_logger
33
from .common.init import init
44
from .upload.wrapper import upload_files

dagshub/auth/token_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def auth_flow(self, request: Request) -> Generator[Request, Response, None]:
3737

3838
def can_renegotiate(self):
3939
# Env var tokens cannot renegotiate, every other token type can
40-
return type(self._token) is not EnvVarDagshubToken
40+
return not type(self._token) is EnvVarDagshubToken
4141

4242
def renegotiate_token(self):
4343
if not self._token_storage.is_valid_token(self._token, self._host):

dagshub/data_engine/annotation/importer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def download_annotations(self, dest_dir: Path):
9595
log_message("Downloading annotations from repository")
9696
repoApi = self.ds.source.repoApi
9797
if self.annotations_type == "cvat":
98+
# Download just the annotation file
9899
repoApi.download(self.annotations_file.as_posix(), dest_dir, keep_source_prefix=True)
99100
elif self.annotations_type == "yolo":
100101
# Download the dataset .yaml file and the images + annotations
@@ -107,6 +108,7 @@ def download_annotations(self, dest_dir: Path):
107108
assert context.path is not None
108109
repoApi.download(self.annotations_file.parent / context.path, dest_dir, keep_source_prefix=True)
109110
elif self.annotations_type == "coco":
111+
# Download just the annotation file
110112
repoApi.download(self.annotations_file.as_posix(), dest_dir, keep_source_prefix=True)
111113

112114
@staticmethod
@@ -157,10 +159,8 @@ def remap_annotations(
157159
)
158160
continue
159161
for ann in anns:
160-
if ann.filename is not None:
161-
ann.filename = remap_func(ann.filename)
162-
else:
163-
ann.filename = new_filename
162+
assert ann.filename is not None
163+
ann.filename = remap_func(ann.filename)
164164
remapped[new_filename] = anns
165165

166166
return remapped

dagshub/data_engine/annotation/metadata.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -271,28 +271,6 @@ def add_image_pose(
271271
self.annotations.append(ann)
272272
self._update_datapoint()
273273

274-
def add_coco_annotation(
275-
self,
276-
coco_json: str,
277-
):
278-
"""
279-
Add annotations from a COCO-format JSON string.
280-
281-
Args:
282-
coco_json: A COCO-format JSON string with ``categories``, ``images``, and ``annotations`` keys.
283-
"""
284-
from dagshub_annotation_converter.converters.coco import load_coco_from_json_string
285-
286-
grouped, _ = load_coco_from_json_string(coco_json)
287-
new_anns: list[IRAnnotationBase] = []
288-
for anns in grouped.values():
289-
for ann in anns:
290-
ann.filename = self.datapoint.path
291-
new_anns.append(ann)
292-
self.annotations.extend(new_anns)
293-
log_message(f"Added {len(new_anns)} COCO annotation(s) to datapoint {self.datapoint.path}")
294-
self._update_datapoint()
295-
296274
def add_yolo_annotation(
297275
self,
298276
annotation_type: Literal["bbox", "segmentation", "pose"],

dagshub/data_engine/model/query_result.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,10 @@ def export_as_coco(
900900

901901
context = CocoContext()
902902
if classes is not None:
903-
context.categories = dict(classes)
903+
categories = Categories()
904+
for category_id, category_name in classes.items():
905+
categories.add(category_name, category_id)
906+
context.categories = categories
904907

905908
# Add the source prefix to all annotations
906909
for ann in annotations:

tests/data_engine/annotation_import/test_coco.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import datetime
22
import json
3-
from pathlib import PurePosixPath
4-
from unittest.mock import patch, PropertyMock
3+
from unittest.mock import patch
54

65
import pytest
76
from dagshub_annotation_converter.ir.image import (
@@ -17,12 +16,6 @@
1716
from dagshub.data_engine.model.query_result import QueryResult
1817

1918

20-
@pytest.fixture(autouse=True)
21-
def mock_source_prefix(ds):
22-
with patch.object(type(ds.source), "source_prefix", new_callable=PropertyMock, return_value=PurePosixPath()):
23-
yield
24-
25-
2619
# --- import ---
2720

2821

@@ -58,19 +51,6 @@ def test_coco_convert_to_ls_tasks(ds, tmp_path, mock_dagshub_auth):
5851
assert len(task_json["annotations"]) > 0
5952

6053

61-
# --- add_coco_annotation ---
62-
63-
64-
def test_add_coco_annotation_rewrites_filename(ds, mock_dagshub_auth):
65-
dp = Datapoint(datasource=ds, path="my_images/photo.jpg", datapoint_id=0, metadata={})
66-
meta_ann = MetadataAnnotations(datapoint=dp, field="ann")
67-
meta_ann.add_coco_annotation(json.dumps(_make_coco_json()))
68-
69-
assert len(meta_ann.annotations) == 1
70-
assert isinstance(meta_ann.annotations[0], IRBBoxImageAnnotation)
71-
assert meta_ann.annotations[0].filename == "my_images/photo.jpg"
72-
73-
7454
# --- _resolve_annotation_field ---
7555

7656

tests/data_engine/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import datetime
2+
from pathlib import PurePosixPath
3+
from unittest.mock import PropertyMock
24

35
import pytest
46

@@ -34,6 +36,7 @@ def _create_mock_datasource(mocker, id, name) -> Datasource:
3436
mocker.patch.object(ds_state, "get_from_dagshub")
3537
# Stub out root path so all the content_path/etc work without also mocking out RepoAPI
3638
mocker.patch.object(ds_state, "_root_path", return_value="http://example.com")
39+
mocker.patch.object(type(ds_state), "source_prefix", new_callable=PropertyMock, return_value=PurePosixPath())
3740
ds_state.repoApi = MockRepoAPI("kirill/repo")
3841
return Datasource(ds_state)
3942

0 commit comments

Comments
 (0)