Skip to content

Commit fbc9362

Browse files
chore: update ci
1 parent 99782fe commit fbc9362

13 files changed

Lines changed: 167 additions & 54 deletions

.github/workflows/format-code.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Format Python
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
format:
13+
name: Run Code Formatters
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout Repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: "3.x"
24+
25+
- name: Install Formatters
26+
run: |
27+
pip install black isort
28+
29+
- name: Run isort
30+
run: isort .
31+
32+
- name: Run Black Formatter
33+
run: black .
34+
35+
- name: Commit and Push Changes
36+
run: |
37+
git config --global user.name 'github-actions'
38+
git config --global user.email 'github-actions@github.com'
39+
git add .
40+
git commit -m 'Auto-format Python code with isort, Black, and Ruff' || echo "No changes to commit"
41+
git push

.github/workflows/python-package.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Release on Tag
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # only triggers on tags like v1.0.0
7+
8+
jobs:
9+
release:
10+
name: Build and Publish Release
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
contents: write # to create GitHub release
15+
id-token: write # for OIDC (trusted publishing)
16+
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0 # Required for auto-changelog to get all tags and commits
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: '3.11'
27+
28+
- name: Install uv
29+
run: |
30+
curl -LsSf https://astral.sh/uv/install.sh | sh
31+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
32+
33+
- name: Install auto-changelog
34+
run: npm install -g auto-changelog
35+
36+
- name: Clean Old Builds
37+
run: rm -rf dist build *.egg-info
38+
39+
- name: Setup Virtual Environment
40+
run: uv venv
41+
42+
- name: Install dependencies
43+
run: uv pip install -e ".[dev]"
44+
45+
- name: Build the package
46+
run: uv build
47+
48+
- name: Generate Changelog
49+
run: |
50+
auto-changelog --commit-limit false --breaking-pattern "BREAKING CHANGE:"
51+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
52+
git config --local user.name "github-actions[bot]"
53+
git add .
54+
git commit -m "chore: update CHANGELOG.md for ${{ github.ref_name }} "
55+
git checkout main
56+
git push
57+
58+
- name: Create GitHub Release with Notes
59+
uses: softprops/action-gh-release@v2
60+
with:
61+
tag_name: ${{ github.ref_name }}
62+
name: Release ${{ github.ref_name }}
63+
generate_release_notes: true
64+
files: dist/*
65+
body_path: CHANGELOG.md
66+
67+
- name: Publish to PyPI
68+
run: uv publish --token ${{ secrets.POETRY_PYPI_TOKEN_PYPI }}
69+
70+

.github/workflows/run-tox.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Run Tox Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.10", "3.11", "3.12", "3.13"]
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Install uv
26+
run: |
27+
curl -LsSf https://astral.sh/uv/install.sh | sh
28+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
29+
- name: Setup Virtual Environment
30+
run: uv venv
31+
32+
- name: Install dependencies
33+
run: uv pip install -e ".[dev]"
34+
35+
- name: Install Tox
36+
run: uv pip install tox
37+
38+
- name: Run Tox
39+
run: uv run tox

pyproject.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,16 @@ dependencies = [
3434

3535
[project.optional-dependencies]
3636
dev = [
37-
"mypy>=1.15.0",
37+
3838
"pytest>=8.3.4",
3939
"pytest-asyncio>=0.25.3",
4040
"black>=23.0.0",
4141
"isort>=5.12.0",
42-
"ruff>=0.1.0",
4342
]
4443
asyncpg = [
4544
"asyncpg>=0.27.0"
4645
]
4746

48-
49-
50-
51-
5247
[tool.black]
5348
line-length = 88
5449
target-version = ["py39"]

records2/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21

32
from .async_database import Connection, Database, Record
43
from .cli import cli

records2/async_database.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import os
1+
from collections.abc import AsyncGenerator, Sequence
22
from contextlib import asynccontextmanager
3-
from typing import Any, AsyncGenerator, List, Optional, Sequence, Type, TypeVar
3+
from typing import Any, List, Optional, Type, TypeVar
44

55
from pydantic import BaseModel
66
from sqlalchemy import inspect, text
@@ -45,13 +45,13 @@ async def bulk_query(self, query: str, values: Sequence[dict]) -> Any:
4545

4646
async def query_file(self, path: str, **params) -> Any:
4747
async with await self._conn._handle.dbapi_connection.cursor() as cursor:
48-
with open(path, "r") as f:
48+
with open(path) as f:
4949
sql = f.read()
5050
result = await self._conn.execute(text(sql), params)
5151
return result
5252

5353
async def bulk_query_file(self, path: str, values: Sequence[dict]) -> Any:
54-
with open(path, "r") as f:
54+
with open(path) as f:
5555
sql = f.read()
5656
result = await self._conn.execute(text(sql), values)
5757
return result

records2/database.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
# -*- coding: utf-8 -*-
21

32
import os
43
from contextlib import contextmanager
54

6-
from sqlalchemy import create_engine, exc, inspect, text
5+
from sqlalchemy import create_engine, inspect, text
76

87
from .record import Record, RecordCollection
98

109

11-
class Database(object):
10+
class Database:
1211
"""Main interface for database operations."""
1312

1413
def __init__(self, db_url=None, **kwargs):
@@ -62,12 +61,12 @@ def bulk_query(self, query, *multiparams):
6261
return conn.bulk_query(query, *multiparams)
6362

6463
def query_file(self, path, fetchall=False, **params):
65-
with open(path, "r") as f:
64+
with open(path) as f:
6665
query = f.read()
6766
return self.query(query, fetchall=fetchall, **params)
6867

6968
def bulk_query_file(self, path, *multiparams):
70-
with open(path, "r") as f:
69+
with open(path) as f:
7170
query = f.read()
7271
return self.bulk_query(query, *multiparams)
7372

@@ -85,7 +84,7 @@ def transaction(self):
8584
conn.close()
8685

8786

88-
class Connection(object):
87+
class Connection:
8988
def __init__(self, connection, close_with_result=False):
9089
self._connection = connection
9190
self._close_with_result = close_with_result
@@ -124,12 +123,12 @@ def bulk_query(self, query, *multiparams):
124123
return result
125124

126125
def query_file(self, path, fetchall=False, **params):
127-
with open(path, "r") as f:
126+
with open(path) as f:
128127
query = f.read()
129128
return self.query(query, fetchall=fetchall, **params)
130129

131130
def bulk_query_file(self, path, *multiparams):
132-
with open(path, "r") as f:
131+
with open(path) as f:
133132
query = f.read()
134133
return self.bulk_query(query, *multiparams)
135134

records2/record.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21

32
from collections import OrderedDict
43

@@ -10,7 +9,7 @@ def _reduce_datetimes(row):
109
return row
1110

1211

13-
class Record(object):
12+
class Record:
1413
"""A row, from a query, from a database."""
1514

1615
__slots__ = ("_keys", "_values")
@@ -38,9 +37,9 @@ def __getitem__(self, key):
3837
if key in usekeys:
3938
i = usekeys.index(key)
4039
if usekeys.count(key) > 1:
41-
raise KeyError("Record contains multiple '{}' fields.".format(key))
40+
raise KeyError(f"Record contains multiple '{key}' fields.")
4241
return self.values()[i]
43-
raise KeyError("Record contains no '{}' field.".format(key))
42+
raise KeyError(f"Record contains no '{key}' field.")
4443

4544
def __getattr__(self, key):
4645
try:
@@ -74,7 +73,7 @@ def export(self, format, **kwargs):
7473
return self.dataset.export(format, **kwargs)
7574

7675

77-
class RecordCollection(object):
76+
class RecordCollection:
7877
"""A set of excellent Records from a query."""
7978

8079
def __init__(self, rows):
@@ -83,7 +82,7 @@ def __init__(self, rows):
8382
self.pending = True
8483

8584
def __repr__(self):
86-
return "<RecordCollection size={} pending={}>".format(len(self), self.pending)
85+
return f"<RecordCollection size={len(self)} pending={self.pending}>"
8786

8887
def __iter__(self):
8988
i = 0

records2/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21

32
from inspect import isclass
43

0 commit comments

Comments
 (0)