Browse Source
* ♻️ Add support for `pip install "fastapi[standard]"` and make `fastapi` not include the optional standard dependencies * 📝 Update docs to include new fastapi[standard] * ✨ Add new stub fastapi command that tells people to install fastapi[standard] * ✅ Add tests for new stub CLI * 🔧 Add new command fastapi in main fastapi project, for when fastapi-cli is not installed * ✏️ Fix types * 📝 Add note about quotes when installing fastapi[standard] * 📝 Update docs about standard extra dependencies * ⬆️ Upgrade fastapi-clipull/11940/head
committed by
GitHub
15 changed files with 114 additions and 113 deletions
@ -0,0 +1,3 @@ |
|||
from fastapi.cli import main |
|||
|
|||
main() |
@ -0,0 +1,13 @@ |
|||
try: |
|||
from fastapi_cli.cli import main as cli_main |
|||
|
|||
except ImportError: # pragma: no cover |
|||
cli_main = None # type: ignore |
|||
|
|||
|
|||
def main() -> None: |
|||
if not cli_main: # type: ignore[truthy-function] |
|||
message = 'To use the fastapi command, please install "fastapi[standard]":\n\n\tpip install "fastapi[standard]"\n' |
|||
print(message) |
|||
raise RuntimeError(message) # noqa: B904 |
|||
cli_main() |
@ -0,0 +1,32 @@ |
|||
import subprocess |
|||
import sys |
|||
from unittest.mock import patch |
|||
|
|||
import fastapi.cli |
|||
import pytest |
|||
|
|||
|
|||
def test_fastapi_cli(): |
|||
result = subprocess.run( |
|||
[ |
|||
sys.executable, |
|||
"-m", |
|||
"coverage", |
|||
"run", |
|||
"-m", |
|||
"fastapi", |
|||
"dev", |
|||
"non_existent_file.py", |
|||
], |
|||
capture_output=True, |
|||
encoding="utf-8", |
|||
) |
|||
assert result.returncode == 1, result.stdout |
|||
assert "Using path non_existent_file.py" in result.stdout |
|||
|
|||
|
|||
def test_fastapi_cli_not_installed(): |
|||
with patch.object(fastapi.cli, "cli_main", None): |
|||
with pytest.raises(RuntimeError) as exc_info: |
|||
fastapi.cli.main() |
|||
assert "To use the fastapi command, please install" in str(exc_info.value) |
Loading…
Reference in new issue