From 7576a59402c3ac92bbcc49963433495dc4b23799 Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Tue, 1 Feb 2022 17:12:56 +0100 Subject: [PATCH 1/7] Drop Python 3.6 --- .github/workflows/test-suite.yml | 2 +- README.md | 2 +- databases/backends/postgres.py | 1 - databases/core.py | 7 +------ docs/index.md | 2 +- requirements.txt | 7 ++----- setup.py | 5 ++--- 7 files changed, 8 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 6a081e1e..0690b4d1 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: - python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] + python-version: ["3.7", "3.8", "3.9", "3.10"] services: mysql: diff --git a/README.md b/README.md index ede6bbc3..7d333403 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Databases is suitable for integrating against any async Web framework, such as [ **Documentation**: [https://www.encode.io/databases/](https://www.encode.io/databases/) -**Requirements**: Python 3.6+ +**Requirements**: Python 7+ --- diff --git a/databases/backends/postgres.py b/databases/backends/postgres.py index 3d0a36f2..3e1a6fff 100644 --- a/databases/backends/postgres.py +++ b/databases/backends/postgres.py @@ -1,6 +1,5 @@ import logging import typing -from collections.abc import Sequence import asyncpg from sqlalchemy.dialects.postgresql import pypostgresql diff --git a/databases/core.py b/databases/core.py index 893eb37e..a5383052 100644 --- a/databases/core.py +++ b/databases/core.py @@ -1,8 +1,8 @@ import asyncio import contextlib +import contextvars import functools import logging -import sys import typing from types import TracebackType from urllib.parse import SplitResult, parse_qsl, unquote, urlsplit @@ -18,11 +18,6 @@ TransactionBackend, ) -if sys.version_info >= (3, 7): # pragma: no cover - import contextvars as contextvars -else: # pragma: no cover - import aiocontextvars as contextvars - try: # pragma: no cover import click diff --git a/docs/index.md b/docs/index.md index a5198af2..b18de817 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,7 +17,7 @@ expression language, and provides support for PostgreSQL, MySQL, and SQLite. Databases is suitable for integrating against any async Web framework, such as [Starlette][starlette], [Sanic][sanic], [Responder][responder], [Quart][quart], [aiohttp][aiohttp], [Tornado][tornado], or [FastAPI][fastapi]. -**Requirements**: Python 3.6+ +**Requirements**: Python 3.7+ --- diff --git a/requirements.txt b/requirements.txt index a6c8960a..0d1d5b76 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,8 @@ -# 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 -asyncmy;python_version>"3.6" -aiomysql;python_version<"3.10" +asyncmy +aiomysql aiopg aiosqlite asyncpg diff --git a/setup.py b/setup.py index 046933be..decbf7e5 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ def get_packages(package): setup( name="databases", version=get_version("databases"), - python_requires=">=3.6", + python_requires=">=3.7", url="https://github.com/encode/databases", license="BSD", description="Async database support for Python.", @@ -47,7 +47,7 @@ def get_packages(package): author_email="tom@tomchristie.com", packages=get_packages("databases"), package_data={"databases": ["py.typed"]}, - install_requires=["sqlalchemy>=1.4,<1.5", 'aiocontextvars;python_version<"3.7"'], + install_requires=["sqlalchemy>=1.4,<1.5"], extras_require={ "postgresql": ["asyncpg"], "asyncpg": ["asyncpg"], @@ -66,7 +66,6 @@ def get_packages(package): "Operating System :: OS Independent", "Topic :: Internet :: WWW/HTTP", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", From 84ee96da180c16bb0bfdd23d5c9a17d1a667c6f1 Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Tue, 1 Feb 2022 17:20:17 +0100 Subject: [PATCH 2/7] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d333403..ba16a104 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Databases is suitable for integrating against any async Web framework, such as [ **Documentation**: [https://www.encode.io/databases/](https://www.encode.io/databases/) -**Requirements**: Python 7+ +**Requirements**: Python 3.7+ --- From dcb5274cc03ffd3d09876c0e2f352217c400e025 Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Tue, 1 Feb 2022 17:32:06 +0100 Subject: [PATCH 3/7] simplify mysql tests --- requirements.txt | 7 ------ tests/test_databases.py | 52 --------------------------------------- tests/test_integration.py | 3 +-- 3 files changed, 1 insertion(+), 61 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0d1d5b76..69076a76 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,5 @@ -e . -# Async database drivers -asyncmy -aiomysql -aiopg -aiosqlite -asyncpg - # Sync database drivers for standard tooling around setup/teardown/migrations. psycopg2-binary pymysql diff --git a/tests/test_databases.py b/tests/test_databases.py index ad1fb542..0d2a2004 100644 --- a/tests/test_databases.py +++ b/tests/test_databases.py @@ -4,7 +4,6 @@ import functools import os import re -import sys from unittest.mock import MagicMock, patch import pytest @@ -17,23 +16,6 @@ DATABASE_URLS = [url.strip() for url in os.environ["TEST_DATABASE_URLS"].split(",")] -def mysql_versions(wrapped_func): - """ - Decorator used to handle multiple versions of Python for mysql drivers - """ - - @functools.wraps(wrapped_func) - def check(*args, **kwargs): - url = DatabaseURL(kwargs["database_url"]) - if url.scheme in ["mysql", "mysql+aiomysql"] and sys.version_info >= (3, 10): - pytest.skip("aiomysql supports python 3.9 and lower") - if url.scheme == "mysql+asyncmy" and sys.version_info < (3, 7): - pytest.skip("asyncmy supports python 3.7 and higher") - return wrapped_func(*args, **kwargs) - - return check - - class AsyncMock(MagicMock): async def __call__(self, *args, **kwargs): return super(AsyncMock, self).__call__(*args, **kwargs) @@ -145,7 +127,6 @@ def run_sync(*args, **kwargs): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_queries(database_url): """ @@ -223,7 +204,6 @@ async def test_queries(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_queries_raw(database_url): """ @@ -285,7 +265,6 @@ async def test_queries_raw(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_ddl_queries(database_url): """ @@ -304,7 +283,6 @@ async def test_ddl_queries(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_queries_after_error(database_url): """ @@ -329,7 +307,6 @@ class DBException(Exception): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_results_support_mapping_interface(database_url): """ @@ -358,7 +335,6 @@ async def test_results_support_mapping_interface(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_results_support_column_reference(database_url): """ @@ -390,7 +366,6 @@ async def test_results_support_column_reference(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_result_values_allow_duplicate_names(database_url): """ @@ -407,7 +382,6 @@ async def test_result_values_allow_duplicate_names(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_fetch_one_returning_no_results(database_url): """ @@ -422,7 +396,6 @@ async def test_fetch_one_returning_no_results(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_execute_return_val(database_url): """ @@ -449,7 +422,6 @@ async def test_execute_return_val(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_rollback_isolation(database_url): """ @@ -469,7 +441,6 @@ async def test_rollback_isolation(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_rollback_isolation_with_contextmanager(database_url): """ @@ -492,7 +463,6 @@ async def test_rollback_isolation_with_contextmanager(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_transaction_commit(database_url): """ @@ -510,7 +480,6 @@ async def test_transaction_commit(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_transaction_commit_serializable(database_url): """ @@ -555,7 +524,6 @@ def delete_independently(): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_transaction_rollback(database_url): """ @@ -578,7 +546,6 @@ async def test_transaction_rollback(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_transaction_commit_low_level(database_url): """ @@ -602,7 +569,6 @@ async def test_transaction_commit_low_level(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_transaction_rollback_low_level(database_url): """ @@ -627,7 +593,6 @@ async def test_transaction_rollback_low_level(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_transaction_decorator(database_url): """ @@ -658,7 +623,6 @@ async def insert_data(raise_exception): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_datetime_field(database_url): """ @@ -683,7 +647,6 @@ async def test_datetime_field(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_decimal_field(database_url): """ @@ -711,7 +674,6 @@ async def test_decimal_field(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_json_field(database_url): """ @@ -734,7 +696,6 @@ async def test_json_field(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_custom_field(database_url): """ @@ -760,7 +721,6 @@ async def test_custom_field(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_connections_isolation(database_url): """ @@ -783,7 +743,6 @@ async def test_connections_isolation(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_commit_on_root_transaction(database_url): """ @@ -808,7 +767,6 @@ async def test_commit_on_root_transaction(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_connect_and_disconnect(database_url): """ @@ -832,7 +790,6 @@ async def test_connect_and_disconnect(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_connection_context(database_url): """ @@ -874,7 +831,6 @@ async def get_connection_2(): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_connection_context_with_raw_connection(database_url): """ @@ -888,7 +844,6 @@ async def test_connection_context_with_raw_connection(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_queries_with_expose_backend_connection(database_url): """ @@ -995,7 +950,6 @@ async def test_queries_with_expose_backend_connection(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_database_url_interface(database_url): """ @@ -1074,7 +1028,6 @@ async def test_iterate_outside_transaction_with_values(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_iterate_outside_transaction_with_temp_table(database_url): """ @@ -1104,7 +1057,6 @@ async def test_iterate_outside_transaction_with_temp_table(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) @pytest.mark.parametrize("select_query", [notes.select(), "SELECT * FROM notes"]) -@mysql_versions @async_adapter async def test_column_names(database_url, select_query): """ @@ -1126,7 +1078,6 @@ async def test_column_names(database_url, select_query): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_parallel_transactions(database_url): """ @@ -1191,7 +1142,6 @@ async def test_posgres_interface(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_postcompile_queries(database_url): """ @@ -1209,7 +1159,6 @@ async def test_postcompile_queries(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_result_named_access(database_url): async with Database(database_url) as database: @@ -1225,7 +1174,6 @@ async def test_result_named_access(database_url): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions @async_adapter async def test_mapping_property_interface(database_url): """ diff --git a/tests/test_integration.py b/tests/test_integration.py index c3e585b4..139f8ffe 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -5,7 +5,7 @@ from starlette.testclient import TestClient from databases import Database, DatabaseURL -from tests.test_databases import DATABASE_URLS, mysql_versions +from tests.test_databases import DATABASE_URLS metadata = sqlalchemy.MetaData() @@ -84,7 +84,6 @@ async def add_note(request): @pytest.mark.parametrize("database_url", DATABASE_URLS) -@mysql_versions def test_integration(database_url): app = get_app(database_url) From d9e71bca28055970649a1575c21b1d1b402d67bb Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Tue, 1 Feb 2022 17:56:13 +0100 Subject: [PATCH 4/7] update requirements.txt --- requirements.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/requirements.txt b/requirements.txt index 69076a76..9dfce1cf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,12 @@ -e . +# Async database drivers + asyncmy + aiomysql + aiopg + aiosqlite + asyncpg + # Sync database drivers for standard tooling around setup/teardown/migrations. psycopg2-binary pymysql From 61ec452f6e333dbb8dda722e043d54c5463be00e Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Tue, 31 May 2022 11:11:39 +0200 Subject: [PATCH 5/7] update --- databases/core.py | 1 - requirements.txt | 10 +++++----- tests/test_databases.py | 21 --------------------- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/databases/core.py b/databases/core.py index 1ecc82f6..0e27227c 100644 --- a/databases/core.py +++ b/databases/core.py @@ -1,6 +1,5 @@ import asyncio import contextlib -import contextvars import functools import logging import typing diff --git a/requirements.txt b/requirements.txt index 9dfce1cf..0d1d5b76 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,11 @@ -e . # Async database drivers - asyncmy - aiomysql - aiopg - aiosqlite - asyncpg +asyncmy +aiomysql +aiopg +aiosqlite +asyncpg # Sync database drivers for standard tooling around setup/teardown/migrations. psycopg2-binary diff --git a/tests/test_databases.py b/tests/test_databases.py index b445bb7c..a7545e31 100644 --- a/tests/test_databases.py +++ b/tests/test_databases.py @@ -1076,27 +1076,6 @@ async def test_column_names(database_url, select_query): @pytest.mark.parametrize("database_url", DATABASE_URLS) -<<<<<<< HEAD -@async_adapter -async def test_parallel_transactions(database_url): - """ - Test parallel transaction execution. - """ - - async def test_task(db): - async with db.transaction(): - await db.fetch_one("SELECT 1") - - async with Database(database_url) as database: - await database.fetch_one("SELECT 1") - - tasks = [test_task(database) for i in range(4)] - await asyncio.gather(*tasks) - - -@pytest.mark.parametrize("database_url", DATABASE_URLS) -======= ->>>>>>> master @async_adapter async def test_posgres_interface(database_url): """ From a033f4ea25870fd92283a477ddb6703181038a13 Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Thu, 28 Jul 2022 18:52:32 +0200 Subject: [PATCH 6/7] update type hint --- databases/backends/aiopg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/databases/backends/aiopg.py b/databases/backends/aiopg.py index 9ad12f63..60c741a7 100644 --- a/databases/backends/aiopg.py +++ b/databases/backends/aiopg.py @@ -31,7 +31,7 @@ def __init__( self._database_url = DatabaseURL(database_url) self._options = options self._dialect = self._get_dialect() - self._pool = None + self._pool: typing.Union[aiopg.Pool, None] = None def _get_dialect(self) -> Dialect: dialect = PGDialect_psycopg2( From e80e752677b4400bde901f0e1230ace1f667abcc Mon Sep 17 00:00:00 2001 From: Amin Alaee Date: Thu, 28 Jul 2022 18:53:47 +0200 Subject: [PATCH 7/7] remove file --- databases/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 databases/.DS_Store diff --git a/databases/.DS_Store b/databases/.DS_Store deleted file mode 100644 index 4a6f87e65543d23b0c129e542d1ad4631d517607..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!A`?440XC5I_)xU93%LG{Xv<^4Nm)jj<$$Nth5qBf?Ga^&p-n41&IIP%86$u z+E#UGeCFiA%owzSi-4KzP-c=K#F%czD#%PFUi|{yWPoiMqK_hdNbU`I8=#uiD zw;FyU1H5-5>{d=KJz($F`2S)&t{Gv^UufO@eAkJo2zct+3oY|