@@ -89,6 +89,11 @@ class InvalidArtifactType(Exception): # pragma: no cover
89
89
pass
90
90
91
91
92
+ class InvalidArtifactPathTypeOrContentError (Exception ): # pragma: no cover
93
+ def __init__ (self , msg = "Invalid type of Metdata artifact content" ):
94
+ super ().__init__ (msg )
95
+
96
+
92
97
class CustomerNotificationType (ExtendedEnum ):
93
98
NONE = "NONE"
94
99
ALL = "ALL"
@@ -2238,7 +2243,7 @@ def find_model_idx():
2238
2243
def create_custom_metadata_artifact (
2239
2244
self ,
2240
2245
metadata_key_name : str ,
2241
- artifact_path_or_content : str ,
2246
+ artifact_path_or_content : Union [ str , bytes ] ,
2242
2247
path_type : MetadataArtifactPathType = MetadataArtifactPathType .LOCAL ,
2243
2248
) -> ModelMetadataArtifactDetails :
2244
2249
"""Creates model custom metadata artifact for specified model.
@@ -2248,8 +2253,10 @@ def create_custom_metadata_artifact(
2248
2253
metadata_key_name: str
2249
2254
The name of the model custom metadata key
2250
2255
2251
- artifact_path_or_content: str
2252
- The model custom metadata artifact path to be upload. It can also be the actual content of the custom metadata
2256
+ artifact_path_or_content: Union[str,bytes]
2257
+ The model custom metadata artifact path to be upload. It can also be the actual content of the defined metadata
2258
+ The type is string when it represents local path or oss path.
2259
+ The type is bytes when it represents content itself
2253
2260
2254
2261
path_type: MetadataArtifactPathType
2255
2262
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
@@ -2273,16 +2280,23 @@ def create_custom_metadata_artifact(
2273
2280
}
2274
2281
2275
2282
"""
2283
+ if path_type == MetadataArtifactPathType .CONTENT and not isinstance (
2284
+ artifact_path_or_content , bytes
2285
+ ):
2286
+ raise InvalidArtifactPathTypeOrContentError (
2287
+ f"Invalid type of artifact content: { type (artifact_path_or_content )} . It should be bytes."
2288
+ )
2289
+
2276
2290
return self .dsc_model .create_custom_metadata_artifact (
2277
2291
metadata_key_name = metadata_key_name ,
2278
- artifact_path = artifact_path_or_content ,
2292
+ artifact_path_or_content = artifact_path_or_content ,
2279
2293
path_type = path_type ,
2280
2294
)
2281
2295
2282
2296
def create_defined_metadata_artifact (
2283
2297
self ,
2284
2298
metadata_key_name : str ,
2285
- artifact_path_or_content : str ,
2299
+ artifact_path_or_content : Union [ str , bytes ] ,
2286
2300
path_type : MetadataArtifactPathType = MetadataArtifactPathType .LOCAL ,
2287
2301
) -> ModelMetadataArtifactDetails :
2288
2302
"""Creates model defined metadata artifact for specified model.
@@ -2292,8 +2306,10 @@ def create_defined_metadata_artifact(
2292
2306
metadata_key_name: str
2293
2307
The name of the model defined metadata key
2294
2308
2295
- artifact_path_or_content: str
2309
+ artifact_path_or_content: Union[ str,bytes]
2296
2310
The model defined metadata artifact path to be upload. It can also be the actual content of the defined metadata
2311
+ The type is string when it represents local path or oss path.
2312
+ The type is bytes when it represents content itself
2297
2313
2298
2314
path_type: MetadataArtifactPathType
2299
2315
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
@@ -2317,16 +2333,23 @@ def create_defined_metadata_artifact(
2317
2333
}
2318
2334
2319
2335
"""
2336
+ if path_type == MetadataArtifactPathType .CONTENT and not isinstance (
2337
+ artifact_path_or_content , bytes
2338
+ ):
2339
+ raise InvalidArtifactPathTypeOrContentError (
2340
+ f"Invalid type of artifact content: { type (artifact_path_or_content )} . It should be bytes."
2341
+ )
2342
+
2320
2343
return self .dsc_model .create_defined_metadata_artifact (
2321
2344
metadata_key_name = metadata_key_name ,
2322
- artifact_path = artifact_path_or_content ,
2345
+ artifact_path_or_content = artifact_path_or_content ,
2323
2346
path_type = path_type ,
2324
2347
)
2325
2348
2326
2349
def update_custom_metadata_artifact (
2327
2350
self ,
2328
2351
metadata_key_name : str ,
2329
- artifact_path_or_content : str ,
2352
+ artifact_path_or_content : Union [ str , bytes ] ,
2330
2353
path_type : MetadataArtifactPathType = MetadataArtifactPathType .LOCAL ,
2331
2354
) -> ModelMetadataArtifactDetails :
2332
2355
"""Update model custom metadata artifact for specified model.
@@ -2336,8 +2359,10 @@ def update_custom_metadata_artifact(
2336
2359
metadata_key_name: str
2337
2360
The name of the model custom metadata key
2338
2361
2339
- artifact_path_or_content: str
2340
- The model custom metadata artifact path. It can also be the actual content of the custom metadata
2362
+ artifact_path_or_content: Union[str,bytes]
2363
+ The model custom metadata artifact path to be upload. It can also be the actual content of the defined metadata
2364
+ The type is string when it represents local path or oss path.
2365
+ The type is bytes when it represents content itself
2341
2366
2342
2367
path_type: MetadataArtifactPathType
2343
2368
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
@@ -2361,16 +2386,23 @@ def update_custom_metadata_artifact(
2361
2386
}
2362
2387
2363
2388
"""
2389
+ if path_type == MetadataArtifactPathType .CONTENT and not isinstance (
2390
+ artifact_path_or_content , bytes
2391
+ ):
2392
+ raise InvalidArtifactPathTypeOrContentError (
2393
+ f"Invalid type of artifact content: { type (artifact_path_or_content )} . It should be bytes."
2394
+ )
2395
+
2364
2396
return self .dsc_model .update_custom_metadata_artifact (
2365
2397
metadata_key_name = metadata_key_name ,
2366
- artifact_path = artifact_path_or_content ,
2398
+ artifact_path_or_content = artifact_path_or_content ,
2367
2399
path_type = path_type ,
2368
2400
)
2369
2401
2370
2402
def update_defined_metadata_artifact (
2371
2403
self ,
2372
2404
metadata_key_name : str ,
2373
- artifact_path_or_content : str ,
2405
+ artifact_path_or_content : Union [ str , bytes ] ,
2374
2406
path_type : MetadataArtifactPathType = MetadataArtifactPathType .LOCAL ,
2375
2407
) -> ModelMetadataArtifactDetails :
2376
2408
"""Update model defined metadata artifact for specified model.
@@ -2380,8 +2412,10 @@ def update_defined_metadata_artifact(
2380
2412
metadata_key_name: str
2381
2413
The name of the model defined metadata key
2382
2414
2383
- artifact_path_or_content: str
2384
- The model defined metadata artifact path. It can also be the actual content of the defined metadata
2415
+ artifact_path_or_content: Union[str,bytes]
2416
+ The model defined metadata artifact path to be upload. It can also be the actual content of the defined metadata
2417
+ The type is string when it represents local path or oss path.
2418
+ The type is bytes when it represents content itself
2385
2419
2386
2420
path_type: MetadataArtifactPathType
2387
2421
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
@@ -2405,9 +2439,16 @@ def update_defined_metadata_artifact(
2405
2439
}
2406
2440
2407
2441
"""
2442
+ if path_type == MetadataArtifactPathType .CONTENT and not isinstance (
2443
+ artifact_path_or_content , bytes
2444
+ ):
2445
+ raise InvalidArtifactPathTypeOrContentError (
2446
+ f"Invalid type of artifact content: { type (artifact_path_or_content )} . It should be bytes."
2447
+ )
2448
+
2408
2449
return self .dsc_model .update_defined_metadata_artifact (
2409
2450
metadata_key_name = metadata_key_name ,
2410
- artifact_path = artifact_path_or_content ,
2451
+ artifact_path_or_content = artifact_path_or_content ,
2411
2452
path_type = path_type ,
2412
2453
)
2413
2454
@@ -2442,7 +2483,7 @@ def get_custom_metadata_artifact(
2442
2483
)
2443
2484
artifact_file_path = os .path .join (target_dir , f"{ metadata_key_name } " )
2444
2485
2445
- if not override and os . path . exists (artifact_file_path ):
2486
+ if not override and is_path_exists (artifact_file_path ):
2446
2487
raise FileExistsError (f"File already exists: { artifact_file_path } " )
2447
2488
2448
2489
with open (artifact_file_path , "wb" ) as _file :
@@ -2481,7 +2522,7 @@ def get_defined_metadata_artifact(
2481
2522
)
2482
2523
artifact_file_path = os .path .join (target_dir , f"{ metadata_key_name } " )
2483
2524
2484
- if not override and os . path . exists (artifact_file_path ):
2525
+ if not override and is_path_exists (artifact_file_path ):
2485
2526
raise FileExistsError (f"File already exists: { artifact_file_path } " )
2486
2527
2487
2528
with open (artifact_file_path , "wb" ) as _file :
0 commit comments