@@ -265,10 +265,9 @@ def _register_sas_model(
265
265
out_var = []
266
266
in_var = []
267
267
import copy
268
- import zipfile as zp
269
268
270
269
zip_file_copy = copy .deepcopy (zip_file )
271
- tmp_zip = zp .ZipFile (zip_file_copy )
270
+ tmp_zip = zipfile .ZipFile (zip_file_copy )
272
271
if "outputVar.json" in tmp_zip .namelist ():
273
272
out_var = json .loads (
274
273
tmp_zip .read ("outputVar.json" ).decode ("utf=8" )
@@ -328,8 +327,8 @@ def _register_sas_model(
328
327
329
328
if current_session ().version_info () < 4 :
330
329
# 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 )
333
332
else :
334
333
# If using Viya 4, just upload the raw AStore and Model Manager will handle inspection.
335
334
astore = cas .astore .download (rstore = model )
@@ -1008,7 +1007,7 @@ def upload_local_model(
1008
1007
repo_name : Union [str , dict ] = None ,
1009
1008
version : str = "latest" ,
1010
1009
):
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.
1012
1011
Parameters
1013
1012
----------
1014
1013
path : Union[str, Path]
@@ -1017,6 +1016,10 @@ def upload_local_model(
1017
1016
The name of the model.
1018
1017
project_name : str
1019
1018
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
1020
1023
"""
1021
1024
# Use default repository if not specified
1022
1025
try :
@@ -1036,16 +1039,21 @@ def upload_local_model(
1036
1039
# Unable to find or create the repo.
1037
1040
if not repository and not repo_name :
1038
1041
raise ValueError ("Unable to find a default repository" )
1039
- elif not repository :
1042
+ if not repository :
1040
1043
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
1041
1046
p = mr .get_project (project_name )
1042
1047
if p is None :
1043
1048
mr .create_project (project_name , repository )
1049
+
1050
+ # zip up all files in directory (except any previous zip files)
1044
1051
zip_name = str (Path (path ) / (model_name + ".zip" ))
1045
1052
file_names = sorted (Path (path ).glob ("*[!zip]" ))
1046
1053
with zipfile .ZipFile (str (zip_name ), mode = "w" ) as zFile :
1047
1054
for file in file_names :
1048
1055
zFile .write (str (file ), arcname = file .name )
1056
+ # upload zipped model
1049
1057
with open (zip_name , "rb" ) as zip_file :
1050
1058
model = mr .import_model_from_zip (
1051
1059
model_name , project_name , zip_file , version = version
0 commit comments