Skip to content

Commit

Permalink
Migrate logic for default artifact root
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Wilson <benjamin.wilson@databricks.com>
  • Loading branch information
BenWilson2 committed Nov 24, 2021
1 parent 5c1e158 commit 09b84eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
11 changes: 2 additions & 9 deletions mlflow/cli.py
Expand Up @@ -20,7 +20,7 @@
from mlflow.utils.annotations import experimental
from mlflow.utils.logging_utils import eprint
from mlflow.utils.process import ShellCommandException
from mlflow.utils.uri import is_local_uri, resolve_default_artifact_root
from mlflow.utils.uri import resolve_default_artifact_root
from mlflow.entities.lifecycle_stage import LifecycleStage
from mlflow.exceptions import MlflowException

Expand Down Expand Up @@ -271,7 +271,7 @@ def ui(
backend_store_uri = DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH

default_artifact_root = resolve_default_artifact_root(
serve_artifacts, default_artifact_root, backend_store_uri
serve_artifacts, default_artifact_root, backend_store_uri, True
)

try:
Expand Down Expand Up @@ -403,13 +403,6 @@ def server(
if not backend_store_uri:
backend_store_uri = DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH

if not serve_artifacts and not default_artifact_root and not is_local_uri(backend_store_uri):
eprint(
"Option 'default-artifact-root' is required, when backend store is not "
"local file based."
)
sys.exit(1)

default_artifact_root = resolve_default_artifact_root(
serve_artifacts, default_artifact_root, backend_store_uri
)
Expand Down
14 changes: 12 additions & 2 deletions mlflow/utils/uri.py
@@ -1,3 +1,4 @@
import sys
import posixpath
import urllib.parse

Expand All @@ -6,6 +7,7 @@
from mlflow.store.db.db_types import DATABASE_ENGINES
from mlflow.store.tracking import DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH, DEFAULT_ARTIFACTS_URI
from mlflow.utils.validation import _validate_db_type_string
from mlflow.utils.logging_utils import eprint

_INVALID_DB_URI_MSG = (
"Please refer to https://mlflow.org/docs/latest/tracking.html#storage for "
Expand Down Expand Up @@ -297,13 +299,21 @@ def dbfs_hdfs_uri_to_fuse_path(dbfs_uri):
return _DBFS_FUSE_PREFIX + dbfs_uri[len(_DBFS_HDFS_URI_PREFIX) :]


def resolve_default_artifact_root(serve_artifacts, default_artifact_root, backend_store_uri):
def resolve_default_artifact_root(
serve_artifacts, default_artifact_root, backend_store_uri, resolve_to_local=False
):

if serve_artifacts and not default_artifact_root:
default_artifact_root = DEFAULT_ARTIFACTS_URI
elif not serve_artifacts and not default_artifact_root:
if is_local_uri(backend_store_uri):
default_artifact_root = backend_store_uri
else:
elif resolve_to_local:
default_artifact_root = DEFAULT_LOCAL_FILE_AND_ARTIFACT_PATH
else:
eprint(
"Option 'default-artifact-root' is required, when backend store is not "
"local file based."
)
sys.exit(1)
return default_artifact_root

0 comments on commit 09b84eb

Please sign in to comment.