Skip to content

Commit 105800c

Browse files
committed
Add depricated functions per project type
1 parent a22f5e7 commit 105800c

File tree

7 files changed

+133
-121
lines changed

7 files changed

+133
-121
lines changed

superannotate/.DS_Store

6 KB
Binary file not shown.

superannotate/common.py

Lines changed: 91 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -59,45 +59,96 @@
5959
"Semantic Segmentation for Pixel Projects": "semantic_segmentation_pixel"
6060
}
6161

62-
VIDEO_DEPRICATED_FUNCTIONS = [
63-
"upload_images_from_folder_to_project",
64-
"get_image_metadata",
65-
"search_images",
66-
"upload_images_to_project",
67-
"upload_annotations_from_folder_to_project",
68-
"upload_image_annotations",
69-
"download_image",
70-
"download_image_annotations",
71-
"get_image_annotations",
72-
"set_image_annotation_status",
73-
"aggregate_annotations_as_df",
74-
"attach_image_urls_to_project",
75-
"clone_project",
76-
"copy_image",
77-
"export_annotation",
78-
"upload_image_to_project",
79-
"upload_video_to_project",
80-
"add_annotation_bbox_to_image",
81-
"assign_images",
82-
"delete_images",
83-
"get_project_image_count",
84-
"set_project_workflow",
85-
"upload_preannotations_from_folder_to_project",
86-
"upload_videos_from_folder_to_project",
87-
"add_annotation_comment_to_image",
88-
"add_annotation_point_to_image",
89-
"benchmark",
90-
"class_distribution",
91-
"consensus",
92-
"convert_project_type",
93-
"copy_images",
94-
"get_project_workflow",
95-
"move_image",
96-
"move_images",
97-
"set_images_annotation_statuses",
98-
"set_project_default_image_quality_in_editor",
99-
"upload_images_from_google_cloud_to_project",
100-
]
62+
DEPRICATED_FUNCTIONS_PER_PROJECT_TYPE = {
63+
"Vector": [],
64+
"Pixel": [],
65+
"Video": [
66+
"attach_document_urls_to_project",
67+
"upload_images_from_folder_to_project",
68+
"get_image_metadata",
69+
"search_images",
70+
"upload_images_to_project",
71+
"upload_annotations_from_folder_to_project",
72+
"upload_image_annotations",
73+
"download_image",
74+
"download_image_annotations",
75+
"get_image_annotations",
76+
"set_image_annotation_status",
77+
"aggregate_annotations_as_df",
78+
"attach_image_urls_to_project",
79+
"clone_project",
80+
"copy_image",
81+
"export_annotation",
82+
"upload_image_to_project",
83+
"upload_video_to_project",
84+
"add_annotation_bbox_to_image",
85+
"assign_images",
86+
"delete_images",
87+
"get_project_image_count",
88+
"set_project_workflow",
89+
"upload_preannotations_from_folder_to_project",
90+
"upload_videos_from_folder_to_project",
91+
"add_annotation_comment_to_image",
92+
"add_annotation_point_to_image",
93+
"benchmark",
94+
"class_distribution",
95+
"consensus",
96+
"convert_project_type",
97+
"copy_images",
98+
"get_project_workflow",
99+
"move_image",
100+
"move_images",
101+
"set_images_annotation_statuses",
102+
"set_project_default_image_quality_in_editor",
103+
"upload_images_from_google_cloud_to_project",
104+
"get_image_bytes",
105+
"upload_images_from_azure_blob_to_project",
106+
"upload_images_from_public_urls_to_project"
107+
],
108+
"Document": [
109+
"attach_video_urls_to_project",
110+
"upload_images_from_folder_to_project",
111+
"get_image_metadata",
112+
"search_images",
113+
"upload_images_to_project",
114+
"upload_annotations_from_folder_to_project",
115+
"upload_image_annotations",
116+
"download_image",
117+
"download_image_annotations",
118+
"get_image_annotations",
119+
"set_image_annotation_status",
120+
"aggregate_annotations_as_df",
121+
"attach_image_urls_to_project",
122+
"clone_project",
123+
"copy_image",
124+
"export_annotation",
125+
"upload_image_to_project",
126+
"upload_video_to_project",
127+
"add_annotation_bbox_to_image",
128+
"assign_images",
129+
"delete_images",
130+
"get_project_image_count",
131+
"set_project_workflow",
132+
"upload_preannotations_from_folder_to_project",
133+
"upload_videos_from_folder_to_project",
134+
"add_annotation_comment_to_image",
135+
"add_annotation_point_to_image",
136+
"benchmark",
137+
"class_distribution",
138+
"consensus",
139+
"convert_project_type",
140+
"copy_images",
141+
"get_project_workflow",
142+
"move_image",
143+
"move_images",
144+
"set_images_annotation_statuses",
145+
"set_project_default_image_quality_in_editor",
146+
"upload_images_from_google_cloud_to_project",
147+
"get_image_bytes",
148+
"upload_images_from_azure_blob_to_project",
149+
"upload_images_from_public_urls_to_project"
150+
],
151+
}
101152

102153

103154
def prediction_segmentation_status_from_str_to_int(status):
@@ -364,7 +415,7 @@ def write_to_json(output_path, json_data):
364415

365416

366417
def tqdm_converter(
367-
total_num, images_converted, images_not_converted, finish_event
418+
total_num, images_converted, images_not_converted, finish_event
368419
):
369420
with tqdm(total=total_num) as pbar:
370421
while True:

superannotate/db/images.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,6 @@ def download_image(
659659
)
660660

661661
project, project_folder = get_project_and_folder_metadata(project)
662-
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
663-
project_type = project['type']
664-
if upload_state == "External":
665-
raise SABaseException(
666-
0,
667-
f"The function does not support projects containing {project_type} attached with URLs"
668-
)
669662
img = get_image_bytes(
670663
(project, project_folder), image_name, variant=variant
671664
)
@@ -736,14 +729,7 @@ def get_image_bytes(project, image_name, variant='original'):
736729
:rtype: io.BytesIO()
737730
"""
738731
project, project_folder = get_project_and_folder_metadata(project)
739-
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
740-
project_type = project['type']
741732

742-
if upload_state == "External":
743-
raise SABaseException(
744-
0,
745-
f"The function does not support projects containing {project_type} attached with URLs"
746-
)
747733
if variant not in ["original", "lores"]:
748734
raise SABaseException(
749735
0, "Image download variant should be either original or lores"

superannotate/db/project_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def get_project_metadata_bare(project_name, include_complete_image_count=False):
4949
current_frame.f_back.f_back
5050
).function
5151
if res.get("type") and res["type"] in ["Video","Document"] and (
52-
outer_function in common.VIDEO_DEPRICATED_FUNCTIONS or
53-
outer_outer_function in common.VIDEO_DEPRICATED_FUNCTIONS
52+
outer_function in common.DEPRICATED_FUNCTIONS_PER_PROJECT_TYPE[res["type"]] or
53+
outer_outer_function in common.DEPRICATED_FUNCTIONS_PER_PROJECT_TYPE[res["type"]]
5454
):
5555
raise SABaseException(
5656
0,
@@ -152,8 +152,8 @@ def get_project_and_folder_metadata(project):
152152
current_frame.f_back.f_back
153153
).function
154154
if project.get("type") and project["type"] in ["Video","Document"] \
155-
and (outer_function in common.VIDEO_DEPRICATED_FUNCTIONS
156-
or outer_outer_function in common.VIDEO_DEPRICATED_FUNCTIONS):
155+
and (outer_function in common.DEPRICATED_FUNCTIONS_PER_PROJECT_TYPE[project["type"]]
156+
or outer_outer_function in common.DEPRICATED_FUNCTIONS_PER_PROJECT_TYPE[project["type"]]):
157157
project_type = project['type']
158158
raise SABaseException(
159159
0,

superannotate/db/project_images.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ def upload_image_to_project(
5757
"""
5858
initial_project_inp = project
5959
project, folder = get_project_and_folder_metadata(project)
60-
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
61-
project_type = project["type"]
62-
if upload_state == "External":
63-
raise SABaseException(
64-
0,
65-
f"The function does not support projects containing {project_type} attached with URLs"
66-
)
6760
annotation_status = common.annotation_status_str_to_int(annotation_status)
6861
if image_quality_in_editor is None:
6962
image_quality_in_editor = get_project_default_image_quality_in_editor(

superannotate/db/projects.py

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,6 @@ def upload_video_to_project(
417417

418418
limit = _get_available_image_counts(project, folder)
419419

420-
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
421-
project_type = project.get("type")
422-
423-
if upload_state == "External":
424-
raise SABaseException(
425-
0,
426-
f"The function does not support projects containing {project_type} attached with URLs"
427-
)
428420
logger.info("Uploading from video %s.", str(video_path))
429421
tempdir = tempfile.TemporaryDirectory()
430422
upload_file_names = []
@@ -519,14 +511,7 @@ def upload_videos_from_folder_to_project(
519511
:rtype: tuple of list of strs
520512
"""
521513
project, folder = get_project_and_folder_metadata(project)
522-
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
523-
project_type = project.get("type")
524514

525-
if upload_state == "External":
526-
raise SABaseException(
527-
0,
528-
f"The function does not support projects containing {project_type}attached with URLs"
529-
)
530515
if recursive_subfolders:
531516
logger.warning(
532517
"When using recursive subfolder parsing same name videos in different subfolders will overwrite each other."
@@ -618,14 +603,7 @@ def upload_images_from_folder_to_project(
618603
project_folder_name = project["name"] + (
619604
f'/{project_folder["name"]}' if project_folder else ""
620605
)
621-
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
622-
project_type = project.get("type")
623606

624-
if upload_state == "External":
625-
raise SABaseException(
626-
0,
627-
f"The function does not support projects containing {project_type} attached with URLs"
628-
)
629607
if recursive_subfolders:
630608
logger.info(
631609
"When using recursive subfolder parsing same name images in different subfolders will overwrite each other."
@@ -720,14 +698,7 @@ def upload_images_to_project(
720698
"""
721699
project, folder = get_project_and_folder_metadata(project)
722700
folder_name = project["name"] + (f'/{folder["name"]}' if folder else "")
723-
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
724-
project_type = project.get("type")
725701

726-
if upload_state == "External":
727-
raise SABaseException(
728-
0,
729-
f"The function does not support projects containing {project_type} attached with URLs"
730-
)
731702
if not isinstance(img_paths, list):
732703
raise SABaseException(
733704
0, "img_paths argument to upload_images_to_project should be a list"
@@ -793,8 +764,8 @@ def attach_image_urls_to_project(
793764
:return: attached images, failed images, skipped images
794765
:rtype: (list, list, list)
795766
"""
796-
get_project_and_folder_metadata(project)
797-
return attach_file_urls_to_project(project, attachments, annotation_status)
767+
project, folder = get_project_and_folder_metadata(project)
768+
return attach_file_urls_to_project(project, folder, attachments, annotation_status)
798769

799770

800771
@Trackable
@@ -832,13 +803,7 @@ def upload_images_from_public_urls_to_project(
832803
duplicate_images_filenames = []
833804
path_to_url = {}
834805
project, project_folder = get_project_and_folder_metadata(project)
835-
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
836-
project_type = project.get('type')
837-
if upload_state == "External":
838-
raise SABaseException(
839-
0,
840-
f"The function does not support projects containing {project_type} attached with URLs"
841-
)
806+
842807
finish_event = threading.Event()
843808
tqdm_thread = threading.Thread(
844809
target=_tqdm_download,
@@ -942,14 +907,7 @@ def upload_images_from_google_cloud_to_project(
942907
duplicate_images_filenames = []
943908
path_to_url = {}
944909
project, project_folder = get_project_and_folder_metadata(project)
945-
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
946-
project_type = project.get("type")
947910

948-
if upload_state == "External":
949-
raise SABaseException(
950-
0,
951-
f"The function does not support projects containing {project_type} attached with URLs"
952-
)
953911
cloud_client = storage.Client(project=google_project)
954912
bucket = cloud_client.get_bucket(bucket_name)
955913
image_blobs = bucket.list_blobs(prefix=folder_path)
@@ -1028,13 +986,6 @@ def upload_images_from_azure_blob_to_project(
1028986
duplicate_images_filenames = []
1029987
path_to_url = {}
1030988
project, project_folder = get_project_and_folder_metadata(project)
1031-
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
1032-
project_type = project.get('type')
1033-
if upload_state == "External":
1034-
raise SABaseException(
1035-
0,
1036-
f"The function does not support projects containing {project_type} attached with URLs"
1037-
)
1038989
connect_key = os.getenv('AZURE_STORAGE_CONNECTION_STRING')
1039990
blob_service_client = BlobServiceClient.from_connection_string(connect_key)
1040991
container_client = blob_service_client.get_container_client(container_name)
@@ -2013,10 +1964,11 @@ def attach_video_urls_to_project(
20131964
:return: attached videos, failed videos, skipped videos
20141965
:rtype: (list, list, list)
20151966
"""
2016-
return attach_file_urls_to_project(project, attachments, annotation_status)
1967+
project, folder = get_project_and_folder_metadata(project)
1968+
return attach_file_urls_to_project(project,folder, attachments, annotation_status)
20171969

20181970

2019-
def attach_file_urls_to_project(project, attachments, annotation_status):
1971+
def attach_file_urls_to_project(project,folder,attachments, annotation_status):
20201972
"""Link files on external storage to SuperAnnotate.
20211973
20221974
:param project: project name or project folder path
@@ -2031,7 +1983,6 @@ def attach_file_urls_to_project(project, attachments, annotation_status):
20311983
:return: attached files, failed files, skipped files
20321984
:rtype: (list, list, list)
20331985
"""
2034-
project, folder = get_project_and_folder_metadata(project)
20351986
folder_name = project["name"] + (f'/{folder["name"]}' if folder else "")
20361987
upload_state = common.upload_state_int_to_str(project.get("upload_state"))
20371988
if upload_state == "Basic":
@@ -2104,5 +2055,6 @@ def attach_document_urls_to_project(
21042055
:return: attached videos, failed videos, skipped videos
21052056
:rtype: (list, list, list)
21062057
"""
2107-
return attach_file_urls_to_project(project, attachments, annotation_status)
2058+
project, folder = get_project_and_folder_metadata(project)
2059+
return attach_file_urls_to_project(project,folder, attachments, annotation_status)
21082060

tests/test_attach_text.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,33 @@ def test_attach_text_urls():
7474
assert str(
7575
e
7676
) == f"The function does not support projects containing {PROJECT_TYPE} attached with URLs"
77+
78+
79+
with pytest.raises(SABaseException) as e:
80+
sa.attach_video_urls_to_project(
81+
PROJECT_NAME_TEXT, PATH_TO_URLS
82+
)
83+
assert str(
84+
e
85+
) == f"The function does not support projects containing {PROJECT_TYPE} attached with URLs"
86+
87+
88+
def test_attach_text_to_video():
89+
project_name_video = "video t"
90+
project_type_video = "Video"
91+
projects = sa.search_projects(project_name_video, return_metadata=True)
92+
for project in projects:
93+
sa.delete_project(project)
94+
95+
time.sleep(1)
96+
sa.create_project(project_name_video, "test", project_type_video)
97+
time.sleep(1)
98+
99+
with pytest.raises(SABaseException) as e:
100+
sa.attach_document_urls_to_project(
101+
project_name_video, PATH_TO_URLS
102+
)
103+
assert str(
104+
e
105+
) == f"The function does not support projects containing {project_type_video} attached with URLs"
106+

0 commit comments

Comments
 (0)