Skip to content

Commit ed09100

Browse files
committed
Added passthrough for reload_dir option to uvicorn
1 parent 9a47418 commit ed09100

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/fastapi_cli/cli.py

+9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def _run(
8686
command: str,
8787
app: Union[str, None] = None,
8888
proxy_headers: bool = False,
89+
reload_dirs: Union[str, None] = None,
8990
) -> None:
9091
with get_rich_toolkit() as toolkit:
9192
server_type = "development" if command == "dev" else "production"
@@ -167,6 +168,7 @@ def _run(
167168
workers=workers,
168169
root_path=root_path,
169170
proxy_headers=proxy_headers,
171+
reload_dirs=reload_dirs.split(",") if reload_dirs else None,
170172
log_config=get_uvicorn_log_config(),
171173
)
172174

@@ -216,6 +218,12 @@ def dev(
216218
help="Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to populate remote address info."
217219
),
218220
] = True,
221+
reload_dirs: Annotated[
222+
Union[str, None],
223+
typer.Option(
224+
help="Comma separated list of directories to watch for changes in. If not provided, by default the whole current directory will be watched."
225+
),
226+
] = None,
219227
) -> Any:
220228
"""
221229
Run a [bold]FastAPI[/bold] app in [yellow]development[/yellow] mode. 🧪
@@ -251,6 +259,7 @@ def dev(
251259
app=app,
252260
command="dev",
253261
proxy_headers=proxy_headers,
262+
reload_dirs=reload_dirs,
254263
)
255264

256265

tests/test_cli.py

+11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_dev() -> None:
3030
"workers": None,
3131
"root_path": "",
3232
"proxy_headers": True,
33+
"reload_dirs": None,
3334
"log_config": get_uvicorn_log_config(),
3435
}
3536
assert "Using import string: single_file_app:app" in result.output
@@ -94,6 +95,8 @@ def test_dev_args() -> None:
9495
"--app",
9596
"api",
9697
"--no-proxy-headers",
98+
"--reload-dirs",
99+
"api,config",
97100
],
98101
)
99102
assert result.exit_code == 0, result.output
@@ -107,6 +110,10 @@ def test_dev_args() -> None:
107110
"workers": None,
108111
"root_path": "/api",
109112
"proxy_headers": False,
113+
"reload_dirs": [
114+
"api",
115+
"config",
116+
],
110117
"log_config": get_uvicorn_log_config(),
111118
}
112119
assert "Using import string: single_file_app:api" in result.output
@@ -134,6 +141,7 @@ def test_run() -> None:
134141
"workers": None,
135142
"root_path": "",
136143
"proxy_headers": True,
144+
"reload_dirs": None,
137145
"log_config": get_uvicorn_log_config(),
138146
}
139147
assert "Using import string: single_file_app:app" in result.output
@@ -179,6 +187,7 @@ def test_run_args() -> None:
179187
"workers": 2,
180188
"root_path": "/api",
181189
"proxy_headers": False,
190+
"reload_dirs": None,
182191
"log_config": get_uvicorn_log_config(),
183192
}
184193

@@ -218,6 +227,7 @@ def test_dev_help() -> None:
218227
assert "The root path is used to tell your app" in result.output
219228
assert "The name of the variable that contains the FastAPI app" in result.output
220229
assert "Use multiple worker processes." not in result.output
230+
assert "directories to watch for changes in." in result.output
221231

222232

223233
def test_run_help() -> None:
@@ -239,6 +249,7 @@ def test_run_help() -> None:
239249
assert "The root path is used to tell your app" in result.output
240250
assert "The name of the variable that contains the FastAPI app" in result.output
241251
assert "Use multiple worker processes." in result.output
252+
assert "directories to watch for changes in." not in result.output
242253

243254

244255
def test_callback_help() -> None:

0 commit comments

Comments
 (0)