Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use importlib.metadata instead of pkg_resources #446

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions pysteps/io/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""
import importlib

from pkg_resources import iter_entry_points
from importlib.metadata import entry_points

from pysteps import io
from pysteps.decorators import postprocess_import
Expand Down Expand Up @@ -49,17 +49,7 @@ def discover_importers():
The importers found are added to the `pysteps.io.interface_importer_methods`
dictionary containing the available importers.
"""

# The pkg resources needs to be reload to detect new packages installed during
# the execution of the python application. For example, when the plugins are
# installed during the tests
import pkg_resources

importlib.reload(pkg_resources)

for entry_point in pkg_resources.iter_entry_points(
group="pysteps.plugins.importers", name=None
):
for entry_point in entry_points(group="pysteps.plugins.importers"):
_importer = entry_point.load()

importer_function_name = _importer.__name__
Expand All @@ -73,14 +63,14 @@ def discover_importers():
RuntimeWarning(
f"The importer identifier '{importer_short_name}' is already available in"
"'pysteps.io.interface._importer_methods'.\n"
f"Skipping {entry_point.module_name}:{'.'.join(entry_point.attrs)}"
f"Skipping {entry_point.module}:{entry_point.attr}"
)

if hasattr(importers, importer_function_name):
RuntimeWarning(
f"The importer function '{importer_function_name}' is already an attribute"
"of 'pysteps.io.importers`.\n"
f"Skipping {entry_point.module_name}:{'.'.join(entry_point.attrs)}"
f"Skipping {entry_point.module}:{entry_point.attr}"
)
else:
setattr(importers, importer_function_name, _importer)
Expand Down
Loading