Skip to content

Commit 901704d

Browse files
authored
chore(logging): make log consistent fastapi (#547)
* chore(logging): make log consistent fastapi * chore(logging): make log consistent fastapi * chore(logging): make log consistent fastapi * chore(logging): make log consistent fastapi
1 parent ac34370 commit 901704d

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

advanced_alchemy/extensions/starlette/config.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
import contextlib
88
from dataclasses import dataclass, field
9+
from importlib.util import find_spec
910
from typing import TYPE_CHECKING, Any, Callable, Optional, cast
1011

11-
from click import echo
1212
from sqlalchemy.exc import OperationalError
1313
from starlette.concurrency import run_in_threadpool
1414
from starlette.middleware.base import BaseHTTPMiddleware
@@ -30,6 +30,22 @@
3030
from starlette.responses import Response
3131

3232

33+
FASTAPI_CLI_INSTALLED = bool(find_spec("fastapi_cli"))
34+
35+
36+
def _echo(message: str) -> None: # pragma: no cover
37+
"""Echo a message using either rich toolkit or click echo."""
38+
if FASTAPI_CLI_INSTALLED:
39+
from fastapi_cli.utils.cli import get_rich_toolkit
40+
41+
with get_rich_toolkit() as toolkit:
42+
toolkit.print(message, tag="INFO")
43+
else:
44+
from click import echo
45+
46+
echo(message)
47+
48+
3349
def _make_unique_state_key(app: "Starlette", key: str) -> str: # pragma: no cover
3450
"""Generates a unique state key for the Starlette application.
3551
@@ -116,9 +132,9 @@ async def create_all_metadata(self) -> None: # pragma: no cover
116132
)
117133
await conn.commit()
118134
except OperationalError as exc:
119-
echo(f" * Could not create target metadata. Reason: {exc}")
135+
_echo(f" * Could not create target metadata. Reason: {exc}")
120136
else:
121-
echo(" * Created target metadata.")
137+
_echo(" * Created target metadata.")
122138

123139
def init_app(self, app: "Starlette") -> None:
124140
"""Initialize the Starlette application with this configuration.
@@ -259,7 +275,7 @@ async def create_all_metadata(self) -> None: # pragma: no cover
259275
metadata_registry.get(None if self.bind_key == "default" else self.bind_key).create_all, conn
260276
)
261277
except OperationalError as exc:
262-
echo(f" * Could not create target metadata. Reason: {exc}")
278+
_echo(f" * Could not create target metadata. Reason: {exc}")
263279

264280
def init_app(self, app: "Starlette") -> None:
265281
"""Initialize the Starlette application with this configuration.

advanced_alchemy/utils/sync_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ruff: noqa: PYI036, SLF001, ARG001
2-
"""Utilities for async/sync interoperability in SQLSpec.
2+
"""Utilities for async/sync interoperability in Advanced Alchemy.
33
44
This module provides utilities for converting between async and sync functions,
55
managing concurrency limits, and handling context managers. Used primarily

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ lint = [
132132
"types-python-dateutil",
133133
"types-pytz",
134134
"types-ujson",
135-
"types-passlib",
136135
"types-cryptography",
137136
"types-passlib",
138137
]

0 commit comments

Comments
 (0)