Skip to content

Commit 1e4f196

Browse files
authored
Merge pull request #203 from superannotateai/friday_140
Fixed SDK | Error when importing superannotate
2 parents 1efb59e + 6fe22bb commit 1e4f196

File tree

7 files changed

+142
-126
lines changed

7 files changed

+142
-126
lines changed

src/superannotate/lib/app/mixp/decorators.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def get_default(team_name, user_id, project_name=None):
2626

2727

2828
class Trackable:
29+
TEAM_DATA = None
30+
2931
def __init__(self, function):
3032
self.function = function
3133
self._success = False
@@ -38,8 +40,8 @@ def track(self, *args, **kwargs):
3840
properties = data["properties"]
3941
properties["Success"] = self._success
4042
default = get_default(
41-
team_name=controller.team_name,
42-
user_id=controller.user_id,
43+
team_name=self.__class__.TEAM_DATA[1],
44+
user_id=self.__class__.TEAM_DATA[0],
4345
project_name=properties.get("project_name", None),
4446
)
4547
properties.pop("project_name", None)
@@ -52,11 +54,17 @@ def track(self, *args, **kwargs):
5254

5355
def __call__(self, *args, **kwargs):
5456
try:
57+
58+
self.__class__.TEAM_DATA = controller.get_team()
5559
ret = self.function(*args, **kwargs)
5660
self._success = True
57-
self.track(*args, **kwargs)
5861
except Exception as e:
5962
self._success = False
60-
self.track(*args, **kwargs)
6163
raise e
62-
return ret
64+
else:
65+
return ret
66+
finally:
67+
try:
68+
self.track(*args, **kwargs)
69+
except Exception:
70+
pass

src/superannotate/lib/core/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@
5959
"The function does not support projects containing videos attached with URLs"
6060
)
6161

62+
DEPRECATED_DOCUMENT_PROJECTS_MESSAGE = (
63+
"The function does not support projects containing documents attached with URLs"
64+
)
65+
66+
LIMITED_FUNCTIONS = {
67+
ProjectType.VIDEO.value: DEPRECATED_VIDEO_PROJECTS_MESSAGE,
68+
ProjectType.DOCUMENT.value: DEPRECATED_DOCUMENT_PROJECTS_MESSAGE,
69+
}
70+
6271
__version__ = "?"
6372

6473
__alL__ = (
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from abc import ABC
2+
from abc import abstractmethod
3+
4+
from lib.core.exceptions import AppValidationException
5+
from lib.core.response import Response
6+
7+
8+
class BaseUseCase(ABC):
9+
def __init__(self):
10+
self._response = Response()
11+
12+
@abstractmethod
13+
def execute(self) -> Response:
14+
raise NotImplementedError
15+
16+
def _validate(self):
17+
for name in dir(self):
18+
try:
19+
if name.startswith("validate_"):
20+
method = getattr(self, name)
21+
method()
22+
except AppValidationException as e:
23+
self._response.errors = e
24+
25+
def is_valid(self):
26+
self._validate()
27+
return not self._response.errors
28+
29+
30+
class BaseInteractiveUseCase(BaseUseCase):
31+
@property
32+
def response(self):
33+
return self._response
34+
35+
@property
36+
def data(self):
37+
return self.response.data
38+
39+
@abstractmethod
40+
def execute(self):
41+
raise NotImplementedError

0 commit comments

Comments
 (0)