Skip to content

Commit 1e67739

Browse files
authored
Apply fix from #446 to replace pkg_resources with importlib (#485)
1 parent 0908f18 commit 1e67739

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

pysteps/io/interface.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
get_method
1414
"""
15-
import importlib
15+
from importlib.metadata import entry_points
1616

1717
from pysteps.decorators import postprocess_import
1818
from pysteps.io import importers, exporters, interface
@@ -46,17 +46,11 @@ def discover_importers():
4646
The importers found are added to the `pysteps.io.interface_importer_methods`
4747
dictionary containing the available importers.
4848
"""
49-
# The pkg resources needs to be reload to detect new packages installed during
50-
# the execution of the python application. For example, when the plugins are
51-
# installed during the tests
52-
import pkg_resources
53-
54-
importlib.reload(pkg_resources)
5549
# Backward compatibility with previous entry point 'pysteps.plugins.importers' next to 'pysteps.plugins.importer'
5650
for entry_point in list(
57-
pkg_resources.iter_entry_points(group="pysteps.plugins.importer", name=None)
51+
entry_points(group="pysteps.plugins.importer")
5852
) + list(
59-
pkg_resources.iter_entry_points(group="pysteps.plugins.importers", name=None)
53+
entry_points(group="pysteps.plugins.importers")
6054
):
6155
_importer = entry_point.load()
6256

@@ -71,14 +65,14 @@ def discover_importers():
7165
RuntimeWarning(
7266
f"The importer identifier '{importer_short_name}' is already available in"
7367
"'pysteps.io.interface._importer_methods'.\n"
74-
f"Skipping {entry_point.module_name}:{entry_point.attrs}"
68+
f"Skipping {entry_point.module}:{entry_point.attr}"
7569
)
7670

7771
if hasattr(importers, importer_function_name):
7872
RuntimeWarning(
7973
f"The importer function '{importer_function_name}' is already an attribute"
8074
"of 'pysteps.io.importers`.\n"
81-
f"Skipping {entry_point.module_name}:{entry_point.attrs}"
75+
f"Skipping {entry_point.module}:{entry_point.attr}"
8276
)
8377
else:
8478
setattr(importers, importer_function_name, _importer)

pysteps/postprocessing/interface.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
get_method
1818
"""
1919
import importlib
20+
from importlib.metadata import entry_points
2021

2122
from pysteps.postprocessing import diagnostics, ensemblestats
2223
from pprint import pprint
@@ -82,28 +83,19 @@ def discover_postprocessors():
8283
dictionary in 'pysteps.postprocessing.interface' containing the available postprocessors.
8384
"""
8485

85-
# The pkg resources needs to be reloaded to detect new packages installed during
86-
# the execution of the python application. For example, when the plugins are
87-
# installed during the tests
88-
import pkg_resources
89-
90-
importlib.reload(pkg_resources)
91-
9286
# Discover the postprocessors available in the plugins
9387
for plugintype in ["diagnostic", "ensemblestat"]:
94-
for entry_point in pkg_resources.iter_entry_points(
95-
group=f"pysteps.plugins.{plugintype}", name=None
96-
):
88+
for entry_point in entry_points(group=f"pysteps.plugins.{plugintype}"):
9789
_postprocessors = entry_point.load()
9890

9991
postprocessors_function_name = _postprocessors.__name__
10092

101-
if plugintype in entry_point.module_name:
93+
if plugintype in entry_point.module:
10294
add_postprocessor(
10395
postprocessors_function_name,
10496
_postprocessors,
10597
f"{plugintype}s",
106-
entry_point.attrs,
98+
entry_point.attr,
10799
)
108100

109101

0 commit comments

Comments
 (0)