From 8eb9cdf6ca2e8a2a5751a5a88ca107729a54d1b3 Mon Sep 17 00:00:00 2001 From: Gordon Shotwell Date: Wed, 11 Oct 2023 13:17:58 -0300 Subject: [PATCH 1/9] Pass kwargs from run_app to uvicorn --- shiny/_main.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/shiny/_main.py b/shiny/_main.py index ae52ac963..df6d05258 100644 --- a/shiny/_main.py +++ b/shiny/_main.py @@ -146,6 +146,7 @@ def run( app_dir: str, factory: bool, launch_browser: bool, + **kwargs, ) -> None: reload_includes_list = reload_includes.split(",") return run_app( @@ -161,6 +162,7 @@ def run( app_dir=app_dir, factory=factory, launch_browser=launch_browser, + **kwargs, ) @@ -177,6 +179,7 @@ def run_app( app_dir: Optional[str] = ".", factory: bool = False, launch_browser: bool = False, + **kwargs, ) -> None: """ Starts a Shiny app. Press ``Ctrl+C`` (or ``Ctrl+Break`` on Windows) to stop. @@ -217,6 +220,9 @@ def run_app( Treat ``app`` as an application factory, i.e. a () -> callable. launch_browser Launch app browser after app starts, using the Python webbrowser module. + **kwargs + Additional keyword arguments which are passed to ``uvicorn.run``. For more + information see ` Tip --- @@ -312,6 +318,7 @@ def run_app( app_dir=app_dir, factory=factory, **reload_args, + **kwargs, ) From 0c6f5f60c143de8d2c9fdec907f1fa407229f849 Mon Sep 17 00:00:00 2001 From: Gordon Shotwell Date: Mon, 16 Oct 2023 09:56:22 -0300 Subject: [PATCH 2/9] Add reload_excludes argument to shiny run. --- shiny/_main.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/shiny/_main.py b/shiny/_main.py index df6d05258..c748e0568 100644 --- a/shiny/_main.py +++ b/shiny/_main.py @@ -11,7 +11,7 @@ import sys import types from pathlib import Path -from typing import Any, Optional +from typing import Any, Dict, Optional import click import uvicorn @@ -31,6 +31,7 @@ def main() -> None: stop_shortcut = "Ctrl+C" RELOAD_INCLUDES_DEFAULT = ("*.py", "*.css", "*.js", "*.htm", "*.html", "*.png") +RELOAD_EXCLUDES_DEFAULT = (".*", "*.py[cod]", "__pycache__", "env", "venv") @main.command( @@ -95,6 +96,13 @@ def main() -> None: help="File glob(s) to indicate which files should be monitored for changes. Defaults" f' to "{",".join(RELOAD_INCLUDES_DEFAULT)}".', ) +@click.option( + "--reload-excldues", + "reload_excludes", + default=",".join(RELOAD_INCLUDES_DEFAULT), + help="File glob(s) to indicate which files should be excluded from file monitoring. Defaults" + f' to "{",".join(RELOAD_INCLUDES_DEFAULT)}".', +) @click.option( "--ws-max-size", type=int, @@ -141,14 +149,16 @@ def run( reload: bool, reload_dirs: tuple[str, ...], reload_includes: str, + reload_excludes: str, ws_max_size: int, log_level: str, app_dir: str, factory: bool, launch_browser: bool, - **kwargs, + **kwargs: Dict[str, Any], ) -> None: reload_includes_list = reload_includes.split(",") + reload_excludes_list = reload_excludes.split(",") return run_app( app, host=host, @@ -157,6 +167,7 @@ def run( reload=reload, reload_dirs=list(reload_dirs), reload_includes=reload_includes_list, + reload_excludes=reload_excludes_list, ws_max_size=ws_max_size, log_level=log_level, app_dir=app_dir, @@ -174,12 +185,13 @@ def run_app( reload: bool = False, reload_dirs: Optional[list[str]] = None, reload_includes: list[str] | tuple[str, ...] = RELOAD_INCLUDES_DEFAULT, + reload_excludes: list[str] | tuple[str, ...] = RELOAD_EXCLUDES_DEFAULT, ws_max_size: int = 16777216, log_level: Optional[str] = None, app_dir: Optional[str] = ".", factory: bool = False, launch_browser: bool = False, - **kwargs, + **kwargs: Dict[str, Any], ) -> None: """ Starts a Shiny app. Press ``Ctrl+C`` (or ``Ctrl+Break`` on Windows) to stop. @@ -210,6 +222,9 @@ def run_app( reload_includes List or tuple of file globs to indicate which files should be monitored for changes. + reload_excludes + List or tuple of file globas to indicate which files should be excluded from + reload monitoring. Can be combined with `reload_includes` ws_max_size WebSocket max size message in bytes. log_level @@ -222,7 +237,7 @@ def run_app( Launch app browser after app starts, using the Python webbrowser module. **kwargs Additional keyword arguments which are passed to ``uvicorn.run``. For more - information see ` + information see [Uvicorn documentation](https://www.uvicorn.org/). Tip --- From e1f5e3e88d4d643fe61f6ec6b6d146e9e8f1098d Mon Sep 17 00:00:00 2001 From: Gordon Shotwell Date: Mon, 23 Oct 2023 14:48:50 -0300 Subject: [PATCH 3/9] Allow user to set reload dirs --- shiny/_main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/shiny/_main.py b/shiny/_main.py index c748e0568..3cc905dea 100644 --- a/shiny/_main.py +++ b/shiny/_main.py @@ -282,6 +282,8 @@ def run_app( if reload_dirs is None: reload_dirs = [] + if app_dir is not None: + reload_dirs = [app_dir] if reload: # Always watch the app_dir @@ -305,10 +307,6 @@ def run_app( reload_args: ReloadArgs = {} if reload: - reload_dirs = [] - if app_dir is not None: - reload_dirs = [app_dir] - reload_args = { "reload": reload, # Adding `reload_includes` param while `reload=False` produces an warning From 7323bf19dde3036b728e17d68c7af99eac303d6c Mon Sep 17 00:00:00 2001 From: Gordon Shotwell Date: Tue, 24 Oct 2023 14:13:12 -0300 Subject: [PATCH 4/9] Typo --- shiny/_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shiny/_main.py b/shiny/_main.py index 3cc905dea..ef6ba58f6 100644 --- a/shiny/_main.py +++ b/shiny/_main.py @@ -97,7 +97,7 @@ def main() -> None: f' to "{",".join(RELOAD_INCLUDES_DEFAULT)}".', ) @click.option( - "--reload-excldues", + "--reload-excludes", "reload_excludes", default=",".join(RELOAD_INCLUDES_DEFAULT), help="File glob(s) to indicate which files should be excluded from file monitoring. Defaults" @@ -312,7 +312,7 @@ def run_app( # Adding `reload_includes` param while `reload=False` produces an warning # https://github.com/encode/uvicorn/blob/d43afed1cfa018a85c83094da8a2dd29f656d676/uvicorn/config.py#L298-L304 "reload_includes": list(reload_includes), - "reload_excludes": [".*", "*.py[cod]", "__pycache__", "env", "venv"], + "reload_excludes": list(reload_excludes), "reload_dirs": reload_dirs, } From 8f79781d3c6e37c7be41476dbfe9d031d5b9a8dd Mon Sep 17 00:00:00 2001 From: Gordon Shotwell Date: Wed, 25 Oct 2023 10:22:10 -0300 Subject: [PATCH 5/9] Apply suggestions from code review Co-authored-by: Barret Schloerke --- shiny/_main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shiny/_main.py b/shiny/_main.py index ef6ba58f6..b86bf3586 100644 --- a/shiny/_main.py +++ b/shiny/_main.py @@ -99,9 +99,9 @@ def main() -> None: @click.option( "--reload-excludes", "reload_excludes", - default=",".join(RELOAD_INCLUDES_DEFAULT), + default=",".join(RELOAD_EXCLUDES_DEFAULT), help="File glob(s) to indicate which files should be excluded from file monitoring. Defaults" - f' to "{",".join(RELOAD_INCLUDES_DEFAULT)}".', + f' to "{",".join(RELOAD_EXCLUDES_DEFAULT)}".', ) @click.option( "--ws-max-size", @@ -155,7 +155,7 @@ def run( app_dir: str, factory: bool, launch_browser: bool, - **kwargs: Dict[str, Any], + **kwargs: object, ) -> None: reload_includes_list = reload_includes.split(",") reload_excludes_list = reload_excludes.split(",") @@ -191,7 +191,7 @@ def run_app( app_dir: Optional[str] = ".", factory: bool = False, launch_browser: bool = False, - **kwargs: Dict[str, Any], + **kwargs: object, ) -> None: """ Starts a Shiny app. Press ``Ctrl+C`` (or ``Ctrl+Break`` on Windows) to stop. @@ -221,7 +221,7 @@ def run_app( will trigger app reloading. reload_includes List or tuple of file globs to indicate which files should be monitored for - changes. + changes. Can be combined with `reload_excludes`. reload_excludes List or tuple of file globas to indicate which files should be excluded from reload monitoring. Can be combined with `reload_includes` From 0d02bf5fc14b2cabee52198f8e2348845abbd04c Mon Sep 17 00:00:00 2001 From: Gordon Shotwell Date: Wed, 25 Oct 2023 10:27:42 -0300 Subject: [PATCH 6/9] PR review changes --- shiny/_main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shiny/_main.py b/shiny/_main.py index b86bf3586..e3482c9e1 100644 --- a/shiny/_main.py +++ b/shiny/_main.py @@ -163,6 +163,7 @@ def run( app, host=host, port=port, + **kwargs, autoreload_port=autoreload_port, reload=reload, reload_dirs=list(reload_dirs), @@ -173,7 +174,6 @@ def run( app_dir=app_dir, factory=factory, launch_browser=launch_browser, - **kwargs, ) @@ -223,7 +223,7 @@ def run_app( List or tuple of file globs to indicate which files should be monitored for changes. Can be combined with `reload_excludes`. reload_excludes - List or tuple of file globas to indicate which files should be excluded from + List or tuple of file globs to indicate which files should be excluded from reload monitoring. Can be combined with `reload_includes` ws_max_size WebSocket max size message in bytes. @@ -287,7 +287,7 @@ def run_app( if reload: # Always watch the app_dir - if app_dir: + if app_dir and app_dir not in reload_dirs: reload_dirs.append(app_dir) # For developers of Shiny itself; autoreload the app when Shiny package changes if os.getenv("SHINY_PKG_AUTORELOAD"): From e97fdf5b383721267dc4170c6589936ea7b73c4c Mon Sep 17 00:00:00 2001 From: Gordon Shotwell Date: Wed, 25 Oct 2023 10:45:56 -0300 Subject: [PATCH 7/9] Linting --- CHANGELOG.md | 6 +++++- shiny/_main.py | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf20f203c..5e9d8c860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [UNRELEASED] ### New features - +* `shiny run` now takes `reload-includes` and `reload-excludes` to allow you to define which files trigger a reload. +* `shiny.run` now passes keyword arguments to `uvicorn.run` * The `@output` decorator is no longer required for rendering functions; `@render.xxx` decorators now register themselves automatically. You can still use `@output` explicitly if you need to set specific output options (#747). * Added support for integration with Quarto (#746). * Added `shiny.render.renderer_components` decorator to help create new output renderers (#621). @@ -59,6 +60,9 @@ Methods still under consideration in `shiny.experimental.ui`: * `card(wrapper=)`, `card_body()`, `card_image()`, `card_header()` +### Bug fixes +* `shiny run` now respects the user provided `reload-dir` argument (#765) + #### API removals * `shiny.experimental.ui.FillingLayout` has been removed. (#481) diff --git a/shiny/_main.py b/shiny/_main.py index e3482c9e1..fc4c4443c 100644 --- a/shiny/_main.py +++ b/shiny/_main.py @@ -11,7 +11,7 @@ import sys import types from pathlib import Path -from typing import Any, Dict, Optional +from typing import Any, Optional import click import uvicorn @@ -145,6 +145,7 @@ def run( app: str | shiny.App, host: str, port: int, + *, autoreload_port: int, reload: bool, reload_dirs: tuple[str, ...], @@ -163,7 +164,6 @@ def run( app, host=host, port=port, - **kwargs, autoreload_port=autoreload_port, reload=reload, reload_dirs=list(reload_dirs), @@ -174,6 +174,7 @@ def run( app_dir=app_dir, factory=factory, launch_browser=launch_browser, + **kwargs, ) @@ -181,6 +182,7 @@ def run_app( app: str | shiny.App = "app:app", host: str = "127.0.0.1", port: int = 8000, + *, autoreload_port: int = 0, reload: bool = False, reload_dirs: Optional[list[str]] = None, From b5f07d5f86b230c9a82b460b360bea0d689a92e2 Mon Sep 17 00:00:00 2001 From: Gordon Shotwell Date: Thu, 26 Oct 2023 10:18:03 -0300 Subject: [PATCH 8/9] Apply suggestions from code review Co-authored-by: Barret Schloerke --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e9d8c860..b6d86c8f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [UNRELEASED] ### New features -* `shiny run` now takes `reload-includes` and `reload-excludes` to allow you to define which files trigger a reload. -* `shiny.run` now passes keyword arguments to `uvicorn.run` +* `shiny run` now takes `reload-includes` and `reload-excludes` to allow you to define which files trigger a reload (#780). +* `shiny.run` now passes keyword arguments to `uvicorn.run` (#780). * The `@output` decorator is no longer required for rendering functions; `@render.xxx` decorators now register themselves automatically. You can still use `@output` explicitly if you need to set specific output options (#747). * Added support for integration with Quarto (#746). * Added `shiny.render.renderer_components` decorator to help create new output renderers (#621). @@ -61,7 +61,7 @@ Methods still under consideration in `shiny.experimental.ui`: ### Bug fixes -* `shiny run` now respects the user provided `reload-dir` argument (#765) +* `shiny run` now respects the user provided `reload-dir` argument (#765). #### API removals From e97c135d229926cba8fb4e933a1259a48dcbd93d Mon Sep 17 00:00:00 2001 From: Gordon Shotwell Date: Thu, 26 Oct 2023 10:20:30 -0300 Subject: [PATCH 9/9] Update changelog with breaking changes --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6d86c8f0..e3f296768 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,9 @@ Methods still under consideration in `shiny.experimental.ui`: ### Other changes +### Breaking Changes +* `shiny.run` only allows positional arguments for `app`, `host`, and `port`, all other arguments must be specified with keywords. + ## [0.5.1] - 2023-08-08