Merge pull request #2898 from rochacbruno/2897-Add-Extra-Files-to-CLI

Fix #2897 - Add `extra_files` option to `flask run` CLI
This commit is contained in:
David Lord 2019-05-24 07:32:45 -07:00 committed by GitHub
commit 2616d97f32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 2 deletions

View file

@ -49,6 +49,9 @@ Unreleased
not installed, or if the given path isn't a file. :issue:`2937`
- Signaling support has a stub for the ``connect_via`` method when
the Blinker library is not installed. :pr:`3208`
- Add an ``--extra-files`` option to the ``flask run`` CLI command to
specify extra files that will trigger the reloader on change.
:issue:`2897`
.. _#2935: https://github.com/pallets/flask/issues/2935
.. _#2957: https://github.com/pallets/flask/issues/2957
@ -87,7 +90,6 @@ Released 2019-05-17
.. _#2933: https://github.com/pallets/flask/issues/2933
.. _#2986: https://github.com/pallets/flask/pull/2986
Version 1.0.2
-------------

View file

@ -146,6 +146,25 @@ reloader.
* Debugger PIN: 223-456-919
Watch Extra Files with the Reloader
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
.. code-block:: none
$ flask run --extra-files file1:dirA/file2:dirB/
# or
$ export FLASK_RUN_EXTRA_FILES=file1:dirA/file2:dirB/
$ flask run
* Running on http://127.0.0.1:8000/
* Detected change in '/path/to/file1', reloading
Debug Mode
----------

View file

@ -742,6 +742,18 @@ def _validate_key(ctx, param, value):
return value
class SeparatedPathType(click.Path):
"""Click option type that accepts a list of values separated by the
OS's path separator (``:``, ``;`` on Windows). Each value is
validated as a :class:`click.Path` type.
"""
def convert(self, value, param, ctx):
items = self.split_envvar_value(value)
super_convert = super(SeparatedPathType, self).convert
return [super_convert(item, param, ctx) for item in items]
@click.command("run", short_help="Run a development server.")
@click.option("--host", "-h", default="127.0.0.1", help="The interface to bind to.")
@click.option("--port", "-p", default=5000, help="The port to bind to.")
@ -778,8 +790,19 @@ def _validate_key(ctx, param, value):
default=True,
help="Enable or disable multithreading.",
)
@click.option(
"--extra-files",
default=None,
type=SeparatedPathType(),
help=(
"Extra files that trigger a reload on change. Multiple paths"
" are separated by '{}'.".format(os.path.pathsep)
),
)
@pass_script_info
def run_command(info, host, port, reload, debugger, eager_loading, with_threads, cert):
def run_command(
info, host, port, reload, debugger, eager_loading, with_threads, cert, extra_files
):
"""Run a local development server.
This server is for development purposes only. It does not provide
@ -812,6 +835,7 @@ def run_command(info, host, port, reload, debugger, eager_loading, with_threads,
use_debugger=debugger,
threaded=with_threads,
ssl_context=cert,
extra_files=extra_files,
)