Skip to content

Commit 77666aa

Browse files
committed
prep for release
1 parent c5deb29 commit 77666aa

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/sasctl/tasks.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,9 @@ def _register_sas_model(
265265
out_var = []
266266
in_var = []
267267
import copy
268-
import zipfile as zp
269268

270269
zip_file_copy = copy.deepcopy(zip_file)
271-
tmp_zip = zp.ZipFile(zip_file_copy)
270+
tmp_zip = zipfile.ZipFile(zip_file_copy)
272271
if "outputVar.json" in tmp_zip.namelist():
273272
out_var = json.loads(
274273
tmp_zip.read("outputVar.json").decode("utf=8")
@@ -328,8 +327,8 @@ def _register_sas_model(
328327

329328
if current_session().version_info() < 4:
330329
# Upload the model as a ZIP file if using Viya 3.
331-
zipfile = utils.create_package(model, input=input)
332-
model = mr.import_model_from_zip(name, project, zipfile, version=version)
330+
zip_file = utils.create_package(model, input=input)
331+
model = mr.import_model_from_zip(name, project, zip_file, version=version)
333332
else:
334333
# If using Viya 4, just upload the raw AStore and Model Manager will handle inspection.
335334
astore = cas.astore.download(rstore=model)
@@ -1008,7 +1007,7 @@ def upload_local_model(
10081007
repo_name: Union[str, dict] = None,
10091008
version: str = "latest",
10101009
):
1011-
"""A barebones function to upload a model and any associated files to the model repository.
1010+
"""A function to upload a model and any associated files to the model repository.
10121011
Parameters
10131012
----------
10141013
path : Union[str, Path]
@@ -1017,6 +1016,10 @@ def upload_local_model(
10171016
The name of the model.
10181017
project_name : str
10191018
The name of the project to which the model will be uploaded.
1019+
repo_name : Union[str, dict], optional
1020+
repository in which to create the project
1021+
version: str, optional
1022+
The version of the model being uploaded
10201023
"""
10211024
# Use default repository if not specified
10221025
try:
@@ -1036,16 +1039,21 @@ def upload_local_model(
10361039
# Unable to find or create the repo.
10371040
if not repository and not repo_name:
10381041
raise ValueError("Unable to find a default repository")
1039-
elif not repository:
1042+
if not repository:
10401043
raise ValueError(f"Unable to find repository '{repo_name}'")
1044+
1045+
# Get project from repo if it exists; if it doesn't, create a new one
10411046
p = mr.get_project(project_name)
10421047
if p is None:
10431048
mr.create_project(project_name, repository)
1049+
1050+
# zip up all files in directory (except any previous zip files)
10441051
zip_name = str(Path(path) / (model_name + ".zip"))
10451052
file_names = sorted(Path(path).glob("*[!zip]"))
10461053
with zipfile.ZipFile(str(zip_name), mode="w") as zFile:
10471054
for file in file_names:
10481055
zFile.write(str(file), arcname=file.name)
1056+
# upload zipped model
10491057
with open(zip_name, "rb") as zip_file:
10501058
model = mr.import_model_from_zip(
10511059
model_name, project_name, zip_file, version=version

0 commit comments

Comments
 (0)