Skip to content

Commit fd1295f

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
Changed validation message
1 parent 2c8d849 commit fd1295f

File tree

8 files changed

+32
-19
lines changed

8 files changed

+32
-19
lines changed

src/superannotate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,4 @@
299299
logging.config.fileConfig(
300300
os.path.join(WORKING_DIR, "logging.conf"), disable_existing_loggers=False
301301
)
302-
sys.tracebacklimit = 1
302+
sys.tracebacklimit = 0

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def init(path_to_config_json: str):
7474
@validate_arguments
7575
def set_auth_token(token: str):
7676
controller.set_token(token)
77-
controller.init(controller.config_path)
7877

7978

8079
@Trackable

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@ def wrapped(*args, **kwargs):
4040
try:
4141
return pydantic_validate_arguments(func)(*args, **kwargs)
4242
except ValidationError as e:
43-
messages = defaultdict(list)
43+
error_messages = defaultdict(list)
4444
for error in e.errors():
45-
messages[error["loc"][0]].append(f"{error['loc'][-1]} {error['msg']}")
46-
raise AppException(
47-
"\n".join(
48-
[
49-
f"Invalid {message}: {','.join(text)}"
50-
for message, text in messages.items()
51-
]
45+
error_messages[error["loc"][0]].append(
46+
f"{error['loc'][-1]} {error['msg']}"
5247
)
53-
)
48+
texts = ["\n"]
49+
for error, text in error_messages.items():
50+
texts.append(
51+
"{} |{}{}".format(
52+
error, " " * (20 - len(error) + 1), f"\n {' ' * 20}".join(text)
53+
)
54+
)
55+
raise AppException("\n".join(texts))
5456

5557
return wrapped

src/superannotate/lib/core/serviceproviders.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def __call__(cls, *args, **kwargs):
1616
SingleInstanceMetaClass._instances[cls] = super().__call__(*args, **kwargs)
1717
return SingleInstanceMetaClass._instances[cls]
1818

19+
def get_instance(cls):
20+
if cls._instances:
21+
return cls._instances[cls]
22+
1923

2024
class SuerannotateServiceProvider(metaclass=SingleInstanceMetaClass):
2125
@abstractmethod

src/superannotate/lib/core/usecases.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,9 +2281,7 @@ def fill_classes_data(self, annotations: dict):
22812281
for annotation in (
22822282
i for i in annotations["instances"] if i.get("type", None) == "template"
22832283
):
2284-
template_name = templates.get(
2285-
annotation.get("templateId"), None
2286-
)
2284+
template_name = templates.get(annotation.get("templateId"), None)
22872285
if template_name:
22882286
annotation["templateName"] = template_name
22892287

src/superannotate/lib/infrastructure/controller.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,21 @@ def team_name(self):
108108
_, self._team_name = self.get_team()
109109
return self._team_name
110110

111+
@staticmethod
112+
def _validate_token(token: str):
113+
try:
114+
int(token.split("=")[-1])
115+
except ValueError:
116+
raise AppException("Invalid token.")
117+
111118
def set_token(self, token):
119+
self._validate_token(token)
120+
self._team_id = int(token.split("=")[-1])
112121
self.configs.insert(ConfigEntity("token", token))
113-
self._backend_client = SuperannotateBackendService(
114-
api_url=self.configs.get_one("main_endpoint").value,
115-
auth_token=self.configs.get_one("token").value,
116-
logger=self._logger,
117-
)
122+
self._backend_client = SuperannotateBackendService.get_instance()
123+
self._backend_client._api_url = self.configs.get_one("main_endpoint").value
124+
self._backend_client._auth_token = self.configs.get_one("token").value
125+
self._backend_client.get_session.cache_clear()
118126

119127
@property
120128
def projects(self):

src/superannotate/lib/infrastructure/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def wrapper_cache(func):
1212

1313
@wraps(func)
1414
def wrapped_func(*args, **kwargs):
15+
wrapped_func.cache_clear = func.cache_clear
1516
if datetime.utcnow() >= func.expiration:
1617
func.cache_clear()
1718
func.expiration = datetime.utcnow() + func.lifetime

tests/integration/test_interface.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from os.path import dirname
33
import tempfile
4+
import unittest
45

56
import src.superannotate as sa
67
from src.superannotate.lib.app.exceptions import AppException

0 commit comments

Comments
 (0)