Skip to content

Commit 4108d00

Browse files
authored
Merge pull request #243 from superannotateai/develop
Develop
2 parents 2d7d67d + 413b8a0 commit 4108d00

File tree

14 files changed

+146
-92
lines changed

14 files changed

+146
-92
lines changed

src/superannotate/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from superannotate.lib.app.interface.sdk_interface import benchmark
5858
from superannotate.lib.app.interface.sdk_interface import clone_project
5959
from superannotate.lib.app.interface.sdk_interface import consensus
60+
from superannotate.lib.app.interface.sdk_interface import controller
6061
from superannotate.lib.app.interface.sdk_interface import copy_image
6162
from superannotate.lib.app.interface.sdk_interface import copy_images
6263
from superannotate.lib.app.interface.sdk_interface import create_annotation_class
@@ -162,6 +163,7 @@
162163

163164
__all__ = [
164165
"__version__",
166+
"controller",
165167
# Utils
166168
"AppException",
167169
#

src/superannotate/lib/app/helpers.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,30 @@ def get_annotation_paths(folder_path, s3_bucket=None, recursive=False):
4242
return get_s3_annotation_paths(
4343
folder_path, s3_bucket, annotation_paths, recursive
4444
)
45-
return get_local_annotation_paths(folder_path, annotation_paths, recursive)
45+
return get_local_annotation_paths(folder_path, set(annotation_paths), recursive)
4646

4747

4848
def get_local_annotation_paths(
49-
folder_path: Union[str, Path], annotation_paths: List, recursive: bool
49+
folder_path: Union[str, Path], annotation_paths: set, recursive: bool
5050
) -> List[str]:
51-
for path in Path(folder_path).glob("*"):
52-
if recursive and path.is_dir():
53-
get_local_annotation_paths(path, annotation_paths, recursive)
54-
for annotation_path in Path(folder_path).glob("*.json"):
55-
if (
56-
annotation_path.name.endswith(VECTOR_ANNOTATION_POSTFIX)
57-
or annotation_path.name.endswith(PIXEL_ANNOTATION_POSTFIX)
58-
) and str(annotation_path) not in annotation_paths:
59-
annotation_paths.append(str(annotation_path))
60-
return annotation_paths
51+
all_items = [*Path(folder_path).glob("*")]
52+
all_folders = [i for i in all_items if i.is_dir()]
53+
all_not_folders = [i for i in all_items if not i.is_dir()]
54+
annotation_paths.update(
55+
[
56+
str(i)
57+
for i in all_not_folders
58+
if i.name.endswith((VECTOR_ANNOTATION_POSTFIX, PIXEL_ANNOTATION_POSTFIX))
59+
]
60+
)
61+
if recursive:
62+
for folder in all_folders:
63+
get_local_annotation_paths(
64+
folder_path=folder,
65+
annotation_paths=annotation_paths,
66+
recursive=recursive,
67+
)
68+
return list(annotation_paths)
6169

6270

6371
def get_s3_annotation_paths(folder_path, s3_bucket, annotation_paths, recursive):
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import logging
2-
31
from lib.infrastructure.controller import Controller
42
from lib.infrastructure.repositories import ConfigRepository
53

64

7-
logger = logging.getLogger()
8-
9-
105
class BaseInterfaceFacade:
116
def __init__(self):
127
self._config_path = None
@@ -15,6 +10,7 @@ def __init__(self):
1510
def controller(self):
1611
if not ConfigRepository().get_one("token"):
1712
raise Exception("Config does not exists!")
13+
controller = Controller.get_instance()
1814
if self._config_path:
19-
return Controller(logger, self._config_path)
20-
return Controller(logger)
15+
controller.init(self._config_path)
16+
return controller

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import logging
32
import os
43
import sys
54
import tempfile
@@ -24,8 +23,8 @@
2423
from lib.infrastructure.controller import Controller
2524
from lib.infrastructure.repositories import ConfigRepository
2625

27-
logger = logging.getLogger()
28-
controller = Controller(logger)
26+
27+
controller = Controller.get_instance()
2928

3029

3130
class CLIFacade(BaseInterfaceFacade):

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
from tqdm import tqdm
5454

5555

56+
controller = Controller.get_instance()
5657
logger = logging.getLogger("root")
57-
controller = Controller(logger)
5858

5959

6060
@validate_arguments
61-
def init(path_to_config_json: str):
61+
def init(path_to_config_json: Optional[str] = None):
6262
"""
6363
Initializes and authenticates to SuperAnnotate platform using the config file.
6464
If not initialized then $HOME/.superannotate/config.json
@@ -67,7 +67,7 @@ def init(path_to_config_json: str):
6767
:param path_to_config_json: Location to config JSON file
6868
:type path_to_config_json: str or Path
6969
"""
70-
# global controller
70+
global controller
7171
controller.init(path_to_config_json)
7272

7373

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import Union
44

55
from lib.core.enums import AnnotationStatus
6-
from lib.core.exceptions import AppException
76
from pydantic import constr
87
from pydantic import StrictStr
98
from pydantic import validate_arguments as pydantic_validate_arguments

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import functools
22
import sys
33

4+
from lib.infrastructure.controller import Controller
45
from mixpanel import Mixpanel
5-
from superannotate.lib.infrastructure.controller import Controller
6-
from superannotate.version import __version__
6+
from version import __version__
77

88
from .config import TOKEN
99
from .utils import parsers
1010

1111
mp = Mixpanel(TOKEN)
1212

13-
controller = Controller.get_instance()
14-
1513

1614
def get_default(team_name, user_id, project_name=None):
1715
return {
@@ -38,23 +36,26 @@ def track(self, *args, **kwargs):
3836
data = getattr(parsers, self.function.__name__)(*args, **kwargs)
3937
event_name = data["event_name"]
4038
properties = data["properties"]
39+
team_data = self.__class__.TEAM_DATA.data
40+
user_id = team_data.creator_id
41+
team_name = team_data.name
4142
properties["Success"] = self._success
4243
default = get_default(
43-
team_name=self.__class__.TEAM_DATA[1],
44-
user_id=self.__class__.TEAM_DATA[0],
44+
team_name=team_name,
45+
user_id=user_id,
4546
project_name=properties.get("project_name", None),
4647
)
4748
properties.pop("project_name", None)
4849
properties = {**default, **properties}
4950

5051
if "pytest" not in sys.modules:
51-
mp.track(controller.user_id, event_name, properties)
52+
mp.track(user_id, event_name, properties)
5253
except Exception as _:
5354
pass
5455

5556
def __call__(self, *args, **kwargs):
5657
try:
57-
self.__class__.TEAM_DATA = controller.get_team()
58+
self.__class__.TEAM_DATA = Controller.get_instance().get_team()
5859
ret = self.function(*args, **kwargs)
5960
self._success = True
6061
except Exception as e:

src/superannotate/lib/app/mixp/utils/parsers.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import logging
1+
import lib.core as constances
2+
from lib.app.helpers import extract_project_folder
3+
from lib.core.enums import ProjectType
4+
from lib.infrastructure.controller import Controller
25

3-
import superannotate.lib.core as constances
4-
from superannotate.lib.app.helpers import extract_project_folder
5-
from superannotate.lib.core.enums import ProjectType
6-
from superannotate.lib.infrastructure.controller import Controller
7-
8-
controller = Controller(logger=logging.getLogger())
6+
controller = Controller.get_instance()
97

108

119
def get_project_name(project):

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,9 +2027,7 @@ def validate_limitations(self):
20272027
if response.data.folder_limit.remaining_image_count < 1:
20282028
raise AppValidationException(constances.COPY_FOLDER_LIMIT_ERROR_MESSAGE)
20292029
if response.data.project_limit.remaining_image_count < 1:
2030-
raise AppValidationException(
2031-
constances.COPY_PROJECT_LIMIT_ERROR_MESSAGE
2032-
)
2030+
raise AppValidationException(constances.COPY_PROJECT_LIMIT_ERROR_MESSAGE)
20332031
if (
20342032
response.data.user_limit
20352033
and response.data.user_limit.remaining_image_count < 1
@@ -2736,20 +2734,16 @@ def execute(self):
27362734
failed_annotations.append(annotation)
27372735
yield
27382736

2739-
uploaded_annotations = [
2740-
annotation.path for annotation in uploaded_annotations
2741-
]
2742-
missing_annotations.extend(
2743-
[annotation.path for annotation in self._missing_annotations]
2744-
)
2745-
failed_annotations = [
2746-
annotation.path for annotation in failed_annotations
2747-
]
2748-
self._response.data = (
2749-
uploaded_annotations,
2750-
failed_annotations,
2751-
missing_annotations,
2752-
)
2737+
uploaded_annotations = [annotation.path for annotation in uploaded_annotations]
2738+
missing_annotations.extend(
2739+
[annotation.path for annotation in self._missing_annotations]
2740+
)
2741+
failed_annotations = [annotation.path for annotation in failed_annotations]
2742+
self._response.data = (
2743+
uploaded_annotations,
2744+
failed_annotations,
2745+
missing_annotations,
2746+
)
27532747
self.report_missing_data()
27542748
return self._response
27552749

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ def execute(self):
833833
try:
834834
self._response.data = self._teams.get_one(self._team_id)
835835
except Exception:
836-
raise AppException("Can't get team data.")
836+
raise AppException("Can't get team data.") from None
837837
return self._response
838838

839839

0 commit comments

Comments
 (0)