11
11
import requests
12
12
from pydantic import BaseModel , validator
13
13
from typing_extensions import Literal
14
- from typing import (Any , List , Optional , BinaryIO , Dict , Iterable , Tuple , Union ,
15
- Type , Set )
14
+ from typing import (Any , List , Optional , BinaryIO , Dict , Iterable , Tuple ,
15
+ Union , Type , Set )
16
16
17
17
import labelbox
18
18
from labelbox import utils
@@ -79,13 +79,14 @@ def _send_create_file_command(
79
79
response_data = response_json .get ("data" , None )
80
80
if response_data is None :
81
81
raise labelbox .exceptions .LabelboxError (
82
- "Failed to upload, message: %s" % response_json .get ("errors" , None ))
82
+ "Failed to upload, message: %s" %
83
+ response_json .get ("errors" , None ))
83
84
84
85
if not response_data .get ("createBulkImportRequest" , None ):
85
86
raise labelbox .exceptions .LabelboxError (
86
87
"Failed to create BulkImportRequest, message: %s" %
87
- response_json .get ("errors" , None ) or
88
- response_data .get ("error" , None ))
88
+ response_json .get ("errors" , None )
89
+ or response_data .get ("error" , None ))
89
90
90
91
return response_data
91
92
@@ -386,6 +387,22 @@ def create_from_local_file(cls,
386
387
file_name , file_data )
387
388
return cls (client , response_data ["createBulkImportRequest" ])
388
389
390
+ def delete (self ) -> None :
391
+ """ Deletes the BulkImportRequest object
392
+
393
+ Returns:
394
+ None
395
+ """
396
+ id_param = "bulk_request_id"
397
+ query_str = """
398
+ mutation DeleteBulkImportRequestPyApi($%s: ID!) {
399
+ deleteBulkImportRequest (where: {id: $%s}) {
400
+ id
401
+ name
402
+ }
403
+ }""" % (id_param , id_param )
404
+ self .client .execute (query_str , {id_param : self .uid })
405
+
389
406
390
407
def _validate_ndjson (lines : Iterable [Dict [str , Any ]],
391
408
project : "labelbox.Project" ) -> None :
@@ -418,7 +435,8 @@ def _validate_ndjson(lines: Iterable[Dict[str, Any]],
418
435
f'{ uuid } already used in this import job, '
419
436
'must be unique for the project.' )
420
437
uids .add (uuid )
421
- except (pydantic .ValidationError , ValueError , TypeError , KeyError ) as e :
438
+ except (pydantic .ValidationError , ValueError , TypeError ,
439
+ KeyError ) as e :
422
440
raise labelbox .exceptions .MALValidationError (
423
441
f"Invalid NDJson on line { idx } " ) from e
424
442
@@ -502,7 +520,6 @@ class VideoSupported(BaseModel):
502
520
#Base class for a special kind of union.
503
521
# Compatible with pydantic. Improves error messages over a traditional union
504
522
class SpecialUnion :
505
-
506
523
def __new__ (cls , ** kwargs ):
507
524
return cls .build (kwargs )
508
525
@@ -640,10 +657,11 @@ def validate_answers(cls, value, field):
640
657
641
658
def validate_feature_schemas (self , valid_feature_schemas ):
642
659
#Test top level feature schema for this tool
643
- super (NDChecklist , self ).validate_feature_schemas (valid_feature_schemas )
660
+ super (NDChecklist ,
661
+ self ).validate_feature_schemas (valid_feature_schemas )
644
662
#Test the feature schemas provided to the answer field
645
- if len (set ([answer .schemaId for answer in self . answers ])) != len (
646
- self .answers ):
663
+ if len (set ([answer .schemaId
664
+ for answer in self . answers ])) != len ( self .answers ):
647
665
raise ValueError (
648
666
f"Duplicated featureSchema found for checklist { self .uuid } " )
649
667
for answer in self .answers :
@@ -712,7 +730,8 @@ class NDPolygon(NDBaseTool):
712
730
def is_geom_valid (cls , v ):
713
731
if len (v ) < 3 :
714
732
raise ValueError (
715
- f"A polygon must have at least 3 points to be valid. Found { v } " )
733
+ f"A polygon must have at least 3 points to be valid. Found { v } "
734
+ )
716
735
return v
717
736
718
737
@@ -784,7 +803,8 @@ def is_valid_mask(cls, v):
784
803
#Does the dtype matter? Can it be a float?
785
804
if not isinstance (colors , (tuple , list )):
786
805
raise ValueError (
787
- f"Received color that is not a list or tuple. Found : { colors } " )
806
+ f"Received color that is not a list or tuple. Found : { colors } "
807
+ )
788
808
elif len (colors ) != 3 :
789
809
raise ValueError (
790
810
f"Must provide RGB values for segmentation colors. Found : { colors } "
@@ -800,15 +820,14 @@ class NDTool(
800
820
SpecialUnion ,
801
821
Type [Union [NDMask , # type: ignore
802
822
NDTextEntity , NDPoint , NDRectangle , NDPolyline ,
803
- NDPolygon ,]]):
823
+ NDPolygon , ]]):
804
824
...
805
825
806
826
807
827
class NDAnnotation (
808
828
SpecialUnion ,
809
829
Type [Union [NDTool , # type: ignore
810
830
NDClassification ]]):
811
-
812
831
@classmethod
813
832
def build (cls : Any , data ) -> "NDBase" :
814
833
if not isinstance (data , dict ):
0 commit comments