Skip to content

Commit 9b247da

Browse files
committed
1. migrate from poetry to uv
2. migrate from black+flake8 to ruff 3. drop support for Python3.8
1 parent 434a514 commit 9b247da

File tree

9 files changed

+1440
-1579
lines changed

9 files changed

+1440
-1579
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,16 @@ jobs:
2626
TEST_MSSQL_PASS: Abcd12345678
2727
strategy:
2828
matrix:
29-
python-version: [ "3.8", "3.9", "3.10" ]
29+
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
3030
steps:
31-
- uses: actions/cache@v2
32-
with:
33-
path: ~/.cache/pip
34-
key: ${{ runner.os }}-pip-${{ hashFiles('**/poetry.lock') }}
35-
restore-keys: |
36-
${{ runner.os }}-pip-
37-
- uses: actions/checkout@v2
38-
- uses: actions/setup-python@v2
31+
- uses: actions/checkout@v5
32+
- uses: actions/setup-python@v6
3933
with:
4034
python-version: ${{ matrix.python-version }}
41-
- name: Install and configure Poetry
42-
run: |
43-
pip install -U pip poetry
44-
poetry config virtualenvs.create false
35+
- uses: astral-sh/setup-uv@v7
36+
with:
37+
enable-cache: true
38+
activate-environment: true
4539
- name: Install requirements
4640
run: make deps
4741
- name: Install ODBC driver
@@ -53,7 +47,7 @@ jobs:
5347
- name: Run ci
5448
run: make ci
5549
- name: Upload Coverage
56-
run: coveralls --service=github
50+
run: uvx coveralls --service=github
5751
env:
5852
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5953
COVERALLS_FLAG_NAME: ${{ matrix.python-version }}

.github/workflows/pypi.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ jobs:
77
publish:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v2
11-
- uses: actions/setup-python@v1
10+
- uses: actions/checkout@v5
11+
- uses: actions/setup-python@v6
1212
with:
1313
python-version: '3.x'
14-
- name: Install and configure Poetry
15-
run: |
16-
pip install -U pip poetry
17-
poetry config virtualenvs.create false
14+
- uses: astral-sh/setup-uv@v7
1815
- name: Build dists
1916
run: make build
2017
- name: Pypi Publish
21-
uses: pypa/gh-action-pypi-publish@master
18+
uses: pypa/gh-action-pypi-publish@release/v1
2219
with:
2320
user: __token__
2421
password: ${{ secrets.pypi_password }}

Makefile

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,51 @@ py_warn = PYTHONDEVMODE=1
33
pytest_opts = -n auto --cov=asyncodbc --tb=native -q
44

55
up:
6-
@poetry update
6+
@uv lock --upgrade
77

88
deps:
9-
@poetry install
10-
11-
check: deps build
12-
ifneq ($(shell which black),)
13-
black --check $(checkfiles) || (echo "Please run 'make style' to auto-fix style issues" && false)
14-
endif
15-
pflake8 $(checkfiles)
16-
#mypy $(checkfiles)
17-
#pylint -d C,W,R $(checkfiles)
18-
#bandit -r $(checkfiles)
9+
@uv sync --inexact --all-extras --all-groups $(options)
10+
11+
_style:
12+
@ruff format $(checkfiles)
13+
@ruff check --fix $(checkfiles)
14+
style: deps _style
15+
16+
_codeqc:
17+
# mypy $(checkfiles)
18+
bandit -c pyproject.toml -r $(checkfiles)
1919
twine check dist/*
20+
codeqc: build _codeqc
21+
22+
_check: _build
23+
@ruff format --check $(checkfiles) || (echo "Please run 'make style' to auto-fix style issues" && false)
24+
@ruff check $(checkfiles)
25+
$(MAKE) _codeqc
26+
check: deps _check
2027

28+
_lint: _build _style _codeqc
29+
lint: deps _lint
2130

22-
test_mssql: deps
31+
test: deps test_mssql
32+
33+
test_mssql:
2334
$(py_warn) TEST_DSN="DRIVER=ODBC Driver 18 for SQL Server;SERVER=127.0.0.1,1433;UID=sa;PWD=$(TEST_MSSQL_PASS);TrustServerCertificate=YES;MARS_Connection=YES" pytest $(pytest_opts)
2435

2536
_testall: test_mssql
2637

2738
testall: deps _testall
2839
coverage report
2940

30-
ci: check testall
41+
ci: check _testall
3142

3243
docs: deps
3344
rm -fR ./build
3445
sphinx-build -M html docs build
3546

36-
style: deps
37-
isort -src $(checkfiles)
38-
black $(checkfiles)
39-
40-
build: deps
47+
_build:
4148
rm -fR dist/
42-
poetry build
49+
uv build
50+
build: deps _build
4351

4452
publish: deps build
4553
twine upload dist/*

asyncodbc/connection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def connect(
2121
executor=None,
2222
echo=False,
2323
after_created=None,
24-
**kwargs
24+
**kwargs,
2525
):
2626
"""Accepts an ODBC connection string and returns a new Connection object.
2727
@@ -53,7 +53,7 @@ def connect(
5353
executor=executor,
5454
echo=echo,
5555
after_created=after_created,
56-
**kwargs
56+
**kwargs,
5757
)
5858
)
5959

@@ -67,7 +67,7 @@ async def _connect(
6767
executor=None,
6868
echo=False,
6969
after_created=None,
70-
**kwargs
70+
**kwargs,
7171
):
7272
conn = Connection(
7373
dsn=dsn,
@@ -77,7 +77,7 @@ async def _connect(
7777
echo=echo,
7878
executor=executor,
7979
after_created=after_created,
80-
**kwargs
80+
**kwargs,
8181
)
8282
await conn._connect()
8383
return conn
@@ -101,7 +101,7 @@ def __init__(
101101
executor=None,
102102
echo=False,
103103
after_created=None,
104-
**kwargs
104+
**kwargs,
105105
):
106106
self._executor = executor
107107
self._loop = asyncio.get_event_loop()
@@ -133,7 +133,7 @@ async def _connect(self):
133133
autocommit=self._autocommit,
134134
ansi=self._ansi,
135135
timeout=self._timeout,
136-
**self._kwargs
136+
**self._kwargs,
137137
)
138138
self._conn = await f
139139
self._connected = True

asyncodbc/cursor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,7 @@ def rowVerColumns(self, table, catalog=None, schema=None, nullable=True): # nop
269269
def primaryKeys(self, table, catalog=None, schema=None): # nopep8
270270
"""Creates a result set of column names that make up the primary key
271271
for a table by executing the SQLPrimaryKeys function."""
272-
fut = self._run_operation(
273-
self._impl.primaryKeys, table, catalog=catalog, schema=schema
274-
)
272+
fut = self._run_operation(self._impl.primaryKeys, table, catalog=catalog, schema=schema)
275273
return fut
276274

277275
def foreignKeys(self, *a, **kw): # nopep8

asyncodbc/pool.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import asyncio
22
import collections
3-
from typing import Deque, Set
43

54
from .connection import Connection, connect
65
from .utils import _PoolAcquireContextManager, _PoolContextManager
@@ -11,19 +10,13 @@
1110
def create_pool(minsize=1, maxsize=10, echo=False, pool_recycle=-1, **kwargs):
1211
return _PoolContextManager(
1312
_create_pool(
14-
minsize=minsize,
15-
maxsize=maxsize,
16-
echo=echo,
17-
pool_recycle=pool_recycle,
18-
**kwargs
13+
minsize=minsize, maxsize=maxsize, echo=echo, pool_recycle=pool_recycle, **kwargs
1914
)
2015
)
2116

2217

2318
async def _create_pool(minsize=1, maxsize=10, echo=False, pool_recycle=-1, **kwargs):
24-
pool = Pool(
25-
minsize=minsize, maxsize=maxsize, echo=echo, pool_recycle=pool_recycle, **kwargs
26-
)
19+
pool = Pool(minsize=minsize, maxsize=maxsize, echo=echo, pool_recycle=pool_recycle, **kwargs)
2720
if minsize > 0:
2821
async with pool.cond:
2922
await pool.fill_free_pool(False)
@@ -34,13 +27,8 @@ class Pool(asyncio.AbstractServer):
3427
"""Connection pool, just from aiomysql"""
3528

3629
def __init__(
37-
self,
38-
minsize: int,
39-
maxsize: int,
40-
pool_recycle: int,
41-
echo: bool = False,
42-
**kwargs
43-
):
30+
self, minsize: int, maxsize: int, pool_recycle: int, echo: bool = False, **kwargs
31+
) -> None:
4432
if minsize < 0:
4533
raise ValueError("minsize should be zero or greater")
4634
if maxsize < minsize:
@@ -49,10 +37,10 @@ def __init__(
4937
self._loop = asyncio.get_event_loop()
5038
self._conn_kwargs = kwargs
5139
self._acquiring = 0
52-
self._free: Deque[Connection] = collections.deque(maxlen=maxsize)
40+
self._free: collections.deque[Connection] = collections.deque(maxlen=maxsize)
5341
self._cond = asyncio.Condition()
54-
self._used: Set[Connection] = set()
55-
self._terminated: Set[Connection] = set()
42+
self._used: set[Connection] = set()
43+
self._terminated: set[Connection] = set()
5644
self._closing = False
5745
self._closed = False
5846
self._echo = echo
@@ -128,7 +116,7 @@ async def wait_closed(self):
128116
if self._closed:
129117
return
130118
if not self._closing:
131-
raise RuntimeError(".wait_closed() should be called " "after .close()")
119+
raise RuntimeError(".wait_closed() should be called after .close()")
132120

133121
while self._free:
134122
conn = self._free.popleft()
@@ -165,8 +153,7 @@ async def fill_free_pool(self, override_min: bool = False):
165153
while n < free_size:
166154
conn = self._free[-1]
167155
if conn.expired or (
168-
self._recycle > -1
169-
and self._loop.time() - conn.last_usage > self._recycle
156+
self._recycle > -1 and self._loop.time() - conn.last_usage > self._recycle
170157
):
171158
self._free.pop()
172159
await conn.close()

0 commit comments

Comments
 (0)