diff --git a/.github/workflows/test-redistribute.yml b/.github/workflows/test-redistribute.yml index 90fdf89e..6937a9d4 100644 --- a/.github/workflows/test-redistribute.yml +++ b/.github/workflows/test-redistribute.yml @@ -44,6 +44,8 @@ jobs: run: | cd dist/fastapi_cli*/ pip install -r requirements-tests.txt + env: + TIANGOLO_BUILD_PACKAGE: ${{ matrix.package }} - name: Run source distribution tests run: | cd dist/fastapi_cli*/ diff --git a/requirements-tests.txt b/requirements-tests.txt index 0175f5cb..329b3e94 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -4,3 +4,6 @@ pytest >=4.4.0,<8.0.0 coverage[toml] >=6.2,<8.0 mypy ==1.4.1 ruff ==0.2.0 +# Needed explicitly by fastapi-cli-slim +fastapi-slim +uvicorn diff --git a/src/fastapi_cli/cli.py b/src/fastapi_cli/cli.py index d4e22cf5..2aea254c 100644 --- a/src/fastapi_cli/cli.py +++ b/src/fastapi_cli/cli.py @@ -51,6 +51,7 @@ def _run( host: str = "127.0.0.1", port: int = 8000, reload: bool = True, + workers: Union[int, None] = None, root_path: str = "", command: str, app: Union[str, None] = None, @@ -85,6 +86,7 @@ def _run( host=host, port=port, reload=reload, + workers=workers, root_path=root_path, proxy_headers=proxy_headers, ) @@ -200,6 +202,12 @@ def run( help="Enable auto-reload of the server when (code) files change. This is [bold]resource intensive[/bold], use it only during development." ), ] = False, + workers: Annotated[ + Union[int, None], + typer.Option( + help="Use multiple worker processes. Mutually exclusive with the --reload flag." + ), + ] = None, root_path: Annotated[ str, typer.Option( @@ -249,6 +257,7 @@ def run( host=host, port=port, reload=reload, + workers=workers, root_path=root_path, app=app, command="run", diff --git a/tests/test_cli.py b/tests/test_cli.py index 4b7564af..44c14d2c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -26,6 +26,7 @@ def test_dev() -> None: "host": "127.0.0.1", "port": 8000, "reload": True, + "workers": None, "root_path": "", "proxy_headers": True, } @@ -67,6 +68,7 @@ def test_dev_args() -> None: "host": "192.168.0.2", "port": 8080, "reload": False, + "workers": None, "root_path": "/api", "proxy_headers": False, } @@ -92,6 +94,7 @@ def test_run() -> None: "host": "0.0.0.0", "port": 8000, "reload": False, + "workers": None, "root_path": "", "proxy_headers": True, } @@ -118,6 +121,8 @@ def test_run_args() -> None: "--port", "8080", "--no-reload", + "--workers", + "2", "--root-path", "/api", "--app", @@ -133,6 +138,7 @@ def test_run_args() -> None: "host": "192.168.0.2", "port": 8080, "reload": False, + "workers": 2, "root_path": "/api", "proxy_headers": False, } @@ -171,6 +177,7 @@ def test_dev_help() -> None: assert "Enable auto-reload of the server when (code) files change." in result.output 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 def test_run_help() -> None: @@ -191,6 +198,7 @@ def test_run_help() -> None: assert "Enable auto-reload of the server when (code) files change." in result.output 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 def test_callback_help() -> None: