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

PR: Follow the Flask plugin model instead of namespace packages #3210

Merged
merged 14 commits into from
Jun 11, 2016

Conversation

Nodd
Copy link
Contributor

@Nodd Nodd commented Jun 7, 2016

Here is a quick prototype for loading plugins using the flask model.

Fixes #3150.
I went with the two different prefixes because it was simpler, it can be changed in the future.

I still have to look precisely at how to load a module, because from what I saw more functions were deprecated in python 3.5.

TODO:

  • Test user plugins (in ~/.spyder)
  • Test pip installed plugins
  • Remove the removal of whitespace

@Nodd Nodd added this to the v3.0beta4 milestone Jun 7, 2016
@Nodd Nodd assigned Nodd and goanpeca Jun 7, 2016
@ccordoba12
Copy link
Member

@Nodd, thanks a lot for working on this one!

Quick comments:

  1. I'd prefer that we name our plugins like spyder_ui_breakpoints instead of spyderui_breakpoints. I think it's clearer.
  2. Please revert blank removals, unless they are in the area of influence of your change.
  3. Why loading code needs to be revisited again?

@ccordoba12
Copy link
Member

Or maybe spy_ui_breakpoints to make things shorter ;-)

@goanpeca
Copy link
Member

goanpeca commented Jun 7, 2016

@Nodd and @ccordoba12 I dont think adding the ui or io is worth it. IO things are just plugins... so making the difference by name is really just making the names ugly and long.

We should just add some variable in the init of the plugin like

from spyderlib.plugin import IO_PLUGIN, UI_PLUGIN

PLUGIN_TYPES = [IO_PLUGIN, UI_PLUGIN]  # for a plugin that does the two things?
...

And have short names like (pip/conda package and module name):

spyder-autopep8 -> spyder_autopep8
spyder-conda-manager -> spyder_conda_manager
spyder-r -> spyder_r

...

@Nodd
Copy link
Contributor Author

Nodd commented Jun 7, 2016

@ccordoba12

  1. I hesitated between the two, the additional underscore make it look very long, but I agree it's clearer.
  2. Raaah, these freaking whitespaces ! We should burn them all ! OK ok, I'll do it.
  3. It's nothing big, right now I commented everything to test things on my machine easily. The code is the same but I'll double check if it's applied to the correct python versions.

@goanpeca From a certain point of view IO plugins are just plugins because they are additions to spyder, but they are actually very different from UI plugins:

  • they are used exclusively to load new file format, and have nothing to do with anything else
  • they are loaded during the imports (before spyder's initialization) and are considered as constants in multiple parts of the codebase

Also the big problem with differentiating by module variables (apart from being a little magical) is that you have to load the plugin to check which kind it is. Considering how they are loaded and used very differently internally, I sill think it makes sense to differentiate them explicitly in their names. To be honest if we decide to refactor the way IO plugins are loaded, someone else will have to do it because I won't be able to spend time on this.

To keep names shorter, I'd be in favor of having IO plugins starting with spyder_io_ and generic plugins starting with spyder_. I expect that there will be more generic plugins than io plugins in the future. To be exhaustive I'll add that it prevents generic plugin names from starting with io, but I don't think it'll be a problem. What do you prefer ?
In any case io/ui needs to be in the module name only, not necessarily the plugin name itself. spyder-myplugin can install the module spyder_ui_myplugin.

@goanpeca
Copy link
Member

goanpeca commented Jun 7, 2016

@Nodd, I understand how it works and how they load differently and how they might load differently. But IO plugins was just a special case of a general plugin that extends the variable explorer... so in a sense is a normal plugin that extends that functionality. It was not coded that way for whatever reason and it starts in a different part of the application for whatever reason, and trying to compensate for that seems like a bad idea.

In general every normal plugin could/should be extendable.

In any case io/ui needs to be in the module name only, not necessarily the plugin name itself. spyder-myplugin can install the module spyder_ui_myplugin.

I just dislike this very much and find very useful that modules and packages names relate to each other.

I agree that this might be out of the scope of this PR, but I dont see any good reason to maintain the current way IO plugins load/work

@Nodd
Copy link
Contributor Author

Nodd commented Jun 7, 2016

It's not "whatever reason". On one side a plugin is a function to load a file with a specific format and extension. On the other side a plugin has a complex API and explicitly needs a dockwidget (a menu-entry plugin needs a hack currently). Even if we name them both "plugins" they have a very different goal (I'm not even speaking about implementation).

It's not just a naming problem, having 2 different interfaces for plugins is weird. I think that the most correct way would be to integrate IO plugins into UI plugins (maybe with a helper class to inherit from ?), feel free to break everything ! 😉

To keep names shorter, I'd be in favor of having IO plugins starting with spyder_io_ and generic plugins starting with spyder_.

What do you think about this ? This way in the future we could change IO plugins only (merging them into ui plugins) while being backward compatible with ui plugins, and keeping the names clean.

@goanpeca
Copy link
Member

goanpeca commented Jun 7, 2016

It's not just a naming problem, having 2 different interfaces for plugins is weird. I think that the most correct way would be to integrate IO plugins into UI plugins (maybe with a helper class to inherit from ?), feel free to break everything ! 😉

Yes, I would like to have a single plugin interface, that is the whole point :-)

What do you think about this ? This way in the future we could change IO plugins only (merging them into ui plugins) while being backward compatible with ui plugins, and keeping the names clean.

Yes perfect. I would say the approach to take after this PR is:

  • Replicate the IO functionality in normal plugins
  • Allow for easy (io) plugin creation without needing a dockwidget (maybe?)
  • Allow for a standard way of adding entries to menus (this last one requires adding some sort of groups to menu entries)
  • Add extension points to the current widgets?

@Nodd
Copy link
Contributor Author

Nodd commented Jun 7, 2016

WTF git ? I merged nothing !

@goanpeca
Copy link
Member

goanpeca commented Jun 7, 2016

??

@Nodd
Copy link
Contributor Author

Nodd commented Jun 7, 2016

All my commits were removed from the PR...
Edit: OK I got it back.

@Nodd Nodd reopened this Jun 7, 2016
@ccordoba12
Copy link
Member

@Nodd, it seems you changed all line endings of several files :-)

@Nodd
Copy link
Contributor Author

Nodd commented Jun 8, 2016

😭 I edited some files on windows... I tought it was correctly configured, but it seems I was wrong.

@Nodd
Copy link
Contributor Author

Nodd commented Jun 8, 2016

I put the EOL back to the mess they where. I still have to re-mess the whitespaces !

@Nodd
Copy link
Contributor Author

Nodd commented Jun 8, 2016

OK, everything should work now ! I also updated spyder.line_profiler and spyder.autopep8 (in my repo, master branch) if you want to test external plugins.

@ccordoba12
Copy link
Member

Thanks a lot Joseph! We definitely need to move to normalize line endings!!

Could prepare a new PR about that? I promise to merge it and adapt all
our team PRs accordingly. Thanks :-)

El 08/06/16 a las 03:42, Joseph Martinot-Lagarde escribió:

OK, everything should work now ! I also updated spyder.line_profiler
and spyder.autopep8 (in my repo, master branch) if you want to test
external plugins.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#3210 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAWS7U63N7oqKJlSbvRW2L0WqUFuIST0ks5qJoCIgaJpZM4IwJmR.

@Nodd
Copy link
Contributor Author

Nodd commented Jun 8, 2016

line_profiler (the plugin) is still buggy, I ported memory_profiler but it's buggy too. You can test the vim plugin, I just did some work on it.

@Nodd Nodd changed the title [WIP] flask plugin model PR: flask plugin model Jun 9, 2016
@ccordoba12 ccordoba12 modified the milestones: v3.0rc1, v3.0beta4 Jun 9, 2016
@Nodd
Copy link
Contributor Author

Nodd commented Jun 9, 2016

I did some cleanups in the plugins, they should all work now. You have to use the versions from https://github.com/Nodd?tab=repositories, I'll push to spyder-ide when this PR is merged.

@Nodd
Copy link
Contributor Author

Nodd commented Jun 9, 2016

... and I'm slowly starting to hate QuantifiedCode. I like nice-looking code, but this thing is so mechanical that the few useful warnings are lost in the noise.
On this specific PR it should detect when the files are moved around and not modified.

@ccordoba12 ccordoba12 changed the title PR: flask plugin model PR: Follow the Flask plugin model instead of namespace packages Jun 9, 2016
@ccordoba12
Copy link
Member

@Nodd, is this one ready?

I think the only thing left is to fix setup.py to package the new spyder_* directories instead of spyplugins, but I can do that after merging this one.

@Nodd
Copy link
Contributor Author

Nodd commented Jun 9, 2016

I updated the gettext scripts and setup.py (without testing the changes...). Otherwise it should be ready, I don't know if someone tested on another configuration than my machine.

loads its submodules."""
namespace_path = osp.join(plugin_path, base_namespace, plugins_namespace)
PLUGIN_PREFIX = "spyder_"
IO_PREFIX = PLUGIN_PREFIX + "io_"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question here: What's the name for io plugins according to this? Is it spyder_io_foo or spyderio_foo?

I say that because you named our io plugins like spyderio_foo, so those names or this line should be changed :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spyder_io_foo. I forgot to rename the files.

'spyder_profiler': get_package_data('spyder_profiler', EXTLIST),
'spyder_pylint': get_package_data('spyder_pylint', EXTLIST),
'spyderio_dcm': get_package_data('spyderio_dcm', EXTLIST),
'spyderio_hdf5': get_package_data('spyderio_hdf5', EXTLIST),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nodd, these lines also need to be changed to spyder_io_foo :-)

@ccordoba12
Copy link
Member

Except for a minor detail in setup.py this one is ready to go.

@Nodd
Copy link
Contributor Author

Nodd commented Jun 10, 2016

Stupid me, I modified setup.py before renaming the files.
The travis failure seems like a bug in qtpy with Qt5, it tries to import PySide instead

@ccordoba12
Copy link
Member

The problem in Travis had to do with new conda packages for PyQt5. They had the wrong dependencies, so I removed them for now :-)

I have to recompile Qt5 to fix that problem.

@ccordoba12 ccordoba12 merged commit e4959e5 into spyder-ide:master Jun 11, 2016
@Nodd
Copy link
Contributor Author

Nodd commented Jun 11, 2016

I updated the master branch of all "my" plugins in spyder-ide so that they are compatible. Note that it's not the case for spyder.example ! (and spyder.terminado but this one is empty)

@TWAC
Copy link

TWAC commented Jul 12, 2016

After this merge I am not getting plugins from bdist_wheel.
It looks like get_packages() in setup.py still looks for the spyplugins directory.

@Nodd Nodd deleted the flask_plugin_model branch July 18, 2016 13:11
@Nodd
Copy link
Contributor Author

Nodd commented Jul 18, 2016

@TWAC You're right, thank you for noticing. I sent a PR to correct this.

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.

Fix external plugins import
4 participants