diff --git a/pysteps/io/interface.py b/pysteps/io/interface.py index b64ddd8e..d674b01e 100644 --- a/pysteps/io/interface.py +++ b/pysteps/io/interface.py @@ -12,7 +12,7 @@ get_method """ -import importlib +from importlib.metadata import entry_points from pysteps.decorators import postprocess_import from pysteps.io import importers, exporters, interface @@ -46,17 +46,11 @@ 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) # Backward compatibility with previous entry point 'pysteps.plugins.importers' next to 'pysteps.plugins.importer' for entry_point in list( - pkg_resources.iter_entry_points(group="pysteps.plugins.importer", name=None) + entry_points(group="pysteps.plugins.importer") ) + list( - pkg_resources.iter_entry_points(group="pysteps.plugins.importers", name=None) + entry_points(group="pysteps.plugins.importers") ): _importer = entry_point.load() @@ -71,14 +65,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}:{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}:{entry_point.attrs}" + f"Skipping {entry_point.module}:{entry_point.attr}" ) else: setattr(importers, importer_function_name, _importer) diff --git a/pysteps/postprocessing/interface.py b/pysteps/postprocessing/interface.py index 97b96053..130f7cab 100644 --- a/pysteps/postprocessing/interface.py +++ b/pysteps/postprocessing/interface.py @@ -17,6 +17,7 @@ get_method """ import importlib +from importlib.metadata import entry_points from pysteps.postprocessing import diagnostics, ensemblestats from pprint import pprint @@ -82,28 +83,19 @@ def discover_postprocessors(): dictionary in 'pysteps.postprocessing.interface' containing the available postprocessors. """ - # The pkg resources needs to be reloaded 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) - # Discover the postprocessors available in the plugins for plugintype in ["diagnostic", "ensemblestat"]: - for entry_point in pkg_resources.iter_entry_points( - group=f"pysteps.plugins.{plugintype}", name=None - ): + for entry_point in entry_points(group=f"pysteps.plugins.{plugintype}"): _postprocessors = entry_point.load() postprocessors_function_name = _postprocessors.__name__ - if plugintype in entry_point.module_name: + if plugintype in entry_point.module: add_postprocessor( postprocessors_function_name, _postprocessors, f"{plugintype}s", - entry_point.attrs, + entry_point.attr, )