Browse Source

#2377: Don't require FLASK_APP to have .py extension

pull/2383/head
Benjamin Congdon 8 years ago
parent
commit
3c049ad734
No known key found for this signature in database
GPG Key ID: 148FEE4C2C805D4A
  1. 3
      CHANGES
  2. 15
      flask/cli.py

3
CHANGES

@ -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
@ -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
--------------

15
flask/cli.py

@ -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."""
@ -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

Loading…
Cancel
Save