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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ 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.


- The following old deprecated code was removed. (`#2385`_)

- ``flask.ext`` - import extensions directly by their name instead of
Expand Down Expand Up @@ -123,6 +126,7 @@ Major release, unreleased
.. _#2362: https://github.com/pallets/flask/pull/2362
.. _#2374: https://github.com/pallets/flask/pull/2374
.. _#2373: https://github.com/pallets/flask/pull/2373
.. _#2383: https://github.com/pallets/flask/pull/2383
.. _#2385: https://github.com/pallets/flask/issues/2385

Version 0.12.2
Expand Down
15 changes: 13 additions & 2 deletions flask/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ def prepare_exec_for_file(filename):

return '.'.join(module[::-1])

def prepare_exec_for_dir(dirpath):
"""Given a directory this will put the parent directory on the python path
and return the directory name. Used for when FLASK_APP is a module that
contains an app
"""
sys.path.append(os.path.join(dirpath, os.pardir))
return os.path.basename(dirpath)


def locate_app(script_info, app_id, raise_if_not_found=True):
"""Attempts to locate the application."""
Expand Down Expand Up @@ -223,8 +231,11 @@ def find_default_import_path():
app = os.environ.get('FLASK_APP')
if app is None:
return
if os.path.isfile(app):
return prepare_exec_for_file(app)
if os.path.isdir(app):
return prepare_exec_for_dir(app)
for path in [app, app + '.py']:
if os.path.isfile(path):
return prepare_exec_for_file(path)
return app


Expand Down