Skip to content

Commit 6058d2d

Browse files
author
Jason Wang
committed
adding s3 bucket parsing for model paths
1 parent 47cc6ce commit 6058d2d

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

mlflow_export_import/model/import_model.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import os
66
import click
7+
from urllib.parse import urlparse
78

89
import mlflow
910
from mlflow.exceptions import RestException
@@ -211,6 +212,14 @@ def _extract_model_path(source, run_id):
211212
:param run_id: Run ID in the 'source field
212213
:return: relative path to the model artifact
213214
"""
215+
if source[:5] == "s3://": # check if source is s3 bucket
216+
# bucket name may contain 'artifacts', this bypasses the bucket name
217+
pattern = "artifacts"
218+
parsed_s3 = urlparse(source)
219+
s3_path = parsed_s3.path
220+
idx = s3_path.find(pattern)
221+
model_path = s3_path[1+idx+len(pattern):]
222+
return model_path
214223
idx = source.find(run_id)
215224
if idx == -1:
216225
raise MlflowExportImportException(f"Cannot find run ID '{run_id}' in registered model version source field '{source}'", http_status_code=404)

0 commit comments

Comments
 (0)