Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start anyio port #357

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions databases/core.py
@@ -1,4 +1,4 @@
import asyncio
import anyio
import contextlib
import functools
import logging
Expand Down Expand Up @@ -203,14 +203,14 @@ class Connection:
def __init__(self, backend: DatabaseBackend) -> None:
self._backend = backend

self._connection_lock = asyncio.Lock()
self._connection_lock = anyio.Lock()
self._connection = self._backend.connection()
self._connection_counter = 0

self._transaction_lock = asyncio.Lock()
self._transaction_lock = anyio.Lock()
self._transaction_stack = [] # type: typing.List[Transaction]

self._query_lock = asyncio.Lock()
self._query_lock = anyio.Lock()

async def __aenter__(self) -> "Connection":
async with self._connection_lock:
Expand Down
8 changes: 1 addition & 7 deletions requirements.txt
@@ -1,13 +1,7 @@
# Notes...
# The JSONField tests require sqlalchemy 1.3+. Other cases work at lower versions.
# The aiocontextvars package is only required as a backport for Python 3.6.
-e .

# Async database drivers
aiomysql
aiopg
aiosqlite
asyncpg
-e .[trio-postgresql,trio-mysql,mysql,sqlite,postgresql,postgresql-aiopg]

# Sync database drivers for standard tooling around setup/teardown/migrations.
psycopg2-binary
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Expand Up @@ -48,12 +48,15 @@ def get_packages(package):
packages=get_packages("databases"),
package_data={"databases": ["py.typed"]},
data_files=[("", ["LICENSE.md"])],
install_requires=['sqlalchemy<1.4', 'aiocontextvars;python_version<"3.7"'],
install_requires=['sqlalchemy<1.4', 'aiocontextvars;python_version<"3.7"', 'anyio~=3.2'],
extras_require={
"trio-postgresql": ["anyio[trio]", "triopg"],
"trio-mysql": ["anyio[trio]", "trio-mysql"],
"postgresql": ["asyncpg"],
"mysql": ["aiomysql"],
"sqlite": ["aiosqlite"],
"postgresql+aiopg": ["aiopg"]
"postgresql+aiopg": ["aiopg"],
"postgresql-aiopg": ["aiopg"]
},
classifiers=[
"Development Status :: 3 - Alpha",
Expand Down
5 changes: 3 additions & 2 deletions tests/test_connection_options.py
@@ -1,12 +1,13 @@
"""
Unit tests for the backend connection arguments.
"""
import pytest

from databases.backends.aiopg import AiopgBackend
from databases.backends.mysql import MySQLBackend
from databases.backends.postgres import PostgresBackend
from databases.core import DatabaseURL
from tests.test_databases import DATABASE_URLS, async_adapter
from tests.test_databases import DATABASE_URLS


def test_postgres_pool_size():
Expand All @@ -15,7 +16,7 @@ def test_postgres_pool_size():
assert kwargs == {"min_size": 1, "max_size": 20}


@async_adapter
@pytest.mark.anyio
async def test_postgres_pool_size_connect():
for url in DATABASE_URLS:
if DatabaseURL(url).dialect != "postgresql":
Expand Down