Skip to content
Myr

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

3 files+47 added−23 removed

modified:docs/cli.rst+19 added-14 removed
144 unmodified lines
145 * Debugger is active!146 * Debugger PIN: 223-456-919147148149Watch Extra Files with the Reloader150~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~151152When using development mode, the reloader will trigger whenever your153Python code or imported modules change. The reloader can watch154additional files with the ``--extra-files`` option, or the155``FLASK_RUN_EXTRA_FILES`` environment variable. Multiple paths are156separated with ``:``, or ``;`` on Windows.157158.. code-block:: none159160 $ 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', reloading166167168Debug Mode169----------170171Debug mode will be enabled when :envvar:`FLASK_ENV` is ``development``,
48 unmodified lines
220221These can be added to the ``.flaskenv`` file just like ``FLASK_APP`` to222control default command options.223205To define a list of files the reloader should watch additionally to the modules206as in ``extra_files`` argument used in the ``app.run`` and ``werkzeug.serving.run_simple``207you can either use the ``--extra-files`` (or multiple ``-f``) option or define the208``FLASK_RUN_EXTRA_FILES`` environment variable.224210.. code-block:: none211212 # 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', reloading217218On command line the same can be achieved with ``flask run -f /path/to/file1 -f /path/to/file2``.219225Disable dotenv226~~~~~~~~~~~~~~227228The ``flask`` command will show a message if it detects dotenv files but
259 unmodified lines
modified:flask/cli.py+25 added-6 removed
740 unmodified lines
741742 return value743744745class 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 """750751 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]755756757@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 lines
789 "--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_info785def run_command(info, host, port, reload, debugger, eager_loading,786 with_threads, cert, extra_files):803def run_command(804 info, host, port, reload, debugger, eager_loading, with_threads, cert, extra_files805):806 """Run a local development server.807808 This server is for development purposes only. It does not provide809 the stability, security, or performance of production WSGI servers.
24 unmodified lines
834 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 )840841842@click.command("shell", short_help="Run a shell in the app context.")
106 unmodified lines
modified:CHANGES.rst+3 added-3 removed
47 unmodified lines
48 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`5556.. _#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/31256260- Added support to ``extra_files`` argument in `flask run` CLI. (`#2898`_)6362.. _#2898: https://github.com/pallets/flask/pull/28986364Version 1.0.365-------------6667Released 2019-05-17
938 unmodified lines