Skip to content

Commit

Permalink
AC-207: add importlib.metadata python3.12 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
vshevchenko-anaconda committed Feb 20, 2024
1 parent b176920 commit 16ca95e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions binstar_client/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
logger = logging.getLogger('binstar')


def _get_entry_points(group: str) -> typing.List[metadata.EntryPoint]:
def _get_entry_points(group: str) -> typing.List[metadata.EntryPoint] | metadata.EntryPoints:
# The API was changed in Python 3.10, see https://docs.python.org/3/library/importlib.metadata.html#entry-points
if sys.version_info.major == 3 and sys.version_info.minor < 10:
return metadata.entry_points().get(group, [])
Expand Down Expand Up @@ -223,7 +223,7 @@ def _load_main_plugin() -> typing.Optional[typing.Callable[[], typing.Any]]:
"""Allow loading a new CLI main entrypoint via plugin mechanisms. There can only be one."""
plugin_group_name: typing.Final[str] = 'anaconda_cli.main'

plugin_mains: typing.List[metadata.EntryPoint] = _get_entry_points(plugin_group_name)
plugin_mains: typing.List[metadata.EntryPoint] | metadata.EntryPoints = _get_entry_points(plugin_group_name)

if len(plugin_mains) > 1:
raise EnvironmentError(
Expand All @@ -237,7 +237,7 @@ def _load_main_plugin() -> typing.Optional[typing.Callable[[], typing.Any]]:
# e.g. in pyproject.toml, where my_plugin_library.cli.main is the callable entrypoint function
# [project.entry-points."anaconda_cli.main"]
# anaconda = "my_plugin_library.cli:main"
return plugin_mains[0].load()
return tuple(plugin_mains)[0].load()
return None


Expand Down

0 comments on commit 16ca95e

Please sign in to comment.