Skip to content

Commit 4418bf8

Browse files
committedJun 14, 2024·
namespace, bucket, prefix way added again.
1 parent b7e7d74 commit 4418bf8

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed
 

‎ads/model/datascience_model.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,9 @@ def _download_file_description_artifact(self) -> Tuple[Union[str, List[str]], in
14701470

14711471
def add_artifact(
14721472
self,
1473-
uri: str,
1473+
namespace: str,
1474+
bucket: str,
1475+
prefix: Optional[str] = None,
14741476
files: Optional[List[str]] = None,
14751477
):
14761478
"""
@@ -1496,11 +1498,11 @@ def add_artifact(
14961498
If `files` is provided, it only retrieves information about objects with matching file names.
14971499
- If no objects are found to add to the model description, a ValueError is raised.
14981500
"""
1499-
object_storage_details = ObjectStorageDetails.from_path(uri)
1500-
bucket = object_storage_details.bucket
1501-
namespace = object_storage_details.namespace
1502-
prefix = None if object_storage_details.filepath == "" else object_storage_details.filepath
15031501

1502+
# Check if both prefix and files are provided
1503+
if prefix is not None and files is not None:
1504+
raise ValueError("Both 'prefix' and 'files' cannot be provided. Please provide only one.")
1505+
15041506
if self.model_file_description == None:
15051507
self.empty_json = {
15061508
"version": "1.0",
@@ -1513,7 +1515,7 @@ def add_artifact(
15131515
self.object_storage_client = oc.OCIClientFactory(**(self.dsc_model.auth)).object_storage
15141516

15151517
# Remove if the model already exists
1516-
self.remove_artifact(uri=uri)
1518+
self.remove_artifact(namespace=namespace, bucket=bucket, prefix=prefix)
15171519

15181520
def check_if_file_exists(fileName):
15191521
isExists = False
@@ -1588,7 +1590,7 @@ def list_obj_versions_unpaginated():
15881590
)
15891591
self.set_spec(self.CONST_MODEL_FILE_DESCRIPTION, tmp_model_file_description)
15901592

1591-
def remove_artifact(self, uri: str):
1593+
def remove_artifact(self, namespace: str, bucket: str, prefix: Optional[str] = None):
15921594
"""
15931595
Removes information about objects in a specified bucket from the model description JSON.
15941596
@@ -1604,10 +1606,6 @@ def remove_artifact(self, uri: str):
16041606
------
16051607
ValueError: If the model description JSON is None.
16061608
"""
1607-
object_storage_details = ObjectStorageDetails.from_path(uri)
1608-
bucket = object_storage_details.bucket
1609-
namespace = object_storage_details.namespace
1610-
prefix = None if object_storage_details.filepath == "" else object_storage_details.filepath
16111609

16121610
def findModelIdx():
16131611
for idx, model in enumerate(self.model_file_description["models"]):

‎tests/unitary/default_setup/model/test_datascience_model.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,8 @@ def test_add_artifact(self, mock_oci_client_factory):
11551155
mock_oci_client_factory.return_value.object_storage = mock_object_storage_client
11561156

11571157
# self.mock_dsc_model
1158-
self.mock_dsc_model.add_artifact(uri="oci://bucket@namespace/prefix")
1158+
# self.mock_dsc_model.add_artifact(uri="oci://bucket@namespace/prefix")
1159+
self.mock_dsc_model.add_artifact(namespace="namespace", bucket="bucket", prefix="prefix")
11591160
expected_out = {
11601161
'version': '1.0',
11611162
'type': 'modelOSSReferenceDescription',
@@ -1175,7 +1176,8 @@ def test_add_artifact(self, mock_oci_client_factory):
11751176
]
11761177
}
11771178
assert self.mock_dsc_model.model_file_description == expected_out
1178-
self.mock_dsc_model.remove_artifact(uri="oci://bucket@namespace/prefix")
1179+
# self.mock_dsc_model.remove_artifact(uri="oci://bucket@namespace/prefix")
1180+
self.mock_dsc_model.remove_artifact(namespace="namespace", bucket="bucket", prefix="prefix")
11791181
assert self.mock_dsc_model.model_file_description != expected_out
11801182
expected_out = {
11811183
'version': '1.0',
@@ -1185,13 +1187,16 @@ def test_add_artifact(self, mock_oci_client_factory):
11851187
assert self.mock_dsc_model.model_file_description == expected_out
11861188

11871189
def test_remove_artifact(self):
1188-
self.mock_dsc_model.remove_artifact(uri="oci://unzip-multi-model@ociodscdev/model-linear-1")
1190+
# self.mock_dsc_model.remove_artifact(uri="oci://unzip-multi-model@ociodscdev/model-linear-1")
1191+
self.mock_dsc_model.remove_artifact(namespace="ociodscdev", bucket="unzip-multi-model", prefix="model-linear-1")
1192+
11891193
assert self.mock_dsc_model.model_file_description == None
11901194

11911195
self.mock_dsc_model.set_spec(CONST_MODEL_FILE_DESCRIPTION, deepcopy(MODEL_BY_REF_JSON))
11921196
assert self.mock_dsc_model.model_file_description == MODEL_BY_REF_JSON
11931197

1194-
self.mock_dsc_model.remove_artifact(uri="oci://unzip-multi-model@ociodscdev/model-linear-1")
1198+
# self.mock_dsc_model.remove_artifact(uri="oci://unzip-multi-model@ociodscdev/model-linear-1")
1199+
self.mock_dsc_model.remove_artifact(namespace="ociodscdev", bucket="unzip-multi-model", prefix="model-linear-1")
11951200
assert self.mock_dsc_model.model_file_description != MODEL_BY_REF_JSON
11961201

11971202
exptected_json = deepcopy(MODEL_BY_REF_JSON)

0 commit comments

Comments
 (0)
Please sign in to comment.