Merge pull request #2898 from rochacbruno/2897-Add-Extra-Files-to-CLI
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix #2897 - Add `extra_files` option to `flask run` CLI
authored by David Lord · committed by GitHub · parents 4fe81d7, e18cc4d · Browse files · 3 files·+47 added−2 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−2 removed
- other:+47 added−2 removed
Provenance
- Commit
2616d97- Tree
d4c66d9- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
4fe81d7- Parent 2
e18cc4d
3 files changed+47 added−2 removed
modified:docs/cli.rst+19 added
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``,316 unmodified linesmodified:flask/cli.py+25 added-1 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 )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_info782-def run_command(info, host, port, reload, debugger, eager_loading, with_threads, cert):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,838+ 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-1 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/299430 unmodified lines89 .. _#2900: https://github.com/pallets/flask/issues/290090 .. _#2933: https://github.com/pallets/flask/issues/293391 .. _#2986: https://github.com/pallets/flask/pull/298692 90-93 Version 1.0.294 -------------95 96 Released 2018-05-02909 unmodified lines