1212from lib .core .entities import FolderEntity
1313from lib .core .entities import ImageEntity
1414from lib .core .entities import ProjectEntity
15- from lib .core .exceptions import AppException
1615from lib .core .helpers import convert_to_video_editor_json
1716from lib .core .helpers import fill_annotation_ids
1817from lib .core .helpers import fill_document_tags
@@ -111,6 +110,7 @@ def annotations_to_upload(self):
111110 for idx , detail in enumerate (images_detail ):
112111 if detail .name == image_data .name :
113112 images_detail [idx ] = detail ._replace (id = image_data .uuid )
113+ break
114114
115115 missing_annotations = list (
116116 filter (lambda image_detail : image_detail .id is None , images_detail )
@@ -119,13 +119,8 @@ def annotations_to_upload(self):
119119 filter (lambda image_detail : image_detail .id is not None , images_detail )
120120 )
121121 if missing_annotations :
122- for missing in missing_annotations :
123- logger .warning (
124- f"Couldn't find image { missing .path } for annotation upload."
125- )
126- if not annotations_to_upload :
127- raise AppException (
128- "No item to attach annotations."
122+ logger .warning (
123+ f"Couldn't find { len (missing_annotations )} /{ len (annotations_to_upload + missing_annotations )} items on the platform that match the annotations you want to upload."
129124 )
130125 self ._missing_annotations = missing_annotations
131126 self ._annotations_to_upload = annotations_to_upload
@@ -199,9 +194,7 @@ def _log_report(self):
199194 template = "Could not find attribute groups matching existing attribute groups on the platform: [{}]"
200195 elif key == "missing_attributes" :
201196 template = "Could not find attributes matching existing attributes on the platform: [{}]"
202- logger .warning (
203- template .format ("', '" .join (values ))
204- )
197+ logger .warning (template .format ("', '" .join (values )))
205198
206199 def execute (self ):
207200 uploaded_annotations = []
@@ -210,19 +203,27 @@ def execute(self):
210203 iterations_range = range (
211204 0 , len (self .annotations_to_upload ), self .AUTH_DATA_CHUNK_SIZE
212205 )
213- self .reporter .start_progress (len (self .annotations_to_upload ), description = "Uploading Annotations" )
206+ self .reporter .start_progress (
207+ len (self .annotations_to_upload ), description = "Uploading Annotations"
208+ )
214209 for step in iterations_range :
215- annotations_to_upload = self .annotations_to_upload [step : step + self .AUTH_DATA_CHUNK_SIZE ] # noqa: E203
210+ annotations_to_upload = self .annotations_to_upload [
211+ step : step + self .AUTH_DATA_CHUNK_SIZE
212+ ] # noqa: E203
216213 upload_data = self .get_annotation_upload_data (
217214 [int (image .id ) for image in annotations_to_upload ]
218215 )
219- bucket = self .get_bucket_to_upload ([int (image .id ) for image in annotations_to_upload ])
216+ bucket = self .get_bucket_to_upload (
217+ [int (image .id ) for image in annotations_to_upload ]
218+ )
220219 if bucket :
221220 image_id_name_map = {
222221 image .id : image for image in self .annotations_to_upload
223222 }
224223 # dummy progress
225- for _ in range (len (annotations_to_upload ) - len (upload_data .images )):
224+ for _ in range (
225+ len (annotations_to_upload ) - len (upload_data .images )
226+ ):
226227 self .reporter .update_progress ()
227228 with concurrent .futures .ThreadPoolExecutor (
228229 max_workers = self .MAX_WORKERS
@@ -253,7 +254,9 @@ def execute(self):
253254 )
254255 self ._log_report ()
255256 else :
256- self ._response .errors = "Could not find annotations matching existing items on the platform."
257+ self ._response .errors = (
258+ "Could not find annotations matching existing items on the platform."
259+ )
257260 return self ._response
258261
259262
@@ -338,13 +341,26 @@ def from_s3(self):
338341 def set_annotation_json (self ):
339342 if not self ._annotation_json :
340343 if self ._client_s3_bucket :
341- self ._annotation_json = json .load (self .get_s3_file (self .from_s3 , self ._annotation_path ))
344+ self ._annotation_json = json .load (
345+ self .get_s3_file (self .from_s3 , self ._annotation_path )
346+ )
342347 if self ._project .project_type == constances .ProjectType .PIXEL .value :
343- self ._mask = self .get_s3_file (self .from_s3 , self ._annotation_path .replace (constances .PIXEL_ANNOTATION_POSTFIX , constances .ANNOTATION_MASK_POSTFIX ))
348+ self ._mask = self .get_s3_file (
349+ self .from_s3 ,
350+ self ._annotation_path .replace (
351+ constances .PIXEL_ANNOTATION_POSTFIX ,
352+ constances .ANNOTATION_MASK_POSTFIX ,
353+ ),
354+ )
344355 else :
345356 self ._annotation_json = json .load (open (self ._annotation_path ))
346357 if self ._project .project_type == constances .ProjectType .PIXEL .value :
347- self ._mask = open (self ._annotation_path .replace (constances .PIXEL_ANNOTATION_POSTFIX , constances .ANNOTATION_MASK_POSTFIX ))
358+ self ._mask = open (
359+ self ._annotation_path .replace (
360+ constances .PIXEL_ANNOTATION_POSTFIX ,
361+ constances .ANNOTATION_MASK_POSTFIX ,
362+ )
363+ )
348364
349365 def _is_valid_json (self , json_data : dict ):
350366 use_case = ValidateAnnotationUseCase (
@@ -368,7 +384,7 @@ def prepare_annotations(
368384 if project_type in (
369385 constances .ProjectType .VECTOR .value ,
370386 constances .ProjectType .PIXEL .value ,
371- constances .ProjectType .DOCUMENT .value
387+ constances .ProjectType .DOCUMENT .value ,
372388 ):
373389 fill_annotation_ids (
374390 annotations = annotations ,
@@ -415,7 +431,10 @@ def execute(self):
415431 ],
416432 Body = json .dumps (annotation_json ),
417433 )
418- if self ._project .project_type == constances .ProjectType .PIXEL .value and self ._mask :
434+ if (
435+ self ._project .project_type == constances .ProjectType .PIXEL .value
436+ and self ._mask
437+ ):
419438 bucket .put_object (
420439 Key = self .annotation_upload_data .images [self ._image .uuid ][
421440 "annotation_bluemap_path"
0 commit comments