You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
flask-script should support init_app() pattern #122
It would be really handy instead of requiring the flask "App" object at manager creation time, if this could be deferred until later, by using the init_app() pattern.
The basic would be any add_* command, or something which registers would check if self.app is None, and if it is, you add it to a list. Then manager.init_app(app) would go through each list and actually do the registration.
I don't think flask-script should do that. The init_app pattern comes in handy for extensions, but does not make any sense for an application that takes such an external role.
The steps
Create a Flask() object
Register all extensions using ext.init_app()
Run the app and benefit from the functionality of the extension (e.g. Babel)
Step three is definitely not the use case of flask_script: The most you do is to callapp.run() to provide a run function providing a certain setup, but you never provide anything that needs to be accessible at runtime.
flask_script is an external helper, but nothing which provides inside functionality to the running app.
If you are using the application factory pattern, most probably you will have this extension instantiated in a dedicated module. Just for this pattern, it is useful to be able to call the init_app method.
I'm with @lukasjuhrich on this one. Plus, overloading the init_app concept to mean either "initialize the given extention" or "initialize all extentions" would cause additional confusion for everybody, especially those new to flask-script.
A beginner to flask-script would probably get hung up trying to do something like this
which would be incorrect since the proposal is to have manager.init_app(app) calling every other init_app(app).
Please correct me if I've misunderstood the original intent behind this issue, this was how I interpreted it.
I also recently found out that you actually can, in fact, delay the creation of the app object until later, but not via the init_app pattern. This gist by smurfix describes how you can avoid the need to use an initialized app to create the Manager and make use of your already existing app factory (assuming your project is layed out such that there is one). The creation of a manager then becomes (taken from the gist snippet)
Activity
cescoferraro commentedon Apr 28, 2015
Pleaseee!
jbouzekri commentedon Nov 16, 2015
+1
jeffwidman commentedon Dec 7, 2015
👍
maangulo12 commentedon Jan 3, 2016
I would love to see this
+1
lukasjuhrich commentedon Feb 12, 2016
I don't think flask-script should do that. The
init_apppattern comes in handy for extensions, but does not make any sense for an application that takes such an external role.The steps
Flask()objectext.init_app()Step three is definitely not the use case of
flask_script: The most you do is to callapp.run()to provide a run function providing a certain setup, but you never provide anything that needs to be accessible at runtime.flask_scriptis an external helper, but nothing which provides inside functionality to the running app.jbouzekri commentedon Feb 12, 2016
If you are using the application factory pattern, most probably you will have this extension instantiated in a dedicated module. Just for this pattern, it is useful to be able to call the
init_appmethod.brookskindle commentedon Jun 1, 2016
I'm with @lukasjuhrich on this one. Plus, overloading the
init_appconcept to mean either "initialize the given extention" or "initialize all extentions" would cause additional confusion for everybody, especially those new to flask-script.A beginner to flask-script would probably get hung up trying to do something like this
which would be incorrect since the proposal is to have
manager.init_app(app)calling every otherinit_app(app).Please correct me if I've misunderstood the original intent behind this issue, this was how I interpreted it.
I also recently found out that you actually can, in fact, delay the creation of the
appobject until later, but not via theinit_apppattern. This gist by smurfix describes how you can avoid the need to use an initialized app to create the Manager and make use of your already existing app factory (assuming your project is layed out such that there is one). The creation of a manager then becomes (taken from the gist snippet)mercuryseries commentedon Jan 4, 2017
should do the trick