Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added passthrough for reload_dir option to uvicorn #160

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions src/fastapi_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
)

Expand Down Expand Up @@ -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. 🧪
Expand Down Expand Up @@ -251,6 +259,7 @@ def dev(
app=app,
command="dev",
proxy_headers=proxy_headers,
reload_dirs=reload_dirs,
)


Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
}

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Loading