Skip to content

Commit f1a3292

Browse files
committed
updated project creation
1 parent e1abe2c commit f1a3292

File tree

13 files changed

+281
-234
lines changed

13 files changed

+281
-234
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.0
33
log_cli=true
44
python_files = test_*.py
5-
;addopts = -n auto --dist=loadscope
5+
addopts = -n auto --dist=loadscope

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from lib.app.interface.types import NotEmptyStr
3232
from lib.app.interface.types import ProjectStatusEnum
3333
from lib.app.interface.types import ProjectTypes
34+
from lib.app.interface.types import Setting
3435
from lib.app.interface.types import validate_arguments
3536
from lib.app.mixp.decorators import Trackable
3637
from lib.app.serializers import BaseSerializer
@@ -41,6 +42,7 @@
4142
from lib.app.serializers import TeamSerializer
4243
from lib.core import LIMITED_FUNCTIONS
4344
from lib.core.entities import AttachmentEntity
45+
from lib.core.entities import SettingEntity
4446
from lib.core.entities.integrations import IntegrationEntity
4547
from lib.core.entities.project_entities import AnnotationClassEntity
4648
from lib.core.enums import ImageQuality
@@ -181,21 +183,31 @@ def create_project(
181183
project_name: NotEmptyStr,
182184
project_description: NotEmptyStr,
183185
project_type: NotEmptyStr,
186+
settings: List[Setting] = None
184187
):
185188
"""Create a new project in the team.
186189
187190
:param project_name: the new project's name
188191
:type project_name: str
192+
189193
:param project_description: the new project's description
190194
:type project_description: str
195+
191196
:param project_type: the new project type, Vector or Pixel.
192197
:type project_type: str
193198
199+
:param settings: list of settings objects
200+
:type settings: list of dicts
201+
194202
:return: dict object metadata the new project
195203
:rtype: dict
196204
"""
205+
if settings:
206+
settings = parse_obj_as(List[SettingEntity], settings)
207+
else:
208+
settings = []
197209
response = Controller.get_default().create_project(
198-
name=project_name, description=project_description, project_type=project_type
210+
name=project_name, description=project_description, project_type=project_type, settings=settings
199211
)
200212
if response.errors:
201213
raise AppException(response.errors)
@@ -218,7 +230,7 @@ def create_project_from_metadata(project_metadata: Project):
218230
name=project_metadata["name"],
219231
description=project_metadata.get("description"),
220232
project_type=project_metadata["type"],
221-
settings=project_metadata.get("settings", []),
233+
settings=parse_obj_as(List[SettingEntity], project_metadata.get("settings", [])),
222234
annotation_classes=project_metadata.get("classes", []),
223235
workflows=project_metadata.get("workflows", []),
224236
instructions_link=project_metadata.get("instructions_link"),

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ def __eq__(self, other):
107107
AttachmentArgType = Union[NotEmptyStr, Path, conlist(AttachmentDict, min_items=1)]
108108

109109

110+
class Setting(BaseModel):
111+
attribute: NotEmptyStr
112+
value: Union[NotEmptyStr, float, int]
113+
114+
class Config:
115+
extra = Extra.ignore
116+
117+
110118
class AttachmentArg(BaseModel):
111119
__root__: AttachmentArgType
112120

src/superannotate/lib/core/entities/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from lib.core.entities.base import AttachmentEntity
22
from lib.core.entities.base import BaseEntity as TmpBaseEntity
3+
from lib.core.entities.base import SettingEntity
34
from lib.core.entities.integrations import IntegrationEntity
45
from lib.core.entities.items import DocumentEntity
56
from lib.core.entities.items import Entity
@@ -13,7 +14,6 @@
1314
from lib.core.entities.project_entities import ImageInfoEntity
1415
from lib.core.entities.project_entities import MLModelEntity
1516
from lib.core.entities.project_entities import ProjectEntity
16-
from lib.core.entities.project_entities import ProjectSettingEntity
1717
from lib.core.entities.project_entities import S3FileEntity
1818
from lib.core.entities.project_entities import TeamEntity
1919
from lib.core.entities.project_entities import UserEntity
@@ -27,6 +27,8 @@
2727
)
2828

2929
__all__ = [
30+
# base
31+
"SettingEntity",
3032
# items
3133
"TmpImageEntity",
3234
"BaseEntity",
@@ -38,7 +40,6 @@
3840
"AttachmentEntity",
3941
# project
4042
"ProjectEntity",
41-
"ProjectSettingEntity",
4243
"ConfigEntity",
4344
"WorkflowEntity",
4445
"FolderEntity",

src/superannotate/lib/core/entities/base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import uuid
22
from datetime import datetime
33
from typing import Optional
4+
from typing import Union
45

56
from lib.core.enums import AnnotationStatus
67
from pydantic import BaseModel
78
from pydantic import Extra
89
from pydantic import Field
10+
from pydantic import StrictFloat
11+
from pydantic import StrictInt
12+
from pydantic import StrictStr
913

1014

1115
class TimedBaseModel(BaseModel):
@@ -34,3 +38,16 @@ class AttachmentEntity(BaseModel):
3438

3539
class Config:
3640
extra = Extra.ignore
41+
42+
43+
class SettingEntity(BaseModel):
44+
id: Optional[int]
45+
project_id: Optional[int]
46+
attribute: str
47+
value: Union[StrictStr, StrictInt, StrictFloat]
48+
49+
class Config:
50+
extra = Extra.ignore
51+
52+
def __copy__(self):
53+
return SettingEntity(attribute=self.attribute, value=self.value)

src/superannotate/lib/core/entities/project_entities.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -155,31 +155,6 @@ def to_dict(self):
155155
}
156156

157157

158-
class ProjectSettingEntity(BaseEntity):
159-
def __init__(
160-
self,
161-
uuid: int = None,
162-
project_id: int = None,
163-
attribute: str = None,
164-
value: Any = None,
165-
):
166-
super().__init__(uuid)
167-
self.project_id = project_id
168-
self.attribute = attribute
169-
self.value = value
170-
171-
def __copy__(self):
172-
return ProjectSettingEntity(attribute=self.attribute, value=self.value)
173-
174-
def to_dict(self):
175-
return {
176-
"id": self.uuid,
177-
"project_id": self.project_id,
178-
"attribute": self.attribute,
179-
"value": self.value,
180-
}
181-
182-
183158
class WorkflowEntity(BaseEntity):
184159
def __init__(
185160
self,

src/superannotate/lib/core/repositories.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import ABC
2+
from abc import ABCMeta
23
from abc import abstractmethod
34
from typing import Any
45
from typing import List
@@ -42,7 +43,7 @@ def update(self, entity: BaseEntity) -> BaseEntity:
4243
raise NotImplementedError
4344

4445
@abstractmethod
45-
def delete(self, uuid: Any, *args):
46+
def delete(self, uuid: Any):
4647
raise NotImplementedError
4748

4849
def bulk_delete(self, entities: List[BaseEntity]) -> bool:
@@ -56,7 +57,7 @@ def _drop_nones(data: dict):
5657
return data
5758

5859

59-
class BaseProjectRelatedManageableRepository(BaseManageableRepository):
60+
class BaseProjectRelatedManageableRepository(BaseManageableRepository, metaclass=ABCMeta):
6061
def __init__(self, service: SuperannotateServiceProvider, project: ProjectEntity):
6162
self._service = service
6263
self._project = project

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
from lib.core.entities import ImageEntity
2727
from lib.core.entities import ImageInfoEntity
2828
from lib.core.entities import ProjectEntity
29-
from lib.core.entities import ProjectSettingEntity
3029
from lib.core.entities import S3FileEntity
30+
from lib.core.entities import SettingEntity
3131
from lib.core.enums import ImageQuality
3232
from lib.core.enums import ProjectType
3333
from lib.core.exceptions import AppException
@@ -1514,7 +1514,7 @@ class UploadImageS3UseCase(BaseUseCase):
15141514
def __init__(
15151515
self,
15161516
project: ProjectEntity,
1517-
project_settings: List[ProjectSettingEntity],
1517+
project_settings: List[SettingEntity],
15181518
image_path: str,
15191519
image: io.BytesIO,
15201520
s3_repo: BaseManageableRepository,
@@ -1714,7 +1714,7 @@ def __init__(
17141714
backend_service: SuperannotateServiceProvider,
17151715
images: BaseManageableRepository,
17161716
s3_repo,
1717-
project_settings: List[ProjectSettingEntity],
1717+
project_settings: List[SettingEntity],
17181718
include_annotations: Optional[bool] = True,
17191719
copy_annotation_status: Optional[bool] = True,
17201720
copy_pin: Optional[bool] = True,

0 commit comments

Comments
 (0)