Skip to content

Commit

Permalink
Improve is_local_uri (#10638)
Browse files Browse the repository at this point in the history
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
  • Loading branch information
harupy committed Dec 7, 2023
1 parent 369fde4 commit 4bd7f27
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mlflow/utils/uri.py
Expand Up @@ -41,15 +41,18 @@ def is_local_uri(uri, is_tracking_or_registry_uri=True):
return False

parsed_uri = urllib.parse.urlparse(uri)
scheme = parsed_uri.scheme
if scheme == "":
return True

if parsed_uri.hostname and not (
parsed_uri.hostname == "."
or parsed_uri.hostname.startswith("localhost")
or parsed_uri.hostname.startswith("127.0.0.1")
):
return False

scheme = parsed_uri.scheme
if scheme == "" or scheme == "file":
if scheme == "file":
return True

if is_windows() and len(scheme) == 1 and scheme.lower() == pathlib.Path(uri).drive.lower()[0]:
Expand Down
2 changes: 2 additions & 0 deletions tests/utils/test_uri.py
Expand Up @@ -99,6 +99,8 @@ def test_is_local_uri():
assert is_local_uri("file://localhost:5000/mlruns")
assert is_local_uri("file://127.0.0.1/mlruns")
assert is_local_uri("file://127.0.0.1:5000/mlruns")
assert is_local_uri("//proc/self/root")
assert is_local_uri("/proc/self/root")

assert not is_local_uri("file://myhostname/path/to/file")
assert not is_local_uri("https://whatever")
Expand Down

0 comments on commit 4bd7f27

Please sign in to comment.