Skip to content
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

Look for plugins via entry points #677

Merged
merged 6 commits into from
Jul 2, 2015

Conversation

astrofrog
Copy link
Member

This is a WIP, but it shows how glue can load plugins via entry points. The logger doesn't currently work because the level is only set once main() is executed.

This brings up a more fundamental philosophical question which is whether we should be doing all this in __init__.py (short answer: I don't think so). This means that if anyone writes a package that imports something from glue, all plugins will be loaded, and some may take a while. We could instead do all this (loading internal plugins, loading external plugins, and loading user configuration) when the application is started instead.

However, if someone wants to use glue from a Python script but needs to use one of the plugins (which somehow enhances command-line usage) then this won't necessarily work for them.

As a compromise, we could put the loading of plugins and of the configuration in a function that gets executed when GlueApplication is instantiated, and which users can also call from Python scripts if needed:

import glue
glue.load_config()
glue.load_plugins()

Yes, this is a bit more manual for the case where someone wants to use glue from Python without launching the application and needs access to plugins, but that seems like a corner case?

@ChrisBeaumont - what do you think about this idea?

@astrofrog
Copy link
Member Author

I've updated the glue-exp repository to define the entry points to demonstrate how it would work:

https://github.com/glue-viz/glue-exp/blob/master/setup.py#L11

@ChrisBeaumont
Copy link
Member

This change sounds fine as long as it plays nicely with the mac app.

I like your compromise solution, of packaging loading logic into 1-2 functions, and calling from GlueApplication

@astrofrog
Copy link
Member Author

I decided to leave the configuration loading in __init__.py for now since a lot of things rely on that (and more specifically env). However, I've now moved the plugin loading to a function in glue.main and it gets called when starting up GlueApplication.

@astrofrog
Copy link
Member Author

I do want to address the config loading in future, but just in a separate PR.

@astrofrog
Copy link
Member Author

Note to self: I need to prevent plugins from being loaded twice.

@astrofrog
Copy link
Member Author

For now, the Mac app doesn't see the entry points. Looking into it.

@astrofrog
Copy link
Member Author

Bummer: https://bitbucket.org/ronaldoussoren/py2app/issue/1/py2app-doesnt-support-egg-metadata

I still think entry points are the way to go, so will try and see if there are ways to work around this.

@astrofrog
Copy link
Member Author

Note to self: look into how easy it would be to use http://www.sveinbjorn.org/platypus instead of py2app if the worst comes to the worst

@astrofrog astrofrog force-pushed the entry-point-discovery branch from d1230b9 to d82e49a Compare July 2, 2015 19:42
@astrofrog astrofrog changed the title WIP: Look for plugins via entry points Look for plugins via entry points Jul 2, 2015
@astrofrog
Copy link
Member Author

This now works and requires the following patch in the mac builder repository:

glue-viz/Travis-MacGlue@a7ae36c

The issue is that py2app doesn't know about entry points, so what we instead do is use a wrapper function called iter_plugin_entry_points that iterates over the entry points for plugins, and in the glue recipe for py2app we patch this to hard-code the entry points in the app. In the non-app version, this function loads plugins dynamically.

@astrofrog
Copy link
Member Author

Just for the record, this is the patched version of the function:

from pkg_resources import EntryPoint
def iter_plugin_entry_points():
    yield EntryPoint('ginga_viewer', 'glue.plugins.ginga_viewer', attrs=('setup',))
    yield EntryPoint('export_plotly', 'glue.plugins.export_plotly', attrs=('setup',))
    yield EntryPoint('export_d3po', 'glue.plugins.export_d3po', attrs=('setup',))
    yield EntryPoint('pv_slicer', 'glue.plugins.tools.pv_slicer', attrs=('setup',))
    yield EntryPoint('spectrum_tool', 'glue.plugins.tools.spectrum_tool', attrs=('setup',))
    yield EntryPoint('coordinate_helpers', 'glue.plugins.coordinate_helpers', attrs=('setup',))
from glue import plugin_helpers
plugin_helpers.iter_plugin_entry_points = iter_plugin_entry_points

at the moment. If we add plugins to the built-in glue, these will get automatically added to the app in future versions of the app. If we want to add external plugins to the app, we have to remember to add them to the glue_recipe.py file in the Mac builder.

@astrofrog
Copy link
Member Author

Ok, I'm pretty happy with this, and I'd like to include it in 0.5 so that it will already understand plugins. The entry_points mechanism applied to plugins is pretty cool, and I wish I'd known about it sooner!

@ChrisBeaumont - since you ok-ed this before modulo the Mac app issue, and that this is now resolved, I'll go ahead and merge, but feel free to leave comments on this and I can fix post-merge!

astrofrog added a commit that referenced this pull request Jul 2, 2015
@astrofrog astrofrog merged commit 274426c into glue-viz:master Jul 2, 2015
@astrofrog
Copy link
Member Author

Just FYI, the latest 'master' build here: http://mac.glueviz.org/ works fine (basically the export plugins are there)

@astrofrog astrofrog mentioned this pull request Jul 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants