Download tasks/fastapi__fastapi-cli__5e72ded279/trained.patch from WardenOfPluto/build-spec-tasks: direct link, hf CLI and curl.
- Browser
- Download file 7.54 kB
-
https://huggingface.co/datasets/WardenOfPluto/build-spec-tasks/resolve/main/tasks/fastapi__fastapi-cli__5e72ded279/trained.patch
- Command line
-
hf download hf://datasets/WardenOfPluto/build-spec-tasks/tasks/fastapi__fastapi-cli__5e72ded279/trained.patch
-
curl -L -o trained.patch https://huggingface.co/datasets/WardenOfPluto/build-spec-tasks/resolve/main/tasks/fastapi__fastapi-cli__5e72ded279/trained.patch
7.54 kB
| --- a/src/fastapi_cli/cli.py | |
| +++ b/src/fastapi_cli/cli.py | |
| host: str = "127.0.0.1", | |
| port: int = 8000, | |
| reload: bool = True, | |
| + reload_dirs: Union[list[Path], None] = None, | |
| workers: Union[int, None] = None, | |
| root_path: str = "", | |
| command: str, | |
| host=host, | |
| port=port, | |
| reload=reload, | |
| + reload_dirs=reload_dirs, | |
| workers=workers, | |
| root_path=root_path, | |
| proxy_headers=proxy_headers, | |
| help="Enable auto-reload of the server when (code) files change. This is [bold]resource intensive[/bold], use it only during development." | |
| ), | |
| ] = True, | |
| + reload_dirs: Annotated[ | |
| + Union[list[Path], None], | |
| + typer.Option( | |
| + "--reload-dir", | |
| + help="Specify a directory to watch for changes, in addition to the default ones. Can be used multiple times.", | |
| + ), | |
| + ] = None, | |
| root_path: Annotated[ | |
| str, | |
| typer.Option( | |
| host=host, | |
| port=port, | |
| reload=reload, | |
| + reload_dirs=reload_dirs, | |
| root_path=root_path, | |
| app=app, | |
| entrypoint=entrypoint, | |
| --- a/tests/test_cli.py | |
| +++ b/tests/test_cli.py | |
| "host": "127.0.0.1", | |
| "port": 8000, | |
| "reload": True, | |
| + "reload_dirs": None, | |
| "workers": None, | |
| "root_path": "", | |
| "proxy_headers": True, | |
| "host": "127.0.0.1", | |
| "port": 8000, | |
| "reload": True, | |
| + "reload_dirs": None, | |
| "workers": None, | |
| "root_path": "", | |
| "proxy_headers": True, | |
| "host": "192.168.0.2", | |
| "port": 8080, | |
| "reload": False, | |
| + "reload_dirs": None, | |
| "workers": None, | |
| "root_path": "/api", | |
| "proxy_headers": False, | |
| "host": "127.0.0.1", | |
| "port": 8111, | |
| "reload": True, | |
| + "reload_dirs": None, | |
| "workers": None, | |
| "root_path": "", | |
| "proxy_headers": True, | |
| "host": "127.0.0.1", | |
| "port": 8080, | |
| "reload": True, | |
| + "reload_dirs": None, | |
| "workers": None, | |
| "root_path": "", | |
| "proxy_headers": True, | |
| "host": "0.0.0.0", | |
| "port": 8000, | |
| "reload": False, | |
| + "reload_dirs": None, | |
| "workers": None, | |
| "root_path": "", | |
| "proxy_headers": True, | |
| "host": "0.0.0.0", | |
| "port": 8000, | |
| "reload": False, | |
| + "reload_dirs": None, | |
| "workers": None, | |
| "root_path": "", | |
| "proxy_headers": True, | |
| "host": "192.168.0.2", | |
| "port": 8080, | |
| "reload": False, | |
| + "reload_dirs": None, | |
| "workers": 2, | |
| "root_path": "/api", | |
| "proxy_headers": False, | |
| "host": "0.0.0.0", | |
| "port": 8111, | |
| "reload": False, | |
| + "reload_dirs": None, | |
| "workers": None, | |
| "root_path": "", | |
| "proxy_headers": True, | |
| "host": "0.0.0.0", | |
| "port": 8080, | |
| "reload": False, | |
| + "reload_dirs": None, | |
| "workers": None, | |
| "root_path": "", | |
| "proxy_headers": True, | |
| "host": "127.0.0.1", | |
| "port": 8000, | |
| "reload": True, | |
| + "reload_dirs": None, | |
| "workers": None, | |
| "root_path": "", | |
| "proxy_headers": True, | |
| "host": "0.0.0.0", | |
| "port": 8000, | |
| "reload": False, | |
| + "reload_dirs": None, | |
| "workers": None, | |
| "root_path": "", | |
| "proxy_headers": True, | |
| "log_config": get_uvicorn_log_config(), | |
| } | |
| assert "Using import string: single_file_app:app" in result.output | |
| + | |
| + | |
| +def test_dev_reload_dirs() -> None: | |
| + # Today's code: _run in src/fastapi_cli/cli.py never passes reload_dirs to uvicorn.run, | |
| + # so the kwargs dict has no "reload_dirs" key. | |
| + with changing_dir(assets_path): | |
| + with patch.object(uvicorn, "run") as mock_run: | |
| + result = runner.invoke( | |
| + app, | |
| + ["dev", "single_file_app.py", "--reload-dir", "mydir"], | |
| + ) | |
| + assert result.exit_code == 0, result.output | |
| + assert mock_run.called | |
| + assert mock_run.call_args | |
| + assert mock_run.call_args.kwargs["reload_dirs"] == [Path("mydir")] | |
| + assert "Using import string: single_file_app:app" in result.output | |
| + | |
| + | |
| +def test_dev_multiple_reload_dirs() -> None: | |
| + # Today's code: _run in src/fastapi_cli/cli.py never passes reload_dirs to uvicorn.run. | |
| + with changing_dir(assets_path): | |
| + with patch.object(uvicorn, "run") as mock_run: | |
| + result = runner.invoke( | |
| + app, | |
| + [ | |
| + "dev", | |
| + "single_file_app.py", | |
| + "--reload-dir", | |
| + "first_dir", | |
| + "--reload-dir", | |
| + "second_dir", | |
| + ], | |
| + ) | |
| + assert result.exit_code == 0, result.output | |
| + assert mock_run.called | |
| + assert mock_run.call_args | |
| + assert mock_run.call_args.kwargs["reload_dirs"] == [ | |
| + Path("first_dir"), | |
| + Path("second_dir"), | |
| + ] | |
| + | |
| + | |
| +def test_dev_no_reload_dirs_by_default() -> None: | |
| + # Today's code: _run in src/fastapi_cli/cli.py never passes reload_dirs to uvicorn.run, | |
| + # so the kwargs dict has no "reload_dirs" key. | |
| + with changing_dir(assets_path): | |
| + with patch.object(uvicorn, "run") as mock_run: | |
| + result = runner.invoke(app, ["dev", "single_file_app.py"]) | |
| + assert result.exit_code == 0, result.output | |
| + assert mock_run.called | |
| + assert mock_run.call_args | |
| + assert mock_run.call_args.kwargs["reload_dirs"] is None | |
| + | |
| + | |
| +def test_run_has_no_reload_dirs_option() -> None: | |
| + # Today's code: run in src/fastapi_cli/cli.py defines no --reload-dir option; | |
| + # after the change it still must not, only dev gets it. | |
| + result = runner.invoke(app, ["run", "--help"]) | |
| + assert result.exit_code == 0, result.output | |
| + assert "--reload-dir" not in result.output | |
| + | |
| + | |
| +def test_dev_help_shows_reload_dir() -> None: | |
| + # Today's code: dev in src/fastapi_cli/cli.py defines no --reload-dir option, | |
| + # so its help text cannot mention it. | |
| + result = runner.invoke(app, ["dev", "--help"]) | |
| + assert result.exit_code == 0, result.output | |
| + assert "Specify a directory to watch for changes" in result.output | |
| def test_script() -> None: | |