1111import requests
1212from pydantic import BaseModel , validator
1313from 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 )
1616
1717import labelbox
1818from labelbox import utils
@@ -79,13 +79,14 @@ def _send_create_file_command(
7979 response_data = response_json .get ("data" , None )
8080 if response_data is None :
8181 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 ))
8384
8485 if not response_data .get ("createBulkImportRequest" , None ):
8586 raise labelbox .exceptions .LabelboxError (
8687 "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 ))
8990
9091 return response_data
9192
@@ -386,6 +387,22 @@ def create_from_local_file(cls,
386387 file_name , file_data )
387388 return cls (client , response_data ["createBulkImportRequest" ])
388389
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+
389406
390407def _validate_ndjson (lines : Iterable [Dict [str , Any ]],
391408 project : "labelbox.Project" ) -> None :
@@ -418,7 +435,8 @@ def _validate_ndjson(lines: Iterable[Dict[str, Any]],
418435 f'{ uuid } already used in this import job, '
419436 'must be unique for the project.' )
420437 uids .add (uuid )
421- except (pydantic .ValidationError , ValueError , TypeError , KeyError ) as e :
438+ except (pydantic .ValidationError , ValueError , TypeError ,
439+ KeyError ) as e :
422440 raise labelbox .exceptions .MALValidationError (
423441 f"Invalid NDJson on line { idx } " ) from e
424442
@@ -502,7 +520,6 @@ class VideoSupported(BaseModel):
502520#Base class for a special kind of union.
503521# Compatible with pydantic. Improves error messages over a traditional union
504522class SpecialUnion :
505-
506523 def __new__ (cls , ** kwargs ):
507524 return cls .build (kwargs )
508525
@@ -640,10 +657,11 @@ def validate_answers(cls, value, field):
640657
641658 def validate_feature_schemas (self , valid_feature_schemas ):
642659 #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 )
644662 #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 ):
647665 raise ValueError (
648666 f"Duplicated featureSchema found for checklist { self .uuid } " )
649667 for answer in self .answers :
@@ -712,7 +730,8 @@ class NDPolygon(NDBaseTool):
712730 def is_geom_valid (cls , v ):
713731 if len (v ) < 3 :
714732 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+ )
716735 return v
717736
718737
@@ -784,7 +803,8 @@ def is_valid_mask(cls, v):
784803 #Does the dtype matter? Can it be a float?
785804 if not isinstance (colors , (tuple , list )):
786805 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+ )
788808 elif len (colors ) != 3 :
789809 raise ValueError (
790810 f"Must provide RGB values for segmentation colors. Found : { colors } "
@@ -800,15 +820,14 @@ class NDTool(
800820 SpecialUnion ,
801821 Type [Union [NDMask , # type: ignore
802822 NDTextEntity , NDPoint , NDRectangle , NDPolyline ,
803- NDPolygon ,]]):
823+ NDPolygon , ]]):
804824 ...
805825
806826
807827class NDAnnotation (
808828 SpecialUnion ,
809829 Type [Union [NDTool , # type: ignore
810830 NDClassification ]]):
811-
812831 @classmethod
813832 def build (cls : Any , data ) -> "NDBase" :
814833 if not isinstance (data , dict ):
0 commit comments