Skip to content

Commit

Permalink
#2377: Don't require FLASK_APP to have .py extension
Browse files Browse the repository at this point in the history
  • Loading branch information
bcongdon committed Jun 25, 2017
1 parent 45c8fb3 commit 3c049ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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`_)

.. _#1489: https://github.com/pallets/flask/pull/1489
.. _#1621: https://github.com/pallets/flask/pull/1621
Expand All @@ -107,6 +109,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

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 @@ -222,8 +230,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

0 comments on commit 3c049ad

Please sign in to comment.