Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions shiny/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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-excludes",
"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,
Expand Down Expand Up @@ -141,13 +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: Dict[str, Any],
) -> None:
reload_includes_list = reload_includes.split(",")
reload_excludes_list = reload_excludes.split(",")
return run_app(
app,
host=host,
Expand All @@ -156,11 +167,13 @@ 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,
factory=factory,
launch_browser=launch_browser,
**kwargs,
)


Expand All @@ -172,11 +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: Dict[str, Any],
) -> None:
"""
Starts a Shiny app. Press ``Ctrl+C`` (or ``Ctrl+Break`` on Windows) to stop.
Expand Down Expand Up @@ -207,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
Expand All @@ -217,6 +235,9 @@ def run_app(
Treat ``app`` as an application factory, i.e. a () -> <ASGI app> 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 [Uvicorn documentation](https://www.uvicorn.org/).

Tip
---
Expand Down Expand Up @@ -261,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
Expand All @@ -284,16 +307,12 @@ 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
# 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,
}

Expand All @@ -312,6 +331,7 @@ def run_app(
app_dir=app_dir,
factory=factory,
**reload_args,
**kwargs,
)


Expand Down