-
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
Support for importers plugins #174
Conversation
The plugin functionality it is only tested in the minimal checks.
Hi @aperezhortal So, if I understand correctly, to install a new custom importer, I would have to first run the cookiecutter, then implement my importer in the template, right? After this, how is the registration into pysteps done? Simply using pip install? One more question, I assume new plugins won't be shared with the rest of the community, correct? These will essentially remain private methods. Once again, great idea, thanks! |
The first step is creating the plugin (a python package). To facilitate this, cookiecutter (and the cookiecutter-pysteps-plugin template) is used to create the skeleton of the plugin project. Then, the new importers need to be added to the barebone project.
When you install the package using Then, when pysteps is importer, it calls the pysteps.io.interface.discover_importers() function that looks for the entry points available in the python distribution and registers the ones that belong to the "pysteps.plugins.importers" group (the group name was defined in the setup.py). The main advantage of this approach is that the plugins will keep working if the pysteps version is updated without any user intervention.
This is the best part, in my opinion. The users who create the plugins have ownership and they are free to distribute or not the packages. For example, if an organization uses "in-house" tools to read files that cannot be openly distributed, they can internally distribute the plugin. (I will include the information of these anwers in the plugins documentation) |
This sounds really great, I personally think we should go ahead. What would be the next steps? How can we help? |
Great! I will push the first draft soon with the minimal installation instructions to use it as a starting point. We can then incrementally improve the tutorial to make it as clear and easy to follow as possible. |
This is the first draft for the importers plugin implementation.
Codecov Report
@@ Coverage Diff @@
## master #174 +/- ##
==========================================
- Coverage 75.92% 75.72% -0.21%
==========================================
Files 125 126 +1
Lines 9487 9491 +4
==========================================
- Hits 7203 7187 -16
- Misses 2284 2304 +20
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@aperezhortal this is truly amazing work! The documentation is excellent, I just corrected few typos and suggested few changes.
9022668
to
61052e2
Compare
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.
Very nice, Andres, very cool contribution!
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.
Great work @aperezhortal! I have nothing to add. :)
This PR adds support for adding additional importers to the pysteps interface without modifying the pysteps source code. Instead, the users can add custom importers to pysteps by installing external packages, called plugins, that are automatically "discovered" and integrated to pysteps.
How does it work?
Let's suppose that we have a plugin (python package), named
importer_abc_xyz
, that contains the following importers:importer_abc_xyz.importers.import_abc_yyy
importer_abc_xyz.importers.import_abc_zzz
When the plugin is installed, it adds entry_points to the python installation advertising the components of this plugin to other packages (in our case, pysteps).
Next, when pysteps is imported, it discovers the available entry_points that belong to the pysteps.plugins.importers group (the group name is defined in the plugin). These discovered importers are added as attributes to the
io.importers
module, and they are registered to theio.get_method
interface.After the external importers are registered, they become part of the pysteps interface and can be used together with the other available importers.
Plugin project template
To make the creation of the plugin easier, a cookiecutter project template, available at https://github.com/pySTEPS/cookiecutter-pysteps-plugin, can be used to quickly create a plugin project by executing:
$> cookiecutter https://github.com/pySTEPS/cookiecutter-pysteps-plugin
and follow the interactive instructions.
Documentation
PR progress [Updated]