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
@@ -252,8 +253,6 @@ def execute(self):
252253 [annotation .path for annotation in self ._missing_annotations ],
253254 )
254255 self ._log_report ()
255- else :
256- self ._response .errors = "Could not find annotations matching existing items on the platform."
257256 return self ._response
258257
259258
@@ -338,13 +337,26 @@ def from_s3(self):
338337 def set_annotation_json (self ):
339338 if not self ._annotation_json :
340339 if self ._client_s3_bucket :
341- self ._annotation_json = json .load (self .get_s3_file (self .from_s3 , self ._annotation_path ))
340+ self ._annotation_json = json .load (
341+ self .get_s3_file (self .from_s3 , self ._annotation_path )
342+ )
342343 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 ))
344+ self ._mask = self .get_s3_file (
345+ self .from_s3 ,
346+ self ._annotation_path .replace (
347+ constances .PIXEL_ANNOTATION_POSTFIX ,
348+ constances .ANNOTATION_MASK_POSTFIX ,
349+ ),
350+ )
344351 else :
345352 self ._annotation_json = json .load (open (self ._annotation_path ))
346353 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 ))
354+ self ._mask = open (
355+ self ._annotation_path .replace (
356+ constances .PIXEL_ANNOTATION_POSTFIX ,
357+ constances .ANNOTATION_MASK_POSTFIX ,
358+ )
359+ )
348360
349361 def _is_valid_json (self , json_data : dict ):
350362 use_case = ValidateAnnotationUseCase (
@@ -368,7 +380,7 @@ def prepare_annotations(
368380 if project_type in (
369381 constances .ProjectType .VECTOR .value ,
370382 constances .ProjectType .PIXEL .value ,
371- constances .ProjectType .DOCUMENT .value
383+ constances .ProjectType .DOCUMENT .value ,
372384 ):
373385 fill_annotation_ids (
374386 annotations = annotations ,
@@ -415,7 +427,10 @@ def execute(self):
415427 ],
416428 Body = json .dumps (annotation_json ),
417429 )
418- if self ._project .project_type == constances .ProjectType .PIXEL .value and self ._mask :
430+ if (
431+ self ._project .project_type == constances .ProjectType .PIXEL .value
432+ and self ._mask
433+ ):
419434 bucket .put_object (
420435 Key = self .annotation_upload_data .images [self ._image .uuid ][
421436 "annotation_bluemap_path"
0 commit comments