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

fix: missing wheel(*.whl) for Python 3.12 #97

Merged
merged 14 commits into from
May 30, 2024
Merged
24 changes: 18 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ jobs:
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 5
strategy:
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10" ]
waketzheng marked this conversation as resolved.
Show resolved Hide resolved
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install and configure Poetry
Expand All @@ -42,10 +48,16 @@ jobs:
options: --health-cmd="mariadb-admin ping -uroot -p${MYSQL_ROOT_PASSWORD}" --health-interval 10s --health-timeout 5s --health-retries 5
strategy:
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10" ]
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install and configure Poetry
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### 0.2.10

- Fix ssl context pass bool.
- Fix missing `*.whl` for Python 3.12 (#94)

### 0.2.9

Expand Down
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ up:
deps:
@poetry install

style: deps
_style:
@isort -src $(checkfiles)
@black $(checkfiles)

check: deps
style: deps _style

_check:
@black --check $(checkfiles) || (echo "Please run 'make style' to auto-fix style issues" && false)
@ruff $(checkfiles)
@ruff check $(checkfiles)
@mypy $(checkfiles)

test: deps
check: deps _check

_test:
$(py_warn) MYSQL_PASS=$(MYSQL_PASS) pytest

test: deps _test

clean:
@rm -rf *.so && rm -rf build && rm -rf dist && rm -rf asyncmy/*.c && rm -rf asyncmy/*.so && rm -rf asyncmy/*.html

Expand All @@ -29,4 +35,4 @@ build: clean
benchmark: deps
@python benchmark/main.py

ci: check test
ci: deps _check _test
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,33 @@ Now you can uninstall previously installed tools.
function if you want just one connection to the database, consider connection pool for multiple connections.

```py
import asyncio
import os

from asyncmy import connect
from asyncmy.cursors import DictCursor
import asyncio


async def run():
conn = await connect()
conn = await connect(user=os.getenv("DB_USER"), password=os.getenv("DB_PASSWORD", ""))
async with conn.cursor(cursor=DictCursor) as cursor:
await cursor.execute("create database if not exists test")
await cursor.execute(
"""CREATE TABLE if not exists test.asyncmy
(
`id` int primary key auto_increment,
`decimal` decimal(10, 2),
`date` date,
`datetime` datetime,
`float` float,
`string` varchar(200),
`tinyint` tinyint
)"""
await cursor.execute("CREATE DATABASE IF NOT EXISTS test")
await cursor.execute("""
"""
CREATE TABLE IF NOT EXISTS test.`asyncmy` (
`id` int primary key AUTO_INCREMENT,
`decimal` decimal(10, 2),
`date` date,
`datetime` datetime,
`float` float,
`string` varchar(200),
`tinyint` tinyint
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
""".strip()
)


if __name__ == '__main__':
if __name__ == "__main__":
asyncio.run(run())
```

Expand Down
1 change: 1 addition & 0 deletions asyncmy/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Implements auth methods
"""

from .errors import OperationalError

try:
Expand Down
1 change: 0 additions & 1 deletion asyncmy/constants/CR.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa
# errmsg.h
CR_ERROR_FIRST = 2000
CR_UNKNOWN_ERROR = 2000
Expand Down
43 changes: 22 additions & 21 deletions asyncmy/contexts.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
from collections.abc import Coroutine
from typing import Any, Iterator


class _ContextManager(Coroutine):
__slots__ = ("_coro", "_obj")

def __init__(self, coro):
def __init__(self, coro: Coroutine) -> None:
self._coro = coro
self._obj = None
self._obj: Any = None

def send(self, value):
def send(self, value) -> Any:
return self._coro.send(value)

def throw(self, typ, val=None, tb=None):
def throw(self, typ, val=None, tb=None) -> Any:
if val is None:
return self._coro.throw(typ)
elif tb is None:
return self._coro.throw(typ, val)
else:
return self._coro.throw(typ, val, tb)

def close(self):
def close(self) -> None:
return self._coro.close()

@property
def gi_frame(self):
return self._coro.gi_frame
def gi_frame(self) -> Any:
return self._coro.gi_frame # type:ignore[attr-defined]

@property
def gi_running(self):
return self._coro.gi_running
def gi_running(self) -> Any:
return self._coro.gi_running # type:ignore[attr-defined]

@property
def gi_code(self):
return self._coro.gi_code
def gi_code(self) -> Any:
return self._coro.gi_code # type:ignore[attr-defined]

def __next__(self):
def __next__(self) -> Any:
return self.send(None)

def __iter__(self):
def __iter__(self) -> Iterator:
return self._coro.__await__()

def __await__(self):
def __await__(self) -> Any:
return self._coro.__await__()

async def __aenter__(self):
async def __aenter__(self) -> Any:
self._obj = await self._coro
return self._obj

async def __aexit__(self, exc_type, exc, tb):
async def __aexit__(self, exc_type, exc, tb) -> None:
await self._obj.close()
self._obj = None


class _PoolContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc, tb):
async def __aexit__(self, exc_type, exc, tb) -> None:
self._obj.close()
await self._obj.wait_closed()
self._obj = None
Expand All @@ -62,17 +63,17 @@ async def __aexit__(self, exc_type, exc, tb):
class _PoolAcquireContextManager(_ContextManager):
__slots__ = ("_coro", "_conn", "_pool")

def __init__(self, coro, pool):
def __init__(self, coro, pool) -> None:
super().__init__(coro)
self._coro = coro
self._conn = None
self._pool = pool

async def __aenter__(self):
async def __aenter__(self) -> Any:
self._conn = await self._coro
return self._conn

async def __aexit__(self, exc_type, exc, tb):
async def __aexit__(self, exc_type, exc, tb) -> None:
try:
await self._pool.release(self._conn)
finally:
Expand All @@ -81,7 +82,7 @@ async def __aexit__(self, exc_type, exc, tb):


class _ConnectionContextManager(_ContextManager):
async def __aexit__(self, exc_type, exc, tb):
async def __aexit__(self, exc_type, exc, tb) -> None:
if exc_type is not None:
self._obj.close()
else:
Expand Down
11 changes: 5 additions & 6 deletions asyncmy/optionfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
class Parser(RawConfigParser):
def __init__(self, **kwargs):
kwargs["allow_no_value"] = True
super(Parser, self).__init__(**kwargs)
super().__init__(**kwargs)

def get(self, section, option, **kwargs):
value = super(Parser, self).get(section, option)
quotes = ["'", '"']
for quote in quotes:
if len(value) >= 2 and value[0] == value[-1] == quote:
return value[1:-1]
value = super().get(section, option)
quotes = ("'", '"')
if len(value) >= 2 and value[0] == value[-1] and value[0] in quotes:
return value[1:-1]
return value
4 changes: 2 additions & 2 deletions asyncmy/replication/bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ def bit_count(bitmap: list):
n = 0
for i in range(0, len(bitmap)):
bit = bitmap[i]
if type(bit) is str:
if isinstance(bit, str):
bit = ord(bit)
n += BIT_COUNT_IN_BYTE[bit]
return n


def bit_get(bitmap: list, position: int):
bit = bitmap[int(position / 8)]
if type(bit) is str:
if isinstance(bit, str):
bit = ord(bit)
return bit & (1 << (position & 7))
2 changes: 1 addition & 1 deletion asyncmy/replication/row_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
@staticmethod
def _is_null(null_bitmap, position):
bit = null_bitmap[int(position / 8)]
if type(bit) is str:
if isinstance(bit, str):
bit = ord(bit)
return bit & (1 << (position % 8))

Expand Down
2 changes: 1 addition & 1 deletion asyncmy/structs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import struct

h = struct.Struct("<h")
I = struct.Struct("<I") # noqa
I = struct.Struct("<I") # noqa: E741
H = struct.Struct("<H")
Q = struct.Struct("<Q")
i = struct.Struct("<i")
Expand Down
2 changes: 1 addition & 1 deletion asyncmy/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__VERSION__ = "0.2.10-rc1"
__VERSION__ = "0.2.10"
Loading
Loading