add SeparatedPathType to accept multiple paths
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Multiple paths for the reloader's `--extra-files` are accepted as one option, separated by ':'.
authored by David Lord · committed by David Lord · parent 2308cba · Browse files · 3 files·+47 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+47 added−23 removed
- other:+47 added−23 removed
Provenance
- Commit
e18cc4d- Tree
d4c66d9- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
2308cba
3 files changed+47 added−23 removed
modified:docs/cli.rst+19 added-14 removed
144 unmodified lines145 * Debugger is active!146 * Debugger PIN: 223-456-919147 148 149+Watch Extra Files with the Reloader150+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~151+152+When using development mode, the reloader will trigger whenever your153+Python code or imported modules change. The reloader can watch154+additional files with the ``--extra-files`` option, or the155+``FLASK_RUN_EXTRA_FILES`` environment variable. Multiple paths are156+separated with ``:``, or ``;`` on Windows.157+158+.. code-block:: none159+160+ $ flask run --extra-files file1:dirA/file2:dirB/161+ # or162+ $ export FLASK_RUN_EXTRA_FILES=file1:dirA/file2:dirB/163+ $ flask run164+ * Running on http://127.0.0.1:8000/165+ * Detected change in '/path/to/file1', reloading166+167+168 Debug Mode169 ----------170 171 Debug mode will be enabled when :envvar:`FLASK_ENV` is ``development``,48 unmodified lines220 221 These can be added to the ``.flaskenv`` file just like ``FLASK_APP`` to222 control default command options.223 205-To define a list of files the reloader should watch additionally to the modules206-as in ``extra_files`` argument used in the ``app.run`` and ``werkzeug.serving.run_simple``207-you can either use the ``--extra-files`` (or multiple ``-f``) option or define the208-``FLASK_RUN_EXTRA_FILES`` environment variable.224 210-.. code-block:: none211-212- # on windows use ``;`` instead of ``:`` to separate paths213- export FLASK_RUN_EXTRA_FILES=/path/to/file1:/path/to/file2214- flask run215- * Running on http://127.0.0.1:8000/216- * Detected change in '/path/to/file1', reloading217-218-On command line the same can be achieved with ``flask run -f /path/to/file1 -f /path/to/file2``.219-225 Disable dotenv226 ~~~~~~~~~~~~~~227 228 The ``flask`` command will show a message if it detects dotenv files but259 unmodified linesmodified:flask/cli.py+25 added-6 removed
740 unmodified lines741 742 return value743 744 745+class SeparatedPathType(click.Path):746+ """Click option type that accepts a list of values separated by the747+ OS's path separator (``:``, ``;`` on Windows). Each value is748+ validated as a :class:`click.Path` type.749+ """750+751+ def convert(self, value, param, ctx):752+ items = self.split_envvar_value(value)753+ super_convert = super(SeparatedPathType, self).convert754+ return [super_convert(item, param, ctx) for item in items]755+756+757 @click.command("run", short_help="Run a development server.")758 @click.option("--host", "-h", default="127.0.0.1", help="The interface to bind to.")759 @click.option("--port", "-p", default=5000, help="The port to bind to.")760 @click.option(28 unmodified lines789 "--with-threads/--without-threads",790 default=True,791 help="Enable or disable multithreading.",792 )781-@click.option('--extra-files', '-f',782- multiple=True, default=None, type=click.Path(),783- help='Files reloader should watch additionally to the modules')793+@click.option(794+ "--extra-files",795+ default=None,796+ type=SeparatedPathType(),797+ help=(798+ "Extra files that trigger a reload on change. Multiple paths"799+ " are separated by '{}'.".format(os.path.pathsep)800+ ),801+)802 @pass_script_info785-def run_command(info, host, port, reload, debugger, eager_loading,786- with_threads, cert, extra_files):803+def run_command(804+ info, host, port, reload, debugger, eager_loading, with_threads, cert, extra_files805+):806 """Run a local development server.807 808 This server is for development purposes only. It does not provide809 the stability, security, or performance of production WSGI servers.24 unmodified lines834 use_reloader=reload,835 use_debugger=debugger,836 threaded=with_threads,837 ssl_context=cert,819- extra_files=extra_files838+ extra_files=extra_files,839 )840 841 842 @click.command("shell", short_help="Run a shell in the app context.")106 unmodified linesmodified:CHANGES.rst+3 added-3 removed
47 unmodified lines48 with the documentation. It will return ``False`` if python-dotenv is49 not installed, or if the given path isn't a file. :issue:`2937`50 - Signaling support has a stub for the ``connect_via`` method when51 the Blinker library is not installed. :pr:`3208`52+- Add an ``--extra-files`` option to the ``flask run`` CLI command to53+ specify extra files that will trigger the reloader on change.54+ :issue:`2897`55 56 .. _#2935: https://github.com/pallets/flask/issues/293557 .. _#2957: https://github.com/pallets/flask/issues/295758 .. _#2994: https://github.com/pallets/flask/pull/299459 .. _#3059: https://github.com/pallets/flask/pull/305960 .. _#3179: https://github.com/pallets/flask/pull/317961 .. _#3125: https://github.com/pallets/flask/pull/312562 60-- Added support to ``extra_files`` argument in `flask run` CLI. (`#2898`_)63 62-.. _#2898: https://github.com/pallets/flask/pull/289863-64 Version 1.0.365 -------------66 67 Released 2019-05-17938 unmodified lines