Skip to content

Commit c26d731

Browse files
author
Vaghinak Basentsyan
committed
Added email regex
1 parent 32d9257 commit c26d731

File tree

7 files changed

+47
-38
lines changed

7 files changed

+47
-38
lines changed

docs/source/cli.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ Only when COCO format is specified *dataset-name* and *task* arguments are requi
148148
*task* specifies the COCO task for conversion. Please see
149149
:ref:`import_annotation_format <ref_import_annotation_format>` for more details.
150150
151-
The annotation classes will be created during the execution of this command.
152151
153152
----------
154153
@@ -176,8 +175,6 @@ Only when COCO format is specified *dataset-name* and *task* arguments are requi
176175
*task* specifies the COCO task for conversion. Please see
177176
:ref:`import_annotation_format <ref_import_annotation_format>` for more details.
178177

179-
The annotation classes will be created during the execution of this command.
180-
181178
----------
182179

183180
.. _ref_export_project:

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=lo adscope

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def export_project(
144144
sys.exit(0)
145145

146146
def upload_preannotations(
147-
self, project, folder, data_set_name=None, task=None, format=None
147+
self, project, folder, dataset_name=None, task=None, format=None
148148
):
149149
"""
150150
To upload preannotations from folder to project use
@@ -153,20 +153,19 @@ def upload_preannotations(
153153
Only when COCO format is specified dataset-name and task arguments are required.
154154
dataset-name specifies JSON filename (without extension) in <folder_path>.
155155
task specifies the COCO task for conversion. Please see import_annotation_format for more details.
156-
The annotation classes will be created during the execution of this command.
157156
"""
158157
self._upload_annotations(
159158
project=project,
160159
folder=folder,
161160
format=format,
162-
data_set_name=data_set_name,
161+
dataset_name=dataset_name,
163162
task=task,
164163
pre=True,
165164
)
166165
sys.exit(0)
167166

168167
def upload_annotations(
169-
self, project, folder, data_set_name=None, task=None, format=None
168+
self, project, folder, dataset_name=None, task=None, format=None
170169
):
171170
"""
172171
To upload annotations from folder to project use
@@ -175,29 +174,28 @@ def upload_annotations(
175174
Only when COCO format is specified dataset-name and task arguments are required.
176175
dataset-name specifies JSON filename (without extension) in <folder_path>.
177176
task specifies the COCO task for conversion. Please see import_annotation_format for more details.
178-
The annotation classes will be created during the execution of this command.
179177
"""
180178
self._upload_annotations(
181179
project=project,
182180
folder=folder,
183181
format=format,
184-
data_set_name=data_set_name,
182+
dataset_name=dataset_name,
185183
task=task,
186184
pre=False,
187185
)
188186
sys.exit(0)
189187

190188
def _upload_annotations(
191-
self, project, folder, format, data_set_name, task, pre=True
189+
self, project, folder, format, dataset_name, task, pre=True
192190
):
193191
project_name, folder_name = split_project_path(project)
194192
project = self.controller.get_project_metadata(project_name=project_name).data
195193
if not format:
196194
format = "SuperAnnotate"
197-
if not data_set_name and format == "COCO":
195+
if not dataset_name and format == "COCO":
198196
raise Exception("Data-set name is required")
199-
elif not data_set_name:
200-
data_set_name = ""
197+
elif not dataset_name:
198+
dataset_name = ""
201199
if not task:
202200
task = "object_detection"
203201
annotations_path = folder
@@ -207,7 +205,7 @@ def _upload_annotations(
207205
input_dir=folder,
208206
output_dir=temp_dir,
209207
dataset_format=format,
210-
dataset_name=data_set_name,
208+
dataset_name=dataset_name,
211209
project_type=constances.ProjectType.get_name(
212210
project["project"].project_type
213211
),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from lib.app.interface.types import NotEmptyStr
2626
from lib.app.interface.types import ProjectTypes
2727
from lib.app.interface.types import validate_arguments
28+
from lib.app.interface.types import EmailStr
2829
from lib.app.mixp.decorators import Trackable
2930
from lib.app.serializers import BaseSerializers
3031
from lib.app.serializers import ImageSerializer
@@ -40,7 +41,6 @@
4041
from lib.core.types import MLModel
4142
from lib.core.types import Project
4243
from lib.infrastructure.controller import Controller
43-
from pydantic import EmailStr
4444
from pydantic import parse_obj_as
4545
from pydantic import StrictBool
4646
from tqdm import tqdm

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@
1010
from pydantic import StrictStr
1111
from pydantic import validate_arguments as pydantic_validate_arguments
1212
from pydantic import ValidationError
13+
from pydantic.errors import StrRegexError
14+
1315

1416
NotEmptyStr = constr(strict=True, min_length=1)
1517

1618

19+
class EmailStr(StrictStr):
20+
@classmethod
21+
def validate(cls, value: Union[str]) -> Union[str]:
22+
try:
23+
constr(
24+
regex=r"^(?=.{1,254}$)(?=.{1,64}@)[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
25+
).validate(value)
26+
except StrRegexError:
27+
raise ValueError("Invalid email")
28+
return value
29+
30+
1731
class Status(StrictStr):
1832
@classmethod
1933
def validate(cls, value: Union[str]) -> Union[str]:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ def execute(self):
10391039
emails = set(self._emails)
10401040

10411041
to_skip = emails.intersection(team_users)
1042-
to_add = emails.difference(to_skip)
1042+
to_add = list(emails.difference(to_skip))
10431043

10441044
if to_skip:
10451045
self.reporter.log_warning(

tests/integration/test_cli.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def _create_project(self, project_type="Vector"):
9696
shell=True,
9797
)
9898

99-
@pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
100-
reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
99+
# @pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
100+
# reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
101101
def test_create_folder(self):
102102
self._create_project()
103103
subprocess.run(
@@ -110,8 +110,8 @@ def test_create_folder(self):
110110
)
111111
self.assertEqual(self.FOLDER_NAME, folder["name"])
112112

113-
@pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
114-
reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
113+
# @pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
114+
# reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
115115
def test_upload_images(self):
116116
self._create_project()
117117
subprocess.run(
@@ -124,8 +124,8 @@ def test_upload_images(self):
124124
)
125125
self.assertEqual(1, len(sa.search_images(self.PROJECT_NAME)))
126126

127-
@pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
128-
reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
127+
# @pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
128+
# reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
129129
def test_upload_export(self):
130130
self._create_project()
131131
with tempfile.TemporaryDirectory() as temp_dir:
@@ -140,8 +140,8 @@ def test_upload_export(self):
140140
self.assertEqual(len(list(test_dir.glob("*.jpg"))), 0)
141141
self.assertEqual(len(list(test_dir.glob("*.png"))), 0)
142142

143-
@pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
144-
reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
143+
# @pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
144+
# reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
145145
def test_vector_pre_annotation_folder_upload_download_cli(self):
146146
self._create_project()
147147

@@ -169,8 +169,8 @@ def test_vector_pre_annotation_folder_upload_download_cli(self):
169169
)
170170
# tod add test
171171

172-
@pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
173-
reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
172+
# @pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
173+
# reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
174174
def test_vector_annotation_folder_upload_download_cli(self):
175175
self._create_project()
176176
sa.create_annotation_classes_from_classes_json(
@@ -194,18 +194,18 @@ def test_vector_annotation_folder_upload_download_cli(self):
194194
check=True,
195195
shell=True,
196196
)
197-
# from src.superannotate.lib.app.interface.cli_interface import CLIFacade
198-
# # self, project, folder, data_set_name = None, task = None, format = None
199-
# cli_facade = CLIFacade().upload_annotations(self.PROJECT_NAME,self.convertor_data_path,"instances_test",None,"COCO")
197+
from src.superannotate.lib.app.interface.cli_interface import CLIFacade
198+
# self, project, folder, dataset_name = None, task = None, format = None
199+
cli_facade = CLIFacade().upload_annotations(self.PROJECT_NAME,self.convertor_data_path,"instances_test",None,"COCO")
200200
count_in = len(list(self.vector_folder_path.glob("*.json")))
201201
with tempfile.TemporaryDirectory() as temp_dir:
202202
for image_name in sa.search_images(self.PROJECT_NAME):
203203
sa.download_image_annotations(self.PROJECT_NAME, image_name, temp_dir)
204204
count_out = len(list(Path(temp_dir).glob("*.json")))
205205
self.assertEqual(count_in, count_out)
206206

207-
@pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
208-
reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
207+
# @pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
208+
# reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
209209
def test_attach_image_urls(self):
210210
self._create_project()
211211
subprocess.run(
@@ -218,8 +218,8 @@ def test_attach_image_urls(self):
218218

219219
self.assertEqual(3, len(sa.search_images(self.PROJECT_NAME)))
220220

221-
@pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
222-
reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
221+
# @pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
222+
# reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
223223
def test_attach_video_urls(self):
224224
self._create_project("Video")
225225
subprocess.run(
@@ -231,8 +231,8 @@ def test_attach_video_urls(self):
231231
)
232232
# self.assertEqual(3, len(sa.search_images(self.PROJECT_NAME)))
233233

234-
@pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
235-
reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
234+
# @pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
235+
# reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
236236
def test_upload_videos(self):
237237
self._create_project()
238238
subprocess.run(
@@ -245,8 +245,8 @@ def test_upload_videos(self):
245245
)
246246
self.assertEqual(5, len(sa.search_images(self.PROJECT_NAME)))
247247

248-
@pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
249-
reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
248+
# @pytest.mark.skipif(CLI_VERSION and CLI_VERSION != sa.__version__,
249+
# reason=f"Updated package version from {CLI_VERSION} to {sa.__version__}")
250250
def test_attach_document_urls(self):
251251
self._create_project("Document")
252252
subprocess.run(

0 commit comments

Comments
 (0)