Added support for a FLASK_RUN_EXTRA_FILES config variable.

Similar to the `flask run --extra_files=..` CLI argument or the `FLASK_RUN_EXTRA_FILES` environment variable, this is another method to specify other files to watch.
This commit is contained in:
Grayden 2021-08-05 15:46:09 -04:00
parent 0826be48ed
commit 7daf197dd6
3 changed files with 19 additions and 0 deletions

View file

@ -184,12 +184,16 @@ reloader.
Watch Extra Files with the Reloader
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. versionadded:: 2.1
Support for the ``FLASK_RUN_EXTRA_FILES`` config variable was added.
When using development mode, the reloader will trigger whenever your
Python code or imported modules change. The reloader can watch
additional files with the ``--extra-files`` option, or the
``FLASK_RUN_EXTRA_FILES`` environment variable. Multiple paths are
separated with ``:``, or ``;`` on Windows.
.. tabs::
.. group-tab:: Bash
@ -226,6 +230,15 @@ separated with ``:``, or ``;`` on Windows.
* Detected change in '/path/to/file1', reloading
Alternatively, you can set the ``FLASK_RUN_EXTRA_FILES`` config
variable, which takes a list of files::
from flask import Flask
app = Flask(__name__)
app.config['FLASK_RUN_EXTRA_FILES'] = ["file1", "dirA/file2", "dirB/"]
Debug Mode
----------

View file

@ -914,6 +914,7 @@ class Flask(Scaffold):
options.setdefault("use_reloader", self.debug)
options.setdefault("use_debugger", self.debug)
options.setdefault("threaded", True)
options.setdefault("extra_files", self.config.get("FLASK_RUN_EXTRA_FILES"))
cli.show_server_banner(self.env, self.debug, self.name, False)

View file

@ -841,6 +841,11 @@ def run_command(
if debugger is None:
debugger = debug
# Override extra_files argument with config variable if specified
app = info.load_app()
if app.config.get("FLASK_RUN_EXTRA_FILES"):
extra_files = app.config.get("FLASK_RUN_EXTRA_FILES")
show_server_banner(get_env(), debug, info.app_import_path, eager_loading)
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)