forked from mlflow/mlflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move URI helper methods to utils.uri module (mlflow#1915)
Consolidate URI helper methods that aren't just used by tracking to utils.uri.
- Loading branch information
Showing
16 changed files
with
155 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from six.moves import urllib | ||
|
||
from mlflow.exceptions import MlflowException | ||
from mlflow.protos.databricks_pb2 import INVALID_PARAMETER_VALUE | ||
from mlflow.store.db.db_types import DATABASE_ENGINES | ||
from mlflow.utils.validation import _validate_db_type_string | ||
|
||
_INVALID_DB_URI_MSG = "Please refer to https://mlflow.org/docs/latest/tracking.html#storage for " \ | ||
"format specifications." | ||
|
||
|
||
def is_local_uri(uri): | ||
"""Returns true if this is a local file path (/foo or file:/foo).""" | ||
scheme = urllib.parse.urlparse(uri).scheme | ||
return uri != 'databricks' and (scheme == '' or scheme == 'file') | ||
|
||
|
||
def is_http_uri(uri): | ||
scheme = urllib.parse.urlparse(uri).scheme | ||
return scheme == 'http' or scheme == 'https' | ||
|
||
|
||
def is_databricks_uri(uri): | ||
"""Databricks URIs look like 'databricks' (default profile) or 'databricks://profile'""" | ||
scheme = urllib.parse.urlparse(uri).scheme | ||
return scheme == 'databricks' or uri == 'databricks' | ||
|
||
|
||
def get_db_profile_from_uri(uri): | ||
""" | ||
Get the Databricks profile specified by the tracking URI (if any), otherwise | ||
returns None. | ||
""" | ||
parsed_uri = urllib.parse.urlparse(uri) | ||
if parsed_uri.scheme == "databricks": | ||
return parsed_uri.netloc | ||
return None | ||
|
||
|
||
def extract_db_type_from_uri(db_uri): | ||
""" | ||
Parse the specified DB URI to extract the database type. Confirm the database type is | ||
supported. If a driver is specified, confirm it passes a plausible regex. | ||
""" | ||
scheme = urllib.parse.urlparse(db_uri).scheme | ||
scheme_plus_count = scheme.count('+') | ||
|
||
if scheme_plus_count == 0: | ||
db_type = scheme | ||
elif scheme_plus_count == 1: | ||
db_type, _ = scheme.split('+') | ||
else: | ||
error_msg = "Invalid database URI: '%s'. %s" % (db_uri, _INVALID_DB_URI_MSG) | ||
raise MlflowException(error_msg, INVALID_PARAMETER_VALUE) | ||
|
||
_validate_db_type_string(db_type) | ||
|
||
return db_type | ||
|
||
|
||
def get_uri_scheme(uri_or_path): | ||
scheme = urllib.parse.urlparse(uri_or_path).scheme | ||
if any([scheme.lower().startswith(db) for db in DATABASE_ENGINES]): | ||
return extract_db_type_from_uri(uri_or_path) | ||
else: | ||
return scheme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.