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

Handle app factory in FLASK_APP #2264

Closed
davidism opened this issue May 1, 2017 · 9 comments
Closed

Handle app factory in FLASK_APP #2264

davidism opened this issue May 1, 2017 · 9 comments
Labels

Comments

@davidism
Copy link
Member

davidism commented May 1, 2017

FLASK_APP=myproject.app:create_app('dev')

Gunicorn does this with eval
, which I'm not super happy with. Instead, we could use literal_eval to allow a simple list of arguments. The line should never be so complicated that eval would be necessary anyway.

# might need to fix this regex
m = re.search(r'(\w+)(\(.*\))', app_obj)

if m:
    app = getattr(mod, m.group(1))(*literal_eval(m.group(2)))
@davidism davidism added the cli label May 1, 2017
@wgwz
Copy link
Contributor

wgwz commented May 1, 2017

Should be re.search instead of re.match, right?

@davidism
Copy link
Member Author

davidism commented May 23, 2017

Also handle myproject.app:create_app without parens.

literal_eval("('dev')") evaluates to a string, not a tuple, so need to special case one positional arg, probably by adding a comma at the end. Need to check that it's not empty parens though, because then inserting is a syntax error.

This solution only allows positional arguments (and named script_info argument implicitly), but I'm ok with not supporting keyword arguments.

@lepture
Copy link
Contributor

lepture commented May 24, 2017

Down vote on this feature.

The environ FLASK_ENV=dev way would be better.

@ThiefMaster
Copy link
Member

ThiefMaster commented May 24, 2017

Something like FLASK_ENV would not belong into the core of a microframework like Flask. You don't necessarily have multiple configs available - actually, if you want to be able to specify which config to use I'd just use app.config.from_envvar('MYAPP_CONFIG').

I'm ±0 on this issue: It does make FLASK_APP more flexible, but on the other hand always calling the app factory with no arguments - which. in my opinion, should use the most common default values - keeps things nice and simple.

@lepture
Copy link
Contributor

lepture commented May 24, 2017

@ThiefMaster Actually I don't use FLASK_ENV either. The FLASK_ENV way is a suggested replacement for this issue.

I've always been using the MYAPP_CONF=/path/to/conf.py to bootstrap the flask app.

kennethreitz added a commit that referenced this issue May 25, 2017
…ASK_APP

Handle app factory with arguments in FLASK_APP
@Kamekameha
Copy link

I'm not that fond either with such flexibility in FLASK_APP, a simple call with no arguments to the application factory might be enough, IMO. By looking at the deployment options in the docs we may need to write our own wsgi.py (or something similar) application file for a handful of cases anyway.

@kennethreitz
Copy link
Contributor

I merged a pull request yesterday which provides this functionality

@kennethreitz
Copy link
Contributor

The PR looked good to me, and from what I could tell, this was @davidism's plan for the project, so I went ahead with it. Leaving this ticket open for further discussion, if any is needed.

@davidism
Copy link
Member Author

davidism commented May 28, 2017

I really like the shortcut of being able to call the factory in uWSGI and Gunicorn config. I think the ease of setup outweighs the complexity here. If users want to use env vars instead, that's fine and should probably be documented as an alternative.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants