From 54cb43b9ea3890a58466da6bfa7b79cff261c666 Mon Sep 17 00:00:00 2001 From: PokkaKiyo Date: Sun, 5 May 2024 14:21:40 +0800 Subject: [PATCH 1/7] Added the optional workers flag --- src/fastapi_cli/cli.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/fastapi_cli/cli.py b/src/fastapi_cli/cli.py index d4e22cf5..50cc2a69 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, ) @@ -117,6 +119,12 @@ def dev( help="Enable auto-reload of the server when (code) files change. This is [bold]resource intensive[/bold], use it only during development." ), ] = True, + 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( @@ -166,6 +174,7 @@ def dev( host=host, port=port, reload=reload, + workers=workers, root_path=root_path, app=app, command="dev", @@ -200,6 +209,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 +264,7 @@ def run( host=host, port=port, reload=reload, + workers=workers, root_path=root_path, app=app, command="run", From ff30cbde3f63e419fe2978b23c2971ccd7a55885 Mon Sep 17 00:00:00 2001 From: PokkaKiyo Date: Sun, 5 May 2024 14:28:44 +0800 Subject: [PATCH 2/7] Fix the tests --- tests/test_cli.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 4b7564af..4a8faedb 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, } @@ -133,6 +136,7 @@ def test_run_args() -> None: "host": "192.168.0.2", "port": 8080, "reload": False, + "workers": None, "root_path": "/api", "proxy_headers": False, } From d92f694e4ccaeee712ef4b6ff0d3a718cb68d23d Mon Sep 17 00:00:00 2001 From: PokkaKiyo Date: Sun, 5 May 2024 15:29:23 +0800 Subject: [PATCH 3/7] Update tests --- tests/test_cli.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 4a8faedb..1b464c08 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -53,6 +53,8 @@ def test_dev_args() -> None: "--port", "8080", "--no-reload", + "--workers", + "4", "--root-path", "/api", "--app", @@ -68,7 +70,7 @@ def test_dev_args() -> None: "host": "192.168.0.2", "port": 8080, "reload": False, - "workers": None, + "workers": 4, "root_path": "/api", "proxy_headers": False, } @@ -121,6 +123,8 @@ def test_run_args() -> None: "--port", "8080", "--no-reload", + "--workers", + "2", "--root-path", "/api", "--app", @@ -136,7 +140,7 @@ def test_run_args() -> None: "host": "192.168.0.2", "port": 8080, "reload": False, - "workers": None, + "workers": 2, "root_path": "/api", "proxy_headers": False, } From 0f68339034f26455433f390ba0087bcb3fe4fdc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 7 May 2024 11:19:55 -0700 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=91=B7=20Update=20test-redistribute?= =?UTF-8?q?=20install=20env=20vars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test-redistribute.yml | 2 ++ 1 file changed, 2 insertions(+) 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*/ From 491ceec026a55e0b7a268b5f76fa91cccfb7d215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 7 May 2024 11:20:26 -0700 Subject: [PATCH 5/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Tweak=20dev=20command,?= =?UTF-8?q?=20remove=20--workers=20(leave=20only=20in=20run=20command)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fastapi_cli/cli.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/fastapi_cli/cli.py b/src/fastapi_cli/cli.py index 50cc2a69..2aea254c 100644 --- a/src/fastapi_cli/cli.py +++ b/src/fastapi_cli/cli.py @@ -119,12 +119,6 @@ def dev( help="Enable auto-reload of the server when (code) files change. This is [bold]resource intensive[/bold], use it only during development." ), ] = True, - 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( @@ -174,7 +168,6 @@ def dev( host=host, port=port, reload=reload, - workers=workers, root_path=root_path, app=app, command="dev", From 111e7971ad416b2308fe1c10a5b2ef772894557c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 7 May 2024 11:20:59 -0700 Subject: [PATCH 6/7] =?UTF-8?q?=E2=9C=85=20Update=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_cli.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 1b464c08..44c14d2c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -53,8 +53,6 @@ def test_dev_args() -> None: "--port", "8080", "--no-reload", - "--workers", - "4", "--root-path", "/api", "--app", @@ -70,7 +68,7 @@ def test_dev_args() -> None: "host": "192.168.0.2", "port": 8080, "reload": False, - "workers": 4, + "workers": None, "root_path": "/api", "proxy_headers": False, } @@ -179,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: @@ -199,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: From 3b79c039b70543b65b16782e20003a63ea9feefd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 7 May 2024 11:21:11 -0700 Subject: [PATCH 7/7] =?UTF-8?q?=E2=9E=95=20Update=20test=20dependencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements-tests.txt | 3 +++ 1 file changed, 3 insertions(+) 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