Skip to content

Commit

Permalink
fix: importlib.metadata get
Browse files Browse the repository at this point in the history
Signed-off-by: Raphael Auv <raphaelauv@users.noreply.github.com>
  • Loading branch information
raphaelauv committed Dec 26, 2023
1 parent 3c98879 commit 19dc724
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 2 additions & 3 deletions mlflow/cli.py
@@ -1,5 +1,4 @@
import contextlib
import importlib.metadata
import json
import logging
import os
Expand Down Expand Up @@ -27,7 +26,7 @@
from mlflow.tracking import _get_store
from mlflow.utils import cli_args
from mlflow.utils.logging_utils import eprint
from mlflow.utils.os import is_windows
from mlflow.utils.os import get_entry_points, is_windows
from mlflow.utils.process import ShellCommandException
from mlflow.utils.server_cli_utils import (
artifacts_only_config_validation,
Expand Down Expand Up @@ -353,7 +352,7 @@ def _validate_static_prefix(ctx, param, value): # pylint: disable=unused-argume
@click.option(
"--app-name",
default=None,
type=click.Choice([e.name for e in importlib.metadata.entry_points().get("mlflow.app", [])]),
type=click.Choice([e.name for e in get_entry_points("mlflow.app")]),
show_default=True,
help=(
"Application name to be used for the tracking server. "
Expand Down
6 changes: 3 additions & 3 deletions mlflow/server/__init__.py
Expand Up @@ -22,7 +22,7 @@
search_datasets_handler,
upload_artifact_handler,
)
from mlflow.utils.os import is_windows
from mlflow.utils.os import get_entry_points, is_windows
from mlflow.utils.process import _exec_cmd
from mlflow.version import VERSION

Expand Down Expand Up @@ -142,7 +142,7 @@ def serve():


def _find_app(app_name: str) -> str:
apps = importlib.metadata.entry_points().get("mlflow.app", [])
apps = get_entry_points("mlflow.app")
for app in apps:
if app.name == app_name:
return app.value
Expand Down Expand Up @@ -173,7 +173,7 @@ def get_app_client(app_name: str, *args, **kwargs):
:param kwargs: Additional keyword arguments passed to the app client constructor.
:return: An app client instance.
"""
clients = importlib.metadata.entry_points().get("mlflow.app.client", [])
clients = get_entry_points("mlflow.app.client")
for client in clients:
if client.name == app_name:
cls = client.load()
Expand Down
12 changes: 12 additions & 0 deletions mlflow/utils/os.py
@@ -1,8 +1,20 @@
import os
import sys
import importlib.metadata


def is_windows():
"""
:return: Returns true if the local system/OS name is Windows.
"""
return os.name == "nt"


def get_entry_points(namespace):
if sys.version_info >= (3, 10):
return importlib.metadata.entry_points(group=namespace)
else:
try:
return importlib.metadata.entry_points().get(namespace, [])
except AttributeError:
return importlib.metadata.entry_points().select(group=namespace)

0 comments on commit 19dc724

Please sign in to comment.