Skip to content

Commit eba9ef1

Browse files
authored
Merge pull request #167 from superannotateai/re-design-sdk
Re design sdk
2 parents fe6a6b1 + 29705e5 commit eba9ef1

38 files changed

+547
-561
lines changed

requirements_dev.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
Sphinx==3.1.2
22
tox==3.24.2
3+
pytest==6.2.4
4+
pytest-xdist==2.3.0
5+
pytest-parallel==0.1.0

src/superannotate.egg-info/PKG-INFO

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/superannotate.egg-info/SOURCES.txt

Lines changed: 0 additions & 154 deletions
This file was deleted.

src/superannotate.egg-info/entry_points.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/superannotate.egg-info/requires.txt

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/superannotate.egg-info/top_level.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/superannotate/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from superannotate.lib.app.convertors.df_converter import filter_images_by_comments
1515
from superannotate.lib.app.convertors.df_converter import filter_images_by_tags
1616
from superannotate.lib.app.convertors.dicom_converter import dicom_to_rgb_sequence
17+
from superannotate.lib.app.exceptions import AppException
1718
from superannotate.lib.app.input_converters.conversion import coco_split_dataset
1819
from superannotate.lib.app.input_converters.conversion import convert_json_version
1920
from superannotate.lib.app.input_converters.conversion import convert_project_type
@@ -153,6 +154,9 @@
153154

154155

155156
__all__ = [
157+
# Utils
158+
"AppException",
159+
#
156160
"init",
157161
"set_auth_token",
158162
# analytics

src/superannotate/lib/app/helpers.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from ast import literal_eval
2+
from functools import wraps
3+
from inspect import getfullargspec
24
from pathlib import Path
5+
from typing import get_type_hints
36
from typing import List
47
from typing import Optional
58
from typing import Tuple
69
from typing import Union
710

811
import boto3
912
import pandas as pd
13+
from lib.core.exceptions import AppValidationException
1014
from superannotate.lib.app.exceptions import PathError
1115
from superannotate.lib.core import PIXEL_ANNOTATION_POSTFIX
1216
from superannotate.lib.core import VECTOR_ANNOTATION_POSTFIX
@@ -117,3 +121,45 @@ def metric_is_plottable(key):
117121
if key == "total_loss" or "mIoU" in key or "mAP" in key or key == "iteration":
118122
return True
119123
return False
124+
125+
126+
def check_types(obj, **kwargs):
127+
hints = get_type_hints(obj)
128+
129+
errors = []
130+
for attr_name, attr_type in hints.items():
131+
if attr_name == "return":
132+
continue
133+
try:
134+
if attr_type.__origin__ is list:
135+
if attr_type.__args__:
136+
for elem in kwargs[attr_name]:
137+
if type(elem) in attr_type.__args__:
138+
continue
139+
else:
140+
errors.append(f"Invalid input {attr_name}")
141+
elif not isinstance(kwargs[attr_name], list):
142+
errors.append(f"Argument {attr_name} is not of type {attr_type}")
143+
elif attr_type.__origin__ is Union:
144+
if kwargs.get(attr_name) and not isinstance(
145+
kwargs[attr_name], attr_type.__args__
146+
):
147+
errors.append(f"Argument {attr_name} is not of type {attr_type}")
148+
elif kwargs.get(attr_name) and not isinstance(kwargs[attr_name], attr_type):
149+
errors.append(f"Argument {attr_name} is not of type {attr_type}")
150+
except Exception as _:
151+
pass
152+
return errors
153+
154+
155+
def validate_input(decorator):
156+
@wraps(decorator)
157+
def wrapped_decorator(*args, **kwargs):
158+
func_args = getfullargspec(decorator)[0]
159+
kwargs.update(dict(zip(func_args, args)))
160+
errors = check_types(decorator, **kwargs)
161+
if errors:
162+
raise AppValidationException("\n".join(errors))
163+
return decorator(**kwargs)
164+
165+
return wrapped_decorator

src/superannotate/lib/app/input_converters/conversion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def export_annotation(
224224
def import_annotation(
225225
input_dir,
226226
output_dir,
227-
dataset_format,
227+
dataset_format="superannotate",
228228
dataset_name="",
229229
project_type="Vector",
230230
task="object_detection",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from lib.infrastructure.repositories import ConfigRepository
55

66

7-
logger = logging.getLogger()
7+
logger = logging.getLogger("superannotate-python-sdk")
88

99

1010
class BaseInterfaceFacade:

0 commit comments

Comments
 (0)