Skip to content

Commit fc95163

Browse files
committed
migrate to ruff and uv
1 parent a9fd3f6 commit fc95163

File tree

11 files changed

+190
-130
lines changed

11 files changed

+190
-130
lines changed

.github/workflows/actions.yaml

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- uses: actions/checkout@v4
2424
with:
2525
submodules: recursive
26+
2627
- name: Set up Python ${{ matrix.python-version }}
2728
uses: actions/setup-python@v5
2829
with:
@@ -38,20 +39,31 @@ jobs:
3839
if: matrix.os == 'macos-latest'
3940
run: brew install tarantool
4041

42+
- name: Install uv
43+
uses: astral-sh/setup-uv@v4
44+
4145
- name: Install dependencies
42-
run: |
43-
python -m pip install --upgrade pip setuptools wheel coveralls
46+
run: uv sync --all-extras
47+
48+
- name: Run ruff check
49+
run: uv run ruff check .
50+
51+
- name: Run ruff format check
52+
run: uv run ruff format --check .
53+
4454
- name: Run tests
45-
run: |
46-
if [[ "$RUNNER_OS" == "Linux" && ${{ matrix.python-version }} == "3.12" && ${{ matrix.tarantool }} == "3" ]]; then
47-
make build && make test
48-
make clean && make debug && make coverage
49-
# coveralls
50-
else
51-
make build && make lint && make quicktest
52-
fi
55+
run: uv run pytest .
56+
57+
- name: Run coverage tests
58+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.14' && matrix.tarantool == '3'
5359
env:
60+
ASYNCTNT_DEBUG: "1"
5461
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}"
62+
run: |
63+
make clean
64+
uv run pytest --cov
65+
./scripts/run_until_success.sh uv run coverage report -m
66+
./scripts/run_until_success.sh uv run coverage html
5567
5668
build-wheels:
5769
name: Build wheels on ${{ matrix.os }}
@@ -69,75 +81,98 @@ jobs:
6981
submodules: recursive
7082

7183
- uses: actions/setup-python@v5
84+
with:
85+
python-version: '3.14'
86+
87+
- name: Install uv
88+
uses: astral-sh/setup-uv@v4
7289

7390
- name: Install cibuildwheel
74-
run: python -m pip install --upgrade cibuildwheel
91+
run: uv tool install cibuildwheel
92+
93+
- name: Install pyproject-build
94+
run: uv tool install build
95+
96+
- name: Build source archive
97+
run: |
98+
pyproject-build -s .
7599
76100
- name: Build wheels
77-
run: python -m cibuildwheel --output-dir wheelhouse
101+
run: cibuildwheel --output-dir dist
78102
env:
79103
CIBW_BUILD: "cp39-* cp310-* cp311-* cp312-* cp313-* cp314-* pp310-*"
80104

81105
- uses: actions/upload-artifact@v4
82106
with:
83107
name: wheels-${{ matrix.os }}
84-
path: ./wheelhouse/*.whl
108+
path: ./dist/*
85109

86110
publish:
87111
name: Publish wheels
88112
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
89113
needs:
90114
- build-wheels
91115
runs-on: ubuntu-latest
116+
environment:
117+
name: pypi
118+
url: https://pypi.org/p/asynctnt
119+
permissions:
120+
id-token: write # Required for trusted publishing
121+
contents: write # Required for releases
92122
steps:
93123
- name: Get tag
94124
id: get_tag
95125
run: echo ::set-output name=TAG::${GITHUB_REF/refs\/tags\//}
126+
96127
- run: echo "Current tag is ${{ steps.get_tag.outputs.TAG }}"
128+
97129
- uses: actions/checkout@v4
98130
with:
99131
submodules: recursive
132+
100133
- name: Set up Python
101134
uses: actions/setup-python@v5
102135
with:
103-
python-version: '3.12'
136+
python-version: '3.14'
137+
138+
- name: Install uv
139+
uses: astral-sh/setup-uv@v4
104140

105141
- name: Install dependencies
106142
run: |
107-
python -m pip install --upgrade pip setuptools wheel twine build
143+
uv pip install --upgrade build
108144
109145
- uses: actions/download-artifact@v4
110146
with:
111147
name: wheels-ubuntu-latest
112-
path: wheels-ubuntu
148+
path: dist
113149

114150
- uses: actions/download-artifact@v4
115151
with:
116152
name: wheels-macos-latest
117-
path: wheels-macos
153+
path: dist
118154

119155
- uses: actions/download-artifact@v4
120156
with:
121157
name: wheels-windows-latest
122-
path: wheels-windows
158+
path: dist
123159

124-
- name: Publish dist
160+
- name: Build source archive
125161
run: |
126162
python -m build . -s
127-
tree dist wheels-ubuntu wheels-macos wheels-windows
128-
twine upload dist/* wheels-ubuntu/*.whl wheels-macos/*.whl wheels-windows/*.whl
129-
env:
130-
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
131-
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
163+
tree dist
164+
165+
- name: Publish to PyPI
166+
uses: pypa/gh-action-pypi-publish@release/v1
167+
with:
168+
print-hash: true
169+
132170
- uses: marvinpinto/action-automatic-releases@latest
133171
with:
134172
repo_token: "${{ secrets.GITHUB_TOKEN }}"
135173
prerelease: false
136174
title: ${{ steps.get_tag.outputs.TAG }}
137175
files: |
138-
wheels-ubuntu/*.whl
139-
wheels-macos/*.whl
140-
wheels-windows/*.whl
141176
dist/*
142177
143178
docs:
@@ -154,12 +189,10 @@ jobs:
154189
- name: Set up Python
155190
uses: actions/setup-python@v5
156191
with:
157-
python-version: '3.12'
192+
python-version: '3.14'
158193

159-
- name: Install dependencies
160-
run: |
161-
python -m pip install --upgrade pip setuptools wheel build
162-
make build
194+
- name: Install uv
195+
uses: astral-sh/setup-uv@v4
163196

164197
- name: Build docs
165198
run: make docs

Makefile

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,62 @@
11
.PHONY: clean build local debug annotate dist docs style mypy ruff style-check lint test quicktest coverage
22

3-
PYTHON?=python
4-
53
all: local
64

7-
clean:
8-
pip uninstall -y asynctnt
9-
rm -rf asynctnt/*.c asynctnt/*.h asynctnt/*.cpp
10-
rm -rf asynctnt/*.so asynctnt/*.html
11-
rm -rf asynctnt/iproto/*.c asynctnt/iproto/*.h
12-
rm -rf asynctnt/iproto/*.so asynctnt/iproto/*.html asynctnt/iproto/requests/*.html
13-
rm -rf build *.egg-info .eggs dist
14-
find . -name '__pycache__' | xargs rm -rf
15-
rm -rf htmlcov
16-
rm -rf __tnt*
17-
rm -rf tests/__tnt*
18-
19-
205
build:
21-
$(PYTHON) -m pip install -e '.[test,docs]'
6+
uv pip install -e '.[test,docs]'
227

238
local:
24-
$(PYTHON) -m pip install -e .
25-
9+
uv pip install -e .
2610

2711
debug: clean
28-
ASYNCTNT_DEBUG=1 $(PYTHON) -m pip install -e '.[test]'
29-
12+
ASYNCTNT_DEBUG=1 uv pip install -e '.[test]'
3013

3114
annotate:
3215
cython -3 -a asynctnt/iproto/protocol.pyx
3316

34-
dist:
35-
$(PYTHON) -m build .
36-
37-
docs: build
38-
$(MAKE) -C docs html
17+
lint: style-check ruff
3918

4019
style:
41-
$(PYTHON) -m black .
42-
$(PYTHON) -m isort .
20+
uv run --active ruff format .
21+
uv run --active ruff check --select I,F401 --fix .
4322

44-
mypy:
45-
$(PYTHON) -m mypy --enable-error-code ignore-without-code .
23+
style-check:
24+
uv run --active ruff format --check .
4625

4726
ruff:
48-
$(PYTHON) -m ruff check .
49-
50-
style-check:
51-
$(PYTHON) -m black --check --diff .
52-
$(PYTHON) -m isort --check --diff .
27+
uv run --active ruff check .
5328

54-
lint: style-check ruff
29+
mypy:
30+
uv run --active mypy --enable-error-code ignore-without-code .
5531

56-
test: lint
57-
PYTHONASYNCIODEBUG=1 $(PYTHON) -m pytest
58-
$(PYTHON) -m pytest
59-
USE_UVLOOP=1 $(PYTHON) -m pytest
32+
test:
33+
PYTHONASYNCIODEBUG=1 uv run --active pytest
34+
uv run --active pytest
35+
USE_UVLOOP=1 uv run --active pytest
6036

6137
quicktest:
62-
$(PYTHON) -m pytest
38+
uv run --active pytest
6339

6440
coverage:
65-
$(PYTHON) -m pytest --cov
66-
./scripts/run_until_success.sh $(PYTHON) -m coverage report -m
67-
./scripts/run_until_success.sh $(PYTHON) -m coverage html
41+
uv run --active pytest --cov
42+
./scripts/run_until_success.sh uv run --active coverage report -m
43+
./scripts/run_until_success.sh uv run --active coverage html
44+
45+
dist:
46+
uv pip install build
47+
uv run --active python -m build .
48+
49+
docs: build
50+
$(MAKE) -C docs html
51+
52+
clean:
53+
pip uninstall -y asynctnt
54+
rm -rf asynctnt/*.c asynctnt/*.h asynctnt/*.cpp
55+
rm -rf asynctnt/*.so asynctnt/*.html
56+
rm -rf asynctnt/iproto/*.c asynctnt/iproto/*.h
57+
rm -rf asynctnt/iproto/*.so asynctnt/iproto/*.html asynctnt/iproto/requests/*.html
58+
rm -rf build *.egg-info .eggs dist
59+
find . -name '__pycache__' | xargs rm -rf
60+
rm -rf htmlcov
61+
rm -rf __tnt*
62+
rm -rf tests/__tnt*

asynctnt/connection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def __init__(
134134
self._auto_refetch_schema = True
135135
if not self._fetch_schema:
136136
logger.warning(
137-
"Setting fetch_schema to True as " "auto_refetch_schema is True"
137+
"Setting fetch_schema to True as auto_refetch_schema is True"
138138
)
139139
self._fetch_schema = True
140140
else:
@@ -257,12 +257,12 @@ async def full_connect():
257257
if self._host.startswith("unix/"):
258258
unix_path = self._port
259259
assert isinstance(unix_path, str), (
260-
"port must be a str instance for " "unix socket"
260+
"port must be a str instance for unix socket"
261261
)
262262
assert unix_path, "No unix file path specified"
263-
assert os.path.exists(
264-
unix_path
265-
), "Unix socket `{}` not found".format(unix_path)
263+
assert os.path.exists(unix_path), (
264+
"Unix socket `{}` not found".format(unix_path)
265+
)
266266

267267
conn = loop.create_unix_connection(
268268
functools.partial(

bench/benchmark.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def main():
2020
parser.add_argument("-b", type=int, default=300, help="number of bulks")
2121
args = parser.parse_args()
2222

23-
print("Running {} requests in {} batches. ".format(args.n, args.b))
23+
print("Running {} requests in {} batches. ".format(args.n, args.b)) # noqa: T201
2424

2525
scenarios = [
2626
["ping", []],
@@ -38,7 +38,7 @@ def main():
3838
try:
3939
import uvloop
4040
except ImportError:
41-
print("No uvloop installed. Skipping.")
41+
print("No uvloop installed. Skipping.") # noqa: T201
4242
continue
4343

4444
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
@@ -48,7 +48,7 @@ def main():
4848
loop = asyncio.new_event_loop()
4949
asyncio.set_event_loop(loop)
5050

51-
print("--------- uvloop: {} --------- ".format(use_uvloop))
51+
print("--------- uvloop: {} --------- ".format(use_uvloop)) # noqa: T201
5252

5353
for name, conn_creator in [
5454
("asynctnt", create_asynctnt),
@@ -87,7 +87,7 @@ async def bulk_f():
8787
end = datetime.datetime.now()
8888

8989
elapsed = end - start
90-
print(
90+
print( # noqa: T201
9191
"{} [{}] Elapsed: {}, RPS: {}".format(
9292
name, method, elapsed, n / elapsed.total_seconds()
9393
)

0 commit comments

Comments
 (0)