From 7daf197dd602db0ced5b9d6fc16bcfa308528cac Mon Sep 17 00:00:00 2001 From: Grayden Date: Thu, 5 Aug 2021 15:46:09 -0400 Subject: [PATCH] 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. --- docs/cli.rst | 13 +++++++++++++ src/flask/app.py | 1 + src/flask/cli.py | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/docs/cli.rst b/docs/cli.rst index 6036cb2d..4d383fbb 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -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 ---------- diff --git a/src/flask/app.py b/src/flask/app.py index 8c3c39d4..5dcabeb8 100644 --- a/src/flask/app.py +++ b/src/flask/app.py @@ -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) diff --git a/src/flask/cli.py b/src/flask/cli.py index d9e810da..a278bad5 100644 --- a/src/flask/cli.py +++ b/src/flask/cli.py @@ -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)