-
Notifications
You must be signed in to change notification settings - Fork 171
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
Adapt pysteps to allow for postprocessing plugins #405
base: master
Are you sure you want to change the base?
Changes from 28 commits
f2c7514
11abb0d
36741db
9e79882
5abe467
092557c
15de2a4
c6ca85d
f5558ac
e64b70b
6605643
2ed3411
01bf7ba
3586f56
f581846
cb89616
f9bf9cf
13922fc
cb2529c
c1c4817
198df51
8c905f2
1305e88
296694d
b45c9a7
a20ce17
a4e0b6a
f340085
06d181a
17397e5
f5df5a8
ccbb41f
db83773
fa97a35
444331a
657e56e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,8 @@ | |
""" | ||
import importlib | ||
|
||
from importlib.metadata import entry_points | ||
|
||
from pysteps import io | ||
from pysteps.decorators import postprocess_import | ||
from pysteps.io import importers, exporters | ||
from pysteps.io import importers, exporters, interface | ||
from pprint import pprint | ||
|
||
_importer_methods = dict( | ||
|
@@ -49,7 +46,16 @@ def discover_importers(): | |
The importers found are added to the `pysteps.io.interface_importer_methods` | ||
dictionary containing the available importers. | ||
""" | ||
for entry_point in entry_points(group="pysteps.plugins.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.importer", name=None | ||
): | ||
_importer = entry_point.load() | ||
|
||
importer_function_name = _importer.__name__ | ||
|
@@ -63,14 +69,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}:{entry_point.attr}" | ||
f"Skipping {entry_point.module_name}:{entry_point.attrs}" | ||
) | ||
|
||
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}:{entry_point.attr}" | ||
f"Skipping {entry_point.module_name}:{entry_point.attrs}" | ||
) | ||
else: | ||
setattr(importers, importer_function_name, _importer) | ||
|
@@ -81,22 +87,22 @@ def importers_info(): | |
|
||
# Importers available in the `io.importers` module | ||
available_importers = [ | ||
attr for attr in dir(io.importers) if attr.startswith("import_") | ||
attr for attr in dir(importers) if attr.startswith("import_") | ||
] | ||
|
||
print("\nImporters available in the pysteps.io.importers module") | ||
pprint(available_importers) | ||
|
||
# Importers declared in the pysteps.io.get_method interface | ||
importers_in_the_interface = [ | ||
f.__name__ for f in io.interface._importer_methods.values() | ||
f.__name__ for f in interface._importer_methods.values() | ||
] | ||
|
||
print("\nImporters available in the pysteps.io.get_method interface") | ||
pprint( | ||
[ | ||
(short_name, f.__name__) | ||
for short_name, f in io.interface._importer_methods.items() | ||
for short_name, f in interface._importer_methods.items() | ||
] | ||
) | ||
|
||
|
@@ -107,7 +113,7 @@ def importers_info(): | |
|
||
difference = available_importers ^ importers_in_the_interface | ||
if len(difference) > 0: | ||
print("\nIMPORTANT:") | ||
# print("\nIMPORTANT:") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete? |
||
_diff = available_importers - importers_in_the_interface | ||
if len(_diff) > 0: | ||
print( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we just delete this file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, at least not until we change the structure. The objective was to create a structure similar to what exists for the importers with New functions found in the entry_points are added to the available methods in the methods dictionary. The ( Footnotes
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
pysteps.postprocessing.diagnostics | ||
==================== | ||
|
||
Methods for applying diagnostics postprocessing. | ||
|
||
The methods in this module implement the following interface:: | ||
|
||
diagnostic_xxx(optional arguments) | ||
|
||
where **xxx** is the name of the diagnostic to be applied. | ||
|
||
Available Diagnostics Postprocessors | ||
------------------------ | ||
|
||
.. autosummary:: | ||
:toctree: ../generated/ | ||
|
||
""" | ||
|
||
# def diagnostic_example1(filename, **kwargs): | ||
# return "Hello, I am an example diagnostics postprocessor." | ||
|
||
|
||
# def diagnostic_example2(filename, **kwargs): | ||
# return [[42, 42], [42, 42]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should similar lines be added to test the diagnostics plugin? Or not needed here in ci?