sh4nks / flask-plugins

This extension provides an easy way to create plugins for your flask application.
http://flask-plugins.readthedocs.org/en/latest/
Other
52 stars 21 forks source link

Suggestions/Feedback #3

Open sh4nks opened 10 years ago

sh4nks commented 10 years ago

Hey, I would love to hear some opinions about this extension. Is there anything that could be done better? If so, what and how would you do it? Thanks in advance! :)

fredericmohr commented 9 years ago

Nice job, love the plugins extension :)

Two things I stumbled across. First, if you disable the plugins by creating a DISABLED file in the plugin folder the app server has to be restarted. I couldn't find a way to do that from within the application, so that I can enable and disable (and restart the server) from an admin panel.

In the example plugins code is a enable_plugin and disable_plugin feature, which didn't work for me (see https://github.com/sh4nks/flask-plugins/issues/11) and I couldn't find anything about disabling/enabling plugins in the docs besides creating the file.

Second, getting the current state of a plugin (enabled/disable) and a list of all enabled and all disabled plugins would be a great additional feature. This would make it much easier to create a clean admin panel for adding/removing or en/disabling plugins from within the application.

sh4nks commented 9 years ago

Thanks!

I know this annoys me a lot and I would love to get rid of it but Flask has to be restarted if, for example, your plugin registers a blueprint (it is not possible to register a blueprint at runtime). I may have another look on this thing later or do you know how to reload stuff in python? I have implemented methods for enabling/disabling a plugin directly in websites. (https://github.com/sh4nks/flaskbb/blob/master/flaskbb/management/views.py#L457-L544) Feel free to copy/use it :)

To get a list of all enabled plugins you can use this get_plugins_list and for all plugins this get_all_plugins (it includes the disabled and enabled ones). You can also use one of these 2 functions if you just need to get a specific plugin: get_plugin - this will return a plugin instance from the enabled plugins and get_plugin_from_all will return a plugin instance from all plugins (includes also the disabled ones).

I'm gonna put this in the docs after New Year :)

I hope this helps a bit.

Seraf commented 9 years ago

Hello @sh4nks, I was thinking about stevedore as plugin manager. My idea was to use entry_points and do kind of dynamic routing by redirecting all unknown routes to stevedore and let stevedore loop on plugins. Don't know how is it doable or not ?

A guy already done a part of this job but only playing with entry_points : https://copyninja.info/blog/entry_point_wsme.rst.html

As stevedore is mainly used on OpenStack, I guess it could be a good thing to rely on and just focus on integration with Flask. What do you think about it ?

Thanks for your work

sh4nks commented 9 years ago

I have never played with the entry_points but I guess that this could be done by rewriting those 2 methods: https://github.com/sh4nks/flask-plugins/blob/master/flask_plugins/__init__.py#L209-L270 It would be cool to have both options available. So that one can either just drop their plugins in the plugins folder or install it via pip.

I really appreciate it that my work helps. btw, I am also accepting pull request if you want to add this ;)

J4Chard commented 4 years ago

Hi @sh4nks - I just submitted an issue but wanted to balance it out with feedback: this extension is exactly what I need for my project, so thanks for writing it and making it available! I'm extremely glad you already invented this 'wheel', so I don't need to reinvent it.