Skip to content

Commit 177adc4

Browse files
committed
Merge branch 'depricated_functions' of https://github.com/superannotateai/superannotate-python-sdk into develop
2 parents eb2378a + f79923f commit 177adc4

File tree

4 files changed

+56
-29
lines changed

4 files changed

+56
-29
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 32 --dist=loadscope
5+
addopts = -n 32 --dist=loadscope

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

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from lib.app.helpers import get_annotation_paths
3030
from lib.app.helpers import get_paths_and_duplicated_from_csv
3131
from lib.app.helpers import reformat_metrics_json
32+
from lib.app.interface.types import AnnotationStatuses
3233
from lib.app.interface.types import AnnotationType
3334
from lib.app.interface.types import NotEmptyStr
3435
from lib.app.interface.types import Status
@@ -1646,7 +1647,7 @@ def upload_images_from_s3_bucket_to_project(
16461647
def prepare_export(
16471648
project: Union[NotEmptyStr, dict],
16481649
folder_names: Optional[List[NotEmptyStr]] = None,
1649-
annotation_statuses: Optional[List[NotEmptyStr]] = None,
1650+
annotation_statuses: Optional[List[AnnotationStatuses]] = None,
16501651
include_fuse: Optional[StrictBool] = False,
16511652
only_pinned=False,
16521653
):
@@ -2152,38 +2153,50 @@ def download_export(
21522153
"""
21532154
project_name, folder_name = extract_project_folder(project)
21542155
export_name = export["name"] if isinstance(export, dict) else export
2155-
response = controller.download_export(
2156-
project_name=project_name,
2157-
export_name=export_name,
2158-
folder_path=folder_path,
2159-
extract_zip_contents=extract_zip_contents,
2160-
to_s3_bucket=to_s3_bucket,
2161-
)
2162-
downloaded_folder_path = response.data
21632156

21642157
if to_s3_bucket:
2165-
to_s3_bucket = boto3.Session().resource("s3").Bucket(to_s3_bucket)
2166-
2167-
files_to_upload = []
2168-
for file in Path(downloaded_folder_path).rglob("*.*"):
2169-
files_to_upload.append(file)
2170-
2171-
def _upload_file_to_s3(to_s3_bucket, path, s3_key) -> None:
2172-
controller.upload_file_to_s3(
2173-
to_s3_bucket=to_s3_bucket, path=path, s3_key=s3_key
2158+
with tempfile.TemporaryDirectory() as tmp:
2159+
response = controller.download_export(
2160+
project_name=project_name,
2161+
export_name=export_name,
2162+
folder_path=tmp,
2163+
extract_zip_contents=extract_zip_contents,
2164+
to_s3_bucket=to_s3_bucket,
21742165
)
2166+
downloaded_folder_path = response.data
2167+
if to_s3_bucket:
2168+
to_s3_bucket = boto3.Session().resource("s3").Bucket(to_s3_bucket)
2169+
files_to_upload = []
2170+
for file in Path(downloaded_folder_path).rglob("*.*"):
2171+
files_to_upload.append(file)
2172+
2173+
def _upload_file_to_s3(to_s3_bucket, path, s3_key) -> None:
2174+
controller.upload_file_to_s3(
2175+
to_s3_bucket=to_s3_bucket, path=path, s3_key=s3_key
2176+
)
21752177

2176-
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
2177-
results = []
2178-
for path in files_to_upload:
2179-
s3_key = f"{path.as_posix()}"
2180-
results.append(
2181-
executor.submit(_upload_file_to_s3, to_s3_bucket, str(path), s3_key)
2178+
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
2179+
results = []
2180+
for path in files_to_upload:
2181+
s3_key = f"{folder_path}/{path.name}"
2182+
results.append(
2183+
executor.submit(
2184+
_upload_file_to_s3, to_s3_bucket, str(path), s3_key
2185+
)
2186+
)
2187+
for future in concurrent.futures.as_completed(results):
2188+
future.result()
2189+
logger.info(
2190+
"Exported to AWS %s/%s", to_s3_bucket.name, str(folder_path)
21822191
)
2183-
2184-
for future in concurrent.futures.as_completed(results):
2185-
future.result()
2186-
logger.info("Exported to AWS %s/%s", to_s3_bucket, str(path))
2192+
else:
2193+
controller.download_export(
2194+
project_name=project_name,
2195+
export_name=export_name,
2196+
folder_path=folder_path,
2197+
extract_zip_contents=extract_zip_contents,
2198+
to_s3_bucket=to_s3_bucket,
2199+
)
21872200

21882201

21892202
@Trackable

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ def validate(cls, value: Union[str]) -> Union[str]:
3434
return value
3535

3636

37+
class AnnotationStatuses(StrictStr):
38+
@classmethod
39+
def validate(cls, value: Union[str]) -> Union[str]:
40+
if value.lower() not in AnnotationStatus.values():
41+
raise TypeError(
42+
f"Available annotation_statuses are {', '.join(AnnotationStatus.titles())}. "
43+
)
44+
return value
45+
46+
3747
def to_chunks(t, size=2):
3848
it = iter(t)
3949
return zip(*[it] * size)

src/superannotate/lib/core/enums.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def get_value(cls, name):
2727
def values(cls):
2828
return [enum.name.lower() for enum in list(cls)]
2929

30+
@classmethod
31+
def titles(cls):
32+
return [enum.name for enum in list(cls)]
33+
3034

3135
class ProjectType(BaseTitledEnum):
3236
VECTOR = "Vector", 1

0 commit comments

Comments
 (0)