From 6ebf7d43a92b69940b55acff2ea4d0e7d156b406 Mon Sep 17 00:00:00 2001 From: "Joel Young [Jooser PC]" Date: Fri, 28 Feb 2025 11:13:16 -0600 Subject: [PATCH 1/2] Added passthrough for reload_dir option to uvicorn --- src/fastapi_cli/cli.py | 9 +++++++++ tests/test_cli.py | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/fastapi_cli/cli.py b/src/fastapi_cli/cli.py index c983b5c..697903c 100644 --- a/src/fastapi_cli/cli.py +++ b/src/fastapi_cli/cli.py @@ -86,6 +86,7 @@ def _run( command: str, app: Union[str, None] = None, proxy_headers: bool = False, + reload_dirs: Union[str, None] = None, ) -> None: with get_rich_toolkit() as toolkit: server_type = "development" if command == "dev" else "production" @@ -167,6 +168,7 @@ def _run( workers=workers, root_path=root_path, proxy_headers=proxy_headers, + reload_dirs=reload_dirs.split(",") if reload_dirs else None, log_config=get_uvicorn_log_config(), ) @@ -216,6 +218,12 @@ def dev( help="Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to populate remote address info." ), ] = True, + reload_dirs: Annotated[ + Union[str, None], + typer.Option( + help="Comma separated list of directories to watch for changes in. If not provided, by default the whole current directory will be watched." + ), + ] = None, ) -> Any: """ Run a [bold]FastAPI[/bold] app in [yellow]development[/yellow] mode. 🧪 @@ -251,6 +259,7 @@ def dev( app=app, command="dev", proxy_headers=proxy_headers, + reload_dirs=reload_dirs, ) diff --git a/tests/test_cli.py b/tests/test_cli.py index 8bdba1c..76b40a2 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -30,6 +30,7 @@ def test_dev() -> None: "workers": None, "root_path": "", "proxy_headers": True, + "reload_dirs": None, "log_config": get_uvicorn_log_config(), } assert "Using import string: single_file_app:app" in result.output @@ -59,6 +60,7 @@ def test_dev_package() -> None: "workers": None, "root_path": "", "proxy_headers": True, + "reload_dirs": None, "log_config": get_uvicorn_log_config(), } assert "Using import string: nested_package.package:app" in result.output @@ -94,6 +96,8 @@ def test_dev_args() -> None: "--app", "api", "--no-proxy-headers", + "--reload-dirs", + "api,config", ], ) assert result.exit_code == 0, result.output @@ -107,6 +111,10 @@ def test_dev_args() -> None: "workers": None, "root_path": "/api", "proxy_headers": False, + "reload_dirs": [ + "api", + "config", + ], "log_config": get_uvicorn_log_config(), } assert "Using import string: single_file_app:api" in result.output @@ -134,6 +142,7 @@ def test_run() -> None: "workers": None, "root_path": "", "proxy_headers": True, + "reload_dirs": None, "log_config": get_uvicorn_log_config(), } assert "Using import string: single_file_app:app" in result.output @@ -179,6 +188,7 @@ def test_run_args() -> None: "workers": 2, "root_path": "/api", "proxy_headers": False, + "reload_dirs": None, "log_config": get_uvicorn_log_config(), } @@ -218,6 +228,7 @@ def test_dev_help() -> None: assert "The root path is used to tell your app" in result.output assert "The name of the variable that contains the FastAPI app" in result.output assert "Use multiple worker processes." not in result.output + assert "directories to watch for changes in." in result.output def test_run_help() -> None: @@ -239,6 +250,7 @@ def test_run_help() -> None: assert "The root path is used to tell your app" in result.output assert "The name of the variable that contains the FastAPI app" in result.output assert "Use multiple worker processes." in result.output + assert "directories to watch for changes in." not in result.output def test_callback_help() -> None: From 5ce900b0f22334e184c8d639f1d2f584110429ae Mon Sep 17 00:00:00 2001 From: "Joel Young [Jooser PC]" Date: Fri, 28 Feb 2025 11:22:53 -0600 Subject: [PATCH 2/2] Empty commit to force rerun of labeler