Skip to content

Commit 254413b

Browse files
authored
Merge pull request #371 from superannotateai/friday
Friday
2 parents 903736e + e491153 commit 254413b

File tree

8 files changed

+52
-12
lines changed

8 files changed

+52
-12
lines changed

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ def upload_image_annotations(
21122112
mask=mask,
21132113
verbose=verbose,
21142114
)
2115-
if response.errors:
2115+
if response.errors and not response.errors == constances.INVALID_JSON_MESSAGE:
21162116
raise AppException(response.errors)
21172117

21182118

src/superannotate/lib/core/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@
117117
" Run 'pip install --upgrade superannotate' to"
118118
" upgrade from your version {} to {}"
119119
)
120+
121+
USE_VALIDATE_MESSAGE = (
122+
"Use the validate_annotations function to discover the possible reason(s) for "
123+
"which an annotation is invalid."
124+
)
125+
126+
INVALID_JSON_MESSAGE = "Invalid json"
127+
120128
__alL__ = (
121129
ProjectType,
122130
UserRole,

src/superannotate/lib/core/reporter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ def __init__(
2424
self.custom_messages = defaultdict(set)
2525
self.progress_bar = None
2626

27+
def disable_warnings(self):
28+
self._log_warning = False
29+
30+
def enable_warnings(self):
31+
self._log_warning = True
32+
2733
def log_info(self, value: str):
2834
if self._log_info:
2935
self.logger.info(value)

src/superannotate/lib/core/usecases/annotations.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def _upload_annotation(
168168
bucket,
169169
):
170170
try:
171+
self.reporter.disable_warnings()
171172
response = UploadAnnotationUseCase(
172173
project=self._project,
173174
folder=self._folder,
@@ -196,6 +197,8 @@ def _upload_annotation(
196197
except Exception as e:
197198
logger.debug(str(e), exc_info=True)
198199
return path, False
200+
finally:
201+
self.reporter.enable_warnings()
199202

200203
def get_bucket_to_upload(self, ids: List[int]):
201204
upload_data = self.get_annotation_upload_data(ids)
@@ -231,8 +234,7 @@ def _log_report(self):
231234
logger.warning(
232235
f"Couldn't validate {len(self.reporter.custom_messages['invalid_jsons'])}/"
233236
f"{len(self.annotations_to_upload + self.missing_annotations)} annotations from {self._folder_path}. "
234-
f"Use the validate_annotations function to discover the possible reason(s) for "
235-
f"which an annotation is invalid."
237+
f"{constances.USE_VALIDATE_MESSAGE}"
236238
)
237239

238240
def execute(self):
@@ -486,12 +488,13 @@ def execute(self):
486488
)
487489
self._images.update(self._image)
488490
if self._verbose:
489-
logger.info(
490-
"Uploading annotations for image %s in project %s.",
491-
str(self._image.name),
492-
self._project.name,
491+
self.reporter.log_info(
492+
f"Uploading annotations for image {str(self._image.name)} in project {self._project.name}."
493493
)
494494
else:
495-
self._response.errors = "Invalid json"
495+
self._response.errors = constances.INVALID_JSON_MESSAGE
496496
self.reporter.store_message("invalid_jsons", self._annotation_path)
497+
self.reporter.log_warning(
498+
f"Couldn't validate annotations. {constances.USE_VALIDATE_MESSAGE}"
499+
)
497500
return self._response

src/superannotate/lib/core/usecases/projects.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,13 @@ def _copy_workflow(
515515

516516
def execute(self):
517517
if self.is_valid():
518+
if self._project_to_create.project_type in (
519+
constances.ProjectType.PIXEL.value,
520+
constances.ProjectType.VECTOR.value,
521+
):
522+
self._project_to_create.upload_state = (
523+
constances.UploadState.INITIAL.value
524+
)
518525
project = self._projects.insert(self._project_to_create)
519526
self.reporter.log_info(
520527
f"Created project {self._project_to_create.name} with type"

src/superannotate/lib/infrastructure/controller.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,7 @@ def team_id(self) -> int:
216216

217217
@property
218218
def default_reporter(self):
219-
if not self._reporter:
220-
self._reporter = Reporter()
221-
return self._reporter
219+
return Reporter()
222220

223221
@timed_lru_cache(seconds=3600)
224222
def get_auth_data(self, project_id: int, team_id: int, folder_id: int):

tests/integration/projects/test_clone_project.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
import src.superannotate as sa
66
from tests import DATA_SET_PATH
7+
from src.superannotate import constances
78

89

910
class TestCloneProject(TestCase):
@@ -78,7 +79,7 @@ def test_create_like_project(self):
7879
self.PROJECT_NAME_2, self.PROJECT_NAME_1, copy_contributors=True
7980
)
8081
source_project = sa.get_project_metadata(self.PROJECT_NAME_1)
81-
self.assertEqual(new_project['upload_state'], source_project['upload_state'])
82+
self.assertEqual(new_project['upload_state'], constances.UploadState.INITIAL.name)
8283

8384
new_settings = sa.get_project_settings(self.PROJECT_NAME_2)
8485
image_quality = None

tests/integration/test_interface.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,23 @@ def test_download_fuse_without_classes(self):
156156
)
157157
self.assertIsNotNone(result)
158158

159+
def test_validate_log_for_single_uplaod(self):
160+
with self.assertLogs() as logs:
161+
sa.upload_image_to_project(self.PROJECT_NAME, f"{self.folder_path}/{self.EXAMPLE_IMAGE_1}")
162+
sa.upload_image_annotations(
163+
self.PROJECT_NAME, self.EXAMPLE_IMAGE_1, {
164+
"metadatas": {
165+
"name": "example_image_1.jpg",
166+
"width": 1024,
167+
"height": 683,
168+
"status": "Completed",
169+
},
170+
"instance": []
171+
}
172+
)
173+
self.assertEqual(len(logs[1][0]), 150)
174+
175+
159176

160177
class TestPixelInterface(BaseTestCase):
161178
PROJECT_NAME = "Interface Pixel test"

0 commit comments

Comments
 (0)