Skip to content

Commit e414716

Browse files
Adding path directory validation
1 parent 2eb12a3 commit e414716

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

ads/model/datascience_model.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from ads.common import utils
2020
from ads.common.extended_enum import ExtendedEnum
2121
from ads.common.object_storage_details import ObjectStorageDetails
22+
from ads.common.utils import is_path_exists
2223
from ads.config import (
2324
AQUA_SERVICE_MODELS_BUCKET as SERVICE_MODELS_BUCKET,
2425
)
@@ -74,6 +75,11 @@ def __init__(
7475
super().__init__(msg)
7576

7677

78+
class PathNotFoundError(Exception):
79+
def __init__(self, msg="The given path doesn't exist."):
80+
super().__init__(msg)
81+
82+
7783
class ModelFileDescriptionError(Exception): # pragma: no cover
7884
def __init__(self, msg="Model File Description file is not set up."):
7985
super().__init__(msg)
@@ -2407,7 +2413,7 @@ def update_defined_metadata_artifact(
24072413

24082414
def get_custom_metadata_artifact(
24092415
self, metadata_key_name: str, target_dir: str, override: bool = False
2410-
) -> None:
2416+
) -> bytes:
24112417
"""Downloads model custom metadata artifact content for specified model metadata key.
24122418
24132419
Parameters
@@ -2424,9 +2430,13 @@ def get_custom_metadata_artifact(
24242430
- If False (default), raises a `FileExistsError` if the file exists.
24252431
Returns
24262432
-------
2427-
None
2433+
bytes
2434+
File content of the custom metadata artifact
24282435
24292436
"""
2437+
if not is_path_exists(target_dir):
2438+
raise PathNotFoundError(f"Path : {target_dir} does not exist")
2439+
24302440
file_content = self.dsc_model.get_custom_metadata_artifact(
24312441
metadata_key_name=metadata_key_name
24322442
)
@@ -2438,10 +2448,11 @@ def get_custom_metadata_artifact(
24382448
with open(artifact_file_path, "wb") as _file:
24392449
_file.write(file_content)
24402450
logger.debug(f"Artifact downloaded to location - {artifact_file_path}")
2451+
return file_content
24412452

24422453
def get_defined_metadata_artifact(
24432454
self, metadata_key_name: str, target_dir: str, override: bool = False
2444-
) -> None:
2455+
) -> bytes:
24452456
"""Downloads model defined metadata artifact content for specified model metadata key.
24462457
24472458
Parameters
@@ -2458,9 +2469,13 @@ def get_defined_metadata_artifact(
24582469
- If False (default), raises a `FileExistsError` if the file exists.
24592470
Returns
24602471
-------
2461-
None
2472+
bytes
2473+
File content of the custom metadata artifact
24622474
24632475
"""
2476+
if not is_path_exists(target_dir):
2477+
raise PathNotFoundError(f"Path : {target_dir} does not exist")
2478+
24642479
file_content = self.dsc_model.get_defined_metadata_artifact(
24652480
metadata_key_name=metadata_key_name
24662481
)
@@ -2472,6 +2487,7 @@ def get_defined_metadata_artifact(
24722487
with open(artifact_file_path, "wb") as _file:
24732488
_file.write(file_content)
24742489
logger.debug(f"Artifact downloaded to location - {artifact_file_path}")
2490+
return file_content
24752491

24762492
def delete_custom_metadata_artifact(
24772493
self, metadata_key_name: str

0 commit comments

Comments
 (0)