Skip to content

Commit 866b656

Browse files
committed
Merge branch 'assests_provider' into group_type
# Conflicts: # tests/unit/test_enum_arguments_handeling.py
2 parents 6788ae9 + a72cd7e commit 866b656

34 files changed

+702
-5418
lines changed

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
minversion = 3.7
33
log_cli=true
44
python_files = test_*.py
5-
addopts = -n auto --dist=loadscope
5+
;addopts = -n auto --dist=loadscope

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ setuptools~=57.4.0
2020
aiohttp==3.8.1
2121
email-validator>=1.0.3
2222
nest-asyncio==1.5.4
23+
jsonschema==3.2.0

src/superannotate/lib/app/helpers.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import uuid
23
from pathlib import Path
34
from typing import List
@@ -128,3 +129,21 @@ def get_name_url_duplicated_from_csv(csv_path):
128129
else:
129130
duplicate_images.append(temp)
130131
return images_to_upload, duplicate_images
132+
133+
134+
def get_tabulation() -> int:
135+
try:
136+
return int(os.get_terminal_size().columns / 2)
137+
except OSError:
138+
return 48
139+
140+
141+
def wrap_error(errors_list: List[Tuple[str, str]]) -> str:
142+
tabulation = get_tabulation()
143+
msgs = []
144+
for key, value in errors_list:
145+
_tabulation = tabulation - len(key)
146+
if not key:
147+
key, value, _tabulation = value, "", 0
148+
msgs.append("{}{}{}".format(key, " " * _tabulation, value))
149+
return "\n".join(msgs)

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from lib.app.helpers import extract_project_folder
2121
from lib.app.helpers import get_annotation_paths
2222
from lib.app.helpers import get_name_url_duplicated_from_csv
23+
from lib.app.helpers import wrap_error as wrap_validation_errors
2324
from lib.app.interface.base_interface import BaseInterfaceFacade
2425
from lib.app.interface.base_interface import TrackableMeta
2526
from lib.app.interface.types import AnnotationStatuses
@@ -1840,9 +1841,11 @@ def add_annotation_point_to_image(
18401841
annotation_class_attributes,
18411842
error,
18421843
)
1843-
self.controller.upload_image_annotations(
1844+
response = self.controller.upload_image_annotations(
18441845
project_name, folder_name, image_name, annotations
18451846
)
1847+
if response.errors:
1848+
raise AppException(response.errors)
18461849

18471850
def add_annotation_comment_to_image(
18481851
self,
@@ -2109,7 +2112,7 @@ def delete_annotations(
21092112
raise AppException(response.errors)
21102113

21112114
def validate_annotations(
2112-
self, project_type: ProjectTypes, annotations_json: Union[NotEmptyStr, Path]
2115+
self, project_type: ProjectTypes, annotations_json: Union[NotEmptyStr, Path, dict]
21132116
):
21142117
"""Validates given annotation JSON.
21152118
@@ -2122,16 +2125,20 @@ def validate_annotations(
21222125
:return: The success of the validation
21232126
:rtype: bool
21242127
"""
2125-
with open(annotations_json) as file:
2126-
annotation_data = json.loads(file.read())
2127-
response = Controller.validate_annotations(project_type, annotation_data)
2128-
if response.errors:
2129-
raise AppException(response.errors)
2130-
is_valid, _ = response.data
2131-
if is_valid:
2132-
return True
2133-
print(response.report)
2134-
return False
2128+
if isinstance(annotations_json, dict):
2129+
annotation_data = annotations_json
2130+
else:
2131+
annotation_data = json.load(open(annotations_json))
2132+
response = self.controller.validate_annotations(
2133+
project_type, annotation_data
2134+
)
2135+
if response.errors:
2136+
raise AppException(response.errors)
2137+
report = response.data
2138+
if not report:
2139+
return True
2140+
print(wrap_validation_errors(report))
2141+
return False
21352142

21362143
def add_contributors_to_project(
21372144
self,

0 commit comments

Comments
 (0)