Skip to content

Commit 70af197

Browse files
committed
fix: upload .sasast models correctly (PMMODEL-682)
1 parent 5b3e1f8 commit 70af197

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/sasctl/tasks.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,17 +1045,33 @@ def upload_local_model(
10451045
# Get project from repo if it exists; if it doesn't, create a new one
10461046
p = mr.get_project(project_name)
10471047
if p is None:
1048-
mr.create_project(project_name, repository)
1048+
p = mr.create_project(project_name, repository)
10491049

10501050
# zip up all files in directory (except any previous zip files)
10511051
zip_name = str(Path(path) / (model_name + ".zip"))
1052-
file_names = sorted(Path(path).glob("*[!zip]"))
1053-
with zipfile.ZipFile(str(zip_name), mode="w") as zFile:
1052+
file_names = sorted(Path(path).glob("*[!(zip|sasast)]"))
1053+
sasast_file = next(Path(path).glob("*.sasast"), None)
1054+
if sasast_file:
1055+
# If a sasast file is present, upload it as well
1056+
with open(sasast_file, "rb") as sasast:
1057+
sasast_model = sasast.read()
1058+
data = {
1059+
"name": model_name,
1060+
"projectId": p.id,
1061+
"type": "ASTORE",
1062+
}
1063+
files = {"files": (sasast_file.name, sasast_model)}
1064+
model = mr.post("/models", files=files, data=data)
10541065
for file in file_names:
1055-
zFile.write(str(file), arcname=file.name)
1056-
# upload zipped model
1057-
with open(zip_name, "rb") as zip_file:
1058-
model = mr.import_model_from_zip(
1059-
model_name, project_name, zip_file, version=version
1060-
)
1066+
with open(file, "r") as f:
1067+
mr.add_model_content(model, f, file.name)
1068+
else:
1069+
with zipfile.ZipFile(str(zip_name), mode="w") as zFile:
1070+
for file in file_names:
1071+
zFile.write(str(file), arcname=file.name)
1072+
# upload zipped model
1073+
with open(zip_name, "rb") as zip_file:
1074+
model = mr.import_model_from_zip(
1075+
model_name, project_name, zip_file, version=version
1076+
)
10611077
return model

0 commit comments

Comments
 (0)