Skip to content

Commit

Permalink
Address deprecation warning from importlib_resources
Browse files Browse the repository at this point in the history
In `importlib_metdata` 3.9 and Python 3.10, the `entry_points` function
deprecated the `dict`-like interface of its return, instead a new
`select` function was introduced.

https://importlib-metadata.readthedocs.io/en/latest/using.html#functional-api
  • Loading branch information
abravalheri committed Apr 1, 2021
1 parent 8b86d97 commit 24211fd
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/pyscaffold/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import argparse
import sys
import textwrap
from typing import Callable, Iterator, List, Optional, Type
from typing import Callable, Iterable, List, Optional, Type

from ..actions import Action, register, unregister
from ..exceptions import ErrorLoadingExtension
Expand Down Expand Up @@ -146,7 +146,7 @@ def __call__(self, parser, namespace, values, option_string=None):
return AddExtensionAndStore


def iterate_entry_points(group=ENTRYPOINT_GROUP) -> Iterator[EntryPoint]:
def iterate_entry_points(group=ENTRYPOINT_GROUP) -> Iterable[EntryPoint]:
"""Produces a generator yielding an EntryPoint object for each extension registered
via setuptools `entry point mechanism`_.
Expand All @@ -156,7 +156,15 @@ def iterate_entry_points(group=ENTRYPOINT_GROUP) -> Iterator[EntryPoint]:
.. _entry point mechanism: https://setuptools.readthedocs.io/en/latest/pkg_resources.html?highlight=entrypoint#id15
""" # noqa
return (extension for extension in entry_points().get(group, []))
entries = entry_points()
if hasattr(entries, "select"):
# The select method was introduced in importlib_metadata 3.9 (and Python 3.10)
# and the previous dict interface was declared deprecated
return entries.select(group=group) # type: ignore
else:
# TODO: Once Python 3.10 becomes the oldest version supported, this fallback and
# conditional statement can be removed.
return (extension for extension in entries.get(group, [])) # type: ignore


def load_from_entry_point(entry_point: EntryPoint) -> Extension:
Expand Down

0 comments on commit 24211fd

Please sign in to comment.