From 4ccabafb72cab6ed9f486265037062dd9a6f3a10 Mon Sep 17 00:00:00 2001 From: Daniele Nerini Date: Sun, 6 Jul 2025 09:34:17 +0200 Subject: [PATCH 1/3] Re-apply fix from #446 --- pysteps/io/interface.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) 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) From bf5fe70c7a6dd541f9828a07d164cef59af2f5e1 Mon Sep 17 00:00:00 2001 From: Daniele Nerini Date: Tue, 8 Jul 2025 21:02:46 +0200 Subject: [PATCH 2/3] Replace deprecated pkg_resources with importlib --- pysteps/postprocessing/interface.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/pysteps/postprocessing/interface.py b/pysteps/postprocessing/interface.py index 97b96053..ea1e476c 100644 --- a/pysteps/postprocessing/interface.py +++ b/pysteps/postprocessing/interface.py @@ -16,7 +16,7 @@ get_method """ -import importlib +from importlib.metadata import entry_points from pysteps.postprocessing import diagnostics, ensemblestats from pprint import pprint @@ -82,28 +82,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, ) From 1cac989575e81e9965a4816f3643ecff195717c4 Mon Sep 17 00:00:00 2001 From: Daniele Nerini Date: Tue, 8 Jul 2025 22:12:38 +0200 Subject: [PATCH 3/3] Fix missing import --- pysteps/postprocessing/interface.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pysteps/postprocessing/interface.py b/pysteps/postprocessing/interface.py index ea1e476c..130f7cab 100644 --- a/pysteps/postprocessing/interface.py +++ b/pysteps/postprocessing/interface.py @@ -16,6 +16,7 @@ get_method """ +import importlib from importlib.metadata import entry_points from pysteps.postprocessing import diagnostics, ensemblestats