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

Don't require FLASK_APP to have .py extension #2383

Closed

Conversation

bcongdon
Copy link

Addresses #2377. The simplest way that I found to do this was to just patch the find_default_import_path method to check if there's a file with the .py extension.

Worked in all of my testing. 🙂

@bcongdon bcongdon force-pushed the feature/fix-flask-app-py-extension branch from b851684 to 0ccb5d3 Compare June 18, 2017 20:48
@davidism
Copy link
Member

Thanks! This is sort of the opposite direction of what I was imagining though. For example, a package that's not installed still requires FLASK_APP=myapp/__init__ when it should be importable as myapp because the current directory is on the PYTHONPATH.

@bcongdon bcongdon force-pushed the feature/fix-flask-app-py-extension branch 2 times, most recently from f04bf67 to fb437ce Compare June 18, 2017 21:43
@bcongdon
Copy link
Author

Ah, I see. I updated the method to append the sys path if the referenced FLASK_APP is a directory. That should cover both the case where FLASK_APP=myapp and FLASK_APP=/path/to/myapp (where myapp is a module that contains a Flask app)

@@ -82,6 +82,8 @@ Major release, unreleased
- Fix incorrect JSON encoding of aware, non-UTC datetimes. (`#2374`_)
- Template auto reloading will honor the ``run`` command's ``debug`` flag even
if ``app.jinja_env`` was already accessed. (`#2373`_)
- The ``flask`` command no longer requires that the ``FLASK_APP`` environment
variable have a ``.py`` extension. (`#2383`_)

This comment was marked as off-topic.

This comment was marked as off-topic.

flask/cli.py Outdated
for path in [app, app + '.py']:
if os.path.isfile(path):
return prepare_exec_for_file(path)
if os.path.isdir(app):

This comment was marked as off-topic.

@bcongdon bcongdon force-pushed the feature/fix-flask-app-py-extension branch from fb437ce to 3c049ad Compare June 25, 2017 15:14
@davidism
Copy link
Member

A friend pointed out that FLASK_APP=module flask run already works without the .py. So now I'm trying to figure out why that's importable but FLASK_APP=package isn't.

@pachewise
Copy link

@davidism wouldn't it hinge on os.path.isfile() behavior? In that case, don't see how FLASK_APP=module would work unless os.path doesn't care about file extensions...

@davidism
Copy link
Member

davidism commented Jun 27, 2017

Because the current directory is already inserted into sys.path.

@davidism
Copy link
Member

Thanks for working on this. I ended up fixing this in #2414 by dropping the .py requirement rather than handling directories differently.

@davidism davidism closed this Jul 15, 2017
@bcongdon bcongdon deleted the feature/fix-flask-app-py-extension branch July 15, 2017 04:01
@davidism davidism mentioned this pull request Jul 15, 2017
@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants