Skip to content

Commit 6ebf7d4

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

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-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

+12
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
@@ -59,6 +60,7 @@ def test_dev_package() -> None:
5960
"workers": None,
6061
"root_path": "",
6162
"proxy_headers": True,
63+
"reload_dirs": None,
6264
"log_config": get_uvicorn_log_config(),
6365
}
6466
assert "Using import string: nested_package.package:app" in result.output
@@ -94,6 +96,8 @@ def test_dev_args() -> None:
9496
"--app",
9597
"api",
9698
"--no-proxy-headers",
99+
"--reload-dirs",
100+
"api,config",
97101
],
98102
)
99103
assert result.exit_code == 0, result.output
@@ -107,6 +111,10 @@ def test_dev_args() -> None:
107111
"workers": None,
108112
"root_path": "/api",
109113
"proxy_headers": False,
114+
"reload_dirs": [
115+
"api",
116+
"config",
117+
],
110118
"log_config": get_uvicorn_log_config(),
111119
}
112120
assert "Using import string: single_file_app:api" in result.output
@@ -134,6 +142,7 @@ def test_run() -> None:
134142
"workers": None,
135143
"root_path": "",
136144
"proxy_headers": True,
145+
"reload_dirs": None,
137146
"log_config": get_uvicorn_log_config(),
138147
}
139148
assert "Using import string: single_file_app:app" in result.output
@@ -179,6 +188,7 @@ def test_run_args() -> None:
179188
"workers": 2,
180189
"root_path": "/api",
181190
"proxy_headers": False,
191+
"reload_dirs": None,
182192
"log_config": get_uvicorn_log_config(),
183193
}
184194

@@ -218,6 +228,7 @@ def test_dev_help() -> None:
218228
assert "The root path is used to tell your app" in result.output
219229
assert "The name of the variable that contains the FastAPI app" in result.output
220230
assert "Use multiple worker processes." not in result.output
231+
assert "directories to watch for changes in." in result.output
221232

222233

223234
def test_run_help() -> None:
@@ -239,6 +250,7 @@ def test_run_help() -> None:
239250
assert "The root path is used to tell your app" in result.output
240251
assert "The name of the variable that contains the FastAPI app" in result.output
241252
assert "Use multiple worker processes." in result.output
253+
assert "directories to watch for changes in." not in result.output
242254

243255

244256
def test_callback_help() -> None:

0 commit comments

Comments
 (0)