diff --git a/databasez/__init__.py b/databasez/__init__.py index 79f1807..0d3d9c0 100644 --- a/databasez/__init__.py +++ b/databasez/__init__.py @@ -1,5 +1,5 @@ from databasez.core import Database, DatabaseURL -__version__ = "0.11.3" +__version__ = "0.11.4" __all__ = ["Database", "DatabaseURL"] diff --git a/databasez/core/database.py b/databasez/core/database.py index 008131c..d98f804 100644 --- a/databasez/core/database.py +++ b/databasez/core/database.py @@ -31,21 +31,6 @@ from databasez.types import BatchCallable, BatchCallableResult, DictAny -try: # pragma: no cover - import click - - # Extra log info for optional coloured terminal outputs. - LOG_EXTRA = {"color_message": "Query: " + click.style("%s", bold=True) + " Args: %s"} - CONNECT_EXTRA = {"color_message": "Connected to database " + click.style("%s", bold=True)} - DISCONNECT_EXTRA = { - "color_message": "Disconnected from database " + click.style("%s", bold=True) - } -except ImportError: # pragma: no cover - LOG_EXTRA = {} - CONNECT_EXTRA = {} - DISCONNECT_EXTRA = {} - - logger = logging.getLogger("databasez") default_database: type[interfaces.DatabaseBackend] @@ -363,7 +348,6 @@ async def connect(self) -> bool: self._loop = asyncio.get_event_loop() await self.backend.connect(self.url, **self.options) - logger.info("Connected to database %s", self.url.obscure_password, extra=CONNECT_EXTRA) self.is_connected = True if self._global_connection is None: @@ -386,7 +370,7 @@ async def disconnect( # parent_database is injected and should not be specified manually if not await self.decr_refcount() or force: if not self.is_connected: - logger.debug("Already disconnected, skipping disconnection") + logger.debug("Already disconnected, skip disconnecting") return False if force: logger.warning("Force disconnect, despite refcount not 0") @@ -413,11 +397,6 @@ async def disconnect( self._global_connection = None self._connection = None finally: - logger.info( - "Disconnected from database %s", - self.url.obscure_password, - extra=DISCONNECT_EXTRA, - ) self.is_connected = False await self.backend.disconnect() self._loop = None diff --git a/docs/database.md b/docs/database.md index 9daac82..a8dbdb9 100644 --- a/docs/database.md +++ b/docs/database.md @@ -278,6 +278,13 @@ If you want more extensive logging when creating a custom overwrite, you can set By default this is off, to not confuse people. +See `tests/conftest.py` for an example. + +## Debugging db connects + +If you want to get debug output for successfully connecting to the db, you can pass `echo=True` as argument. + + ## Links [esmerald]: https://github.com/dymmond/esmerald diff --git a/docs/release-notes.md b/docs/release-notes.md index 9ecb436..5a6cced 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -5,7 +5,8 @@ ### Changed - Use monkay.asgi helpers. -- Bump to python>=3.10. +- Bump to Python 3.10+. +- Reduce noise by removing info log messages when connecting to/disconnecting from a db. ## 0.11.3 diff --git a/pyproject.toml b/pyproject.toml index 359028a..52e94b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,9 +42,9 @@ keywords = [ "sqlalchemy", "sqlite", "asyncio", - "esmerald", + "ravyn", "saffier", - "jdbc" + "jdbc", ] [project.urls] @@ -94,15 +94,15 @@ fix = true [tool.ruff.lint] select = [ - "E", # pycodestyle errors - "W", # pycodestyle warnings - "F", # pyflakes - "C", # flake8-comprehensions - "B", # flake8-bugbear - "I", # isort + "E", # pycodestyle errors + "W", # pycodestyle warnings + "F", # pyflakes + "C", # flake8-comprehensions + "B", # flake8-bugbear + "I", # isort "ASYNC", # ASYNC "UP", - "SIM", # simplification + "SIM", # simplification ] ignore = [ @@ -116,7 +116,7 @@ ignore = [ "docs_src/*" = ["ASYNC", "F704", "B007"] [tool.ruff.lint.isort] -known-third-party = ["esmerald", "starlette"] +known-third-party = ["ravyn", "starlette", "lilya"] [tool.ruff.lint.pycodestyle] max-line-length = 120 @@ -137,7 +137,11 @@ module = "docs_src.*" ignore_errors = true [tool.pytest.ini_options] -addopts = ["--strict-config", "--strict-markers", "--pdbcls=IPython.terminal.debugger:Pdb"] +addopts = [ + "--strict-config", + "--strict-markers", + "--pdbcls=IPython.terminal.debugger:Pdb", +] xfail_strict = true junit_family = "xunit2" setup_timeout = 5 @@ -179,13 +183,10 @@ build = "mkdocs build" serve = "mkdocs serve --dev-addr localhost:8000" - [tool.hatch.envs.test] # type-checking features = ["all"] -extra-dependencies = [ - "mypy>=1.1.0,<2.0.0", -] +extra-dependencies = ["mypy>=1.1.0,<2.0.0"] [tool.hatch.envs.test.scripts] check_types = "mypy -p databasez" @@ -203,7 +204,7 @@ extra-dependencies = [ # for debugging "sqlalchemy_utils", "ipdb>=0.13.13", - "esmerald>=1.1.0", + "ravyn>=0.3.8", "mypy>=1.1.0,<2.0.0", "starlette>=0.26.1", "httpx", @@ -214,7 +215,7 @@ extra-dependencies = [ "pytest-asyncio", "pytest-xdist", "anyio", - "uvloop" + "uvloop", ] [tool.hatch.envs.hatch-test.env-vars] diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..d3cac87 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,3 @@ +from databasez import utils + +utils.DATABASEZ_OVERWRITE_LOGGING = True diff --git a/tests/test_integration.py b/tests/test_integration.py index 3a39a31..1c44ba0 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -3,11 +3,11 @@ import pytest import sqlalchemy -from esmerald import Gateway, Request, route -from esmerald import JSONResponse as EsmeraldJSONResponse -from esmerald.applications import Esmerald -from esmerald.testclient import EsmeraldTestClient from monkay.asgi import Lifespan +from ravyn import Gateway, Request, route +from ravyn import JSONResponse as EsmeraldJSONResponse +from ravyn.applications import Ravyn +from ravyn.testclient import RavynTestClient from starlette.applications import Starlette from starlette.responses import JSONResponse from starlette.routing import Route @@ -144,7 +144,7 @@ async def add_notes(request: Request) -> EsmeraldJSONResponse: await database.execute(query) return EsmeraldJSONResponse({"text": data["text"], "completed": data["completed"]}) - app = Esmerald(routes=[Gateway(handler=list_notes), Gateway(handler=add_notes)]) + app = Ravyn(routes=[Gateway(handler=list_notes), Gateway(handler=add_notes)]) @app.on_event("startup") async def startup(): @@ -200,7 +200,7 @@ def test_integration(database_url, get_app): def test_integration_esmerald(database_url): app = get_esmerald_app(database_url) - with EsmeraldTestClient(app) as client: + with RavynTestClient(app) as client: response = client.post("/notes", json={"text": "example", "completed": True}) assert response.status_code == 200 assert response.json() == {"text": "example", "completed": True} @@ -209,7 +209,7 @@ def test_integration_esmerald(database_url): assert response.status_code == 200 assert response.json() == [{"text": "example", "completed": True}] - with EsmeraldTestClient(app) as client: + with RavynTestClient(app) as client: # Ensure sessions are isolated response = client.get("/notes") assert response.status_code == 200