From 2027bfc5d9c5771370a3ec858c80706fcac00eb2 Mon Sep 17 00:00:00 2001 From: Vaghinak Basentsyan Date: Fri, 24 Sep 2021 16:53:29 +0400 Subject: [PATCH 1/2] tod --- .../lib/app/interface/sdk_interface.py | 5 ++++- src/superannotate/lib/core/types.py | 1 + src/superannotate/lib/core/usecases.py | 13 +++---------- src/superannotate/lib/infrastructure/services.py | 1 + tests/integration/test_interface.py | 12 ++++++++++++ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/superannotate/lib/app/interface/sdk_interface.py b/src/superannotate/lib/app/interface/sdk_interface.py index 046c78bb5..c2ef8ce22 100644 --- a/src/superannotate/lib/app/interface/sdk_interface.py +++ b/src/superannotate/lib/app/interface/sdk_interface.py @@ -3517,7 +3517,10 @@ def upload_images_to_project( with tqdm(total=len(images_to_upload), desc="Uploading images") as progress_bar: for _ in use_case.execute(): progress_bar.update(1) - return use_case.data + uploaded, failed_images, duplications = use_case.data + if duplications: + logger.info(f"Duplicated images {', '.join(duplications)}") + return uploaded, failed_images, duplications raise AppException(use_case.response.errors) diff --git a/src/superannotate/lib/core/types.py b/src/superannotate/lib/core/types.py index 61d673221..a6590c18b 100644 --- a/src/superannotate/lib/core/types.py +++ b/src/superannotate/lib/core/types.py @@ -17,6 +17,7 @@ class Attribute(BaseModel): class AttributeGroup(BaseModel): name: StrictStr + is_multiselect: Optional[int] attributes: List[Attribute] diff --git a/src/superannotate/lib/core/usecases.py b/src/superannotate/lib/core/usecases.py index 4f9579a77..839332ab6 100644 --- a/src/superannotate/lib/core/usecases.py +++ b/src/superannotate/lib/core/usecases.py @@ -3268,9 +3268,6 @@ def execute(self): annotations, fuse_image, ) - logger.info( - "Downloaded image %s to %s.", self._image.name, str(download_path) - ) return self._response @@ -4067,6 +4064,8 @@ def download_to_local_storage(self, destination: str): project_id=self._project.uuid, export_id=export["id"], ) + if "error" in export: + raise AppException(export["error"]) export_status = export["status"] if export_status in (ExportStatus.ERROR.value, ExportStatus.CANCELED.value): raise AppException("Couldn't download export.") @@ -4877,7 +4876,7 @@ def _upload_image(self, image_path: str): else: try: image_bytes = io.BytesIO(open(image_path, "rb").read()) - except FileNotFoundError: + except OSError: return ProcessedImage( uploaded=False, path=image_path, @@ -4927,10 +4926,6 @@ def images_to_upload(self): [extension in path for extension in self.exclude_file_patterns] ) ] - excluded_paths = [path for path in paths if path not in filtered_paths] - if excluded_paths: - logger.info(f"Excluded paths {', '.join(excluded_paths)}") - image_entities = ( GetBulkImages( service=self._backend_client, @@ -4994,8 +4989,6 @@ def execute(self): duplications.extend(attach_duplications) uploaded = [image["name"] for image in uploaded] failed_images = [image.split("/")[-1] for image in failed_images] - if duplications: - logger.info(f"Duplicated images {', '.join(duplications)}") self._response.data = uploaded, failed_images, duplications return self._response diff --git a/src/superannotate/lib/infrastructure/services.py b/src/superannotate/lib/infrastructure/services.py index b503f6b69..d83744899 100644 --- a/src/superannotate/lib/infrastructure/services.py +++ b/src/superannotate/lib/infrastructure/services.py @@ -39,6 +39,7 @@ def __init__( self._paginate_by = paginate_by self._verify_ssl = verify_ssl self.team_id = auth_token.split("=")[-1] + self.get_session() @timed_lru_cache(seconds=360) def get_session(self): diff --git a/tests/integration/test_interface.py b/tests/integration/test_interface.py index f2ed49b4a..eaa360dab 100644 --- a/tests/integration/test_interface.py +++ b/tests/integration/test_interface.py @@ -138,6 +138,18 @@ def test_overlay_fuse(self): ) self.assertIsNotNone(paths) + def test_upload_images_to_project_returned_data(self): + upload, not_uploaded, duplicated = sa.upload_images_to_project( + self.PROJECT_NAME, + [f"{self.folder_path}/{self.EXAMPLE_IMAGE_1}", f"{self.folder_path}/{self.EXAMPLE_IMAGE_2}"] + ) + self.assertEqual(2, len(upload)) + upload, not_uploaded, duplicated = sa.upload_images_to_project( + self.PROJECT_NAME, + [f"{self.folder_path}/{self.EXAMPLE_IMAGE_1}", f"{self.folder_path}/{self.EXAMPLE_IMAGE_2}"] + ) + self.assertEqual(2, len(duplicated)) + def test_upload_images_to_project_image_quality_in_editor(self): self.assertRaises( AppException, From fb3f55a101cd95d60d174173120a32b33f5b30ea Mon Sep 17 00:00:00 2001 From: shab Date: Sat, 25 Sep 2021 10:33:42 +0400 Subject: [PATCH 2/2] Fix exception message --- .../lib/app/interface/sdk_interface.py | 6 +++++- tests/integration/test_image_quality.py | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/superannotate/lib/app/interface/sdk_interface.py b/src/superannotate/lib/app/interface/sdk_interface.py index c2ef8ce22..3743a88a6 100644 --- a/src/superannotate/lib/app/interface/sdk_interface.py +++ b/src/superannotate/lib/app/interface/sdk_interface.py @@ -3412,7 +3412,9 @@ def upload_image_to_project( if not isinstance(img, io.BytesIO): if from_s3_bucket: - image_bytes = controller.get_image_from_s3(from_s3_bucket, image_name) + response = controller.get_image_from_s3(from_s3_bucket, img) + image_bytes = response.data + else: image_bytes = io.BytesIO(open(img, "rb").read()) else: @@ -3424,6 +3426,8 @@ def upload_image_to_project( folder_name=folder_name, image_quality_in_editor=image_quality_in_editor, ) + if upload_response.errors: + raise AppException(upload_response.errors) controller.upload_images( project_name=project_name, folder_name=folder_name, diff --git a/tests/integration/test_image_quality.py b/tests/integration/test_image_quality.py index 1317ea203..5d92b0d40 100644 --- a/tests/integration/test_image_quality.py +++ b/tests/integration/test_image_quality.py @@ -5,6 +5,7 @@ import src.superannotate as sa from tests.integration.base import BaseTestCase +from src.superannotate import AppException class TestImageQuality(BaseTestCase): @@ -59,3 +60,23 @@ def test_image_quality_setting2(self): shallow=False, ) ) + + + +class TestImageQuality(BaseTestCase): + PROJECT_NAME = "pixel image q" + PROJECT_DESCRIPTION = "Desc" + PROJECT_TYPE = "Pixel" + TEST_FOLDER_PATH = "data_set/big_img" + BIG_IMAGE = "big.jpg" + MESSAGE = "Image resolution 44761088 too large. Max supported for resolution is 4000000" + + @property + def folder_path(self): + return os.path.join(dirname(dirname(__file__)), self.TEST_FOLDER_PATH) + + def test_big_image(self): + try: + sa.upload_image_to_project(self.PROJECT_NAME,f"{self.folder_path}/{self.BIG_IMAGE}") + except AppException as e: + self.assertEqual(str(e),self.MESSAGE)