Skip to content
Merged
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
36 changes: 18 additions & 18 deletions src/fastapi_cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from pathlib import Path
from typing import Annotated, Any, Union
from typing import Annotated, Any

import typer
from pydantic import ValidationError
Expand Down Expand Up @@ -57,7 +57,7 @@ def version_callback(value: bool) -> None:
@app.callback()
def callback(
version: Annotated[
Union[bool, None],
bool | None,
typer.Option(
"--version", help="Show the version and exit.", callback=version_callback
),
Expand Down Expand Up @@ -99,19 +99,19 @@ def _get_module_tree(module_paths: list[Path]) -> Tree:


def _run(
path: Union[Path, None] = None,
path: Path | None = None,
*,
host: str = "127.0.0.1",
port: int = 8000,
reload: bool = True,
reload_dirs: Union[list[Path], None] = None,
workers: Union[int, None] = None,
reload_dirs: list[Path] | None = None,
workers: int | None = None,
root_path: str = "",
command: str,
app: Union[str, None] = None,
entrypoint: Union[str, None] = None,
app: str | None = None,
entrypoint: str | None = None,
proxy_headers: bool = False,
forwarded_allow_ips: Union[str, None] = None,
forwarded_allow_ips: str | None = None,
) -> None:
with get_rich_toolkit() as toolkit:
server_type = "development" if command == "dev" else "production"
Expand Down Expand Up @@ -236,7 +236,7 @@ def _run(
@app.command()
def dev(
path: Annotated[
Union[Path, None],
Path | None,
typer.Argument(
help="A path to a Python file or package directory (with [blue]__init__.py[/blue] files) containing a [bold]FastAPI[/bold] app. If not provided, a default set of paths will be tried."
),
Expand All @@ -262,7 +262,7 @@ def dev(
),
] = True,
reload_dir: Annotated[
Union[list[Path], None],
list[Path] | None,
typer.Option(
help="Set reload directories explicitly, instead of using the current working directory."
),
Expand All @@ -274,13 +274,13 @@ def dev(
),
] = "",
app: Annotated[
Union[str, None],
str | None,
typer.Option(
help="The name of the variable that contains the [bold]FastAPI[/bold] app in the imported module or package. If not provided, it is detected automatically."
),
] = None,
entrypoint: Annotated[
Union[str, None],
str | None,
typer.Option(
"--entrypoint",
"-e",
Expand All @@ -294,7 +294,7 @@ def dev(
),
] = True,
forwarded_allow_ips: Annotated[
Union[str, None],
str | None,
typer.Option(
help="Comma separated list of IP Addresses to trust with proxy headers. The literal '*' means trust everything."
),
Expand Down Expand Up @@ -343,7 +343,7 @@ def dev(
@app.command()
def run(
path: Annotated[
Union[Path, None],
Path | None,
typer.Argument(
help="A path to a Python file or package directory (with [blue]__init__.py[/blue] files) containing a [bold]FastAPI[/bold] app. If not provided, a default set of paths will be tried."
),
Expand All @@ -369,7 +369,7 @@ def run(
),
] = False,
workers: Annotated[
Union[int, None],
int | None,
typer.Option(
help="Use multiple worker processes. Mutually exclusive with the --reload flag."
),
Expand All @@ -381,13 +381,13 @@ def run(
),
] = "",
app: Annotated[
Union[str, None],
str | None,
typer.Option(
help="The name of the variable that contains the [bold]FastAPI[/bold] app in the imported module or package. If not provided, it is detected automatically."
),
] = None,
entrypoint: Annotated[
Union[str, None],
str | None,
typer.Option(
"--entrypoint",
"-e",
Expand All @@ -401,7 +401,7 @@ def run(
),
] = True,
forwarded_allow_ips: Annotated[
Union[str, None],
str | None,
typer.Option(
help="Comma separated list of IP Addresses to trust with proxy headers. The literal '*' means trust everything."
),
Expand Down
6 changes: 3 additions & 3 deletions src/fastapi_cli/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
from pathlib import Path
from typing import Any, Optional
from typing import Any

from pydantic import BaseModel, StrictStr

logger = logging.getLogger(__name__)


class FastAPIConfig(BaseModel):
entrypoint: Optional[StrictStr] = None
entrypoint: StrictStr | None = None

@classmethod
def _read_pyproject_toml(cls) -> dict[str, Any]:
Expand All @@ -33,7 +33,7 @@ def _read_pyproject_toml(cls) -> dict[str, Any]:
return data.get("tool", {}).get("fastapi", {}) # type: ignore

@classmethod
def resolve(cls, entrypoint: Optional[str] = None) -> "FastAPIConfig":
def resolve(cls, entrypoint: str | None = None) -> "FastAPIConfig":
config = cls._read_pyproject_toml()

if entrypoint is not None:
Expand Down
5 changes: 2 additions & 3 deletions src/fastapi_cli/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass
from logging import getLogger
from pathlib import Path
from typing import Union

from fastapi_cli.exceptions import FastAPICLIException

Expand Down Expand Up @@ -65,7 +64,7 @@ def get_module_data_from_path(path: Path) -> ModuleData:
)


def get_app_name(*, mod_data: ModuleData, app_name: Union[str, None] = None) -> str:
def get_app_name(*, mod_data: ModuleData, app_name: str | None = None) -> str:
try:
mod = importlib.import_module(mod_data.module_import_str)
except (ImportError, ValueError) as e:
Expand Down Expand Up @@ -111,7 +110,7 @@ class ImportData:


def get_import_data(
*, path: Union[Path, None] = None, app_name: Union[str, None] = None
*, path: Path | None = None, app_name: str | None = None
) -> ImportData:
if not path:
path = get_default_path()
Expand Down
5 changes: 1 addition & 4 deletions src/fastapi_cli/logging.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import logging
from typing import Union

from rich.console import Console
from rich.logging import RichHandler


def setup_logging(
terminal_width: Union[int, None] = None, level: int = logging.INFO
) -> None:
def setup_logging(terminal_width: int | None = None, level: int = logging.INFO) -> None:
logger = logging.getLogger("fastapi_cli")
console = Console(width=terminal_width) if terminal_width else None
rich_handler = RichHandler(
Expand Down