Skip to content

Commit 247b299

Browse files
Migrate to uv and ruff
1 parent e2cbc08 commit 247b299

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1655
-819
lines changed

.github/workflows/lint.yaml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
name: Python linting
22
on: [push, pull_request]
33
jobs:
4-
test:
4+
lint:
55
name: Lint
66
runs-on: ubuntu-latest
77
strategy:
88
matrix:
9-
python-version: ['3.11']
9+
python-version: ['3.13']
1010
steps:
1111
- uses: actions/checkout@v4
12-
- uses: actions/setup-python@v5
13-
with:
14-
python-version: ${{ matrix.python-version }}
15-
- name: Install tox
16-
run: pip install tox
17-
- name: Run linting
18-
run: tox -e flake8,isort
12+
- name: Set up uv
13+
uses: astral-sh/setup-uv@v3
14+
- name: Set up Python
15+
run: uv python install ${{ matrix.python-version }}
16+
- name: Create virtual environment
17+
run: uv venv
18+
- name: Install dependencies
19+
run: uv pip install -e ".[dev]"
20+
- name: Run ruff check
21+
run: uv run ruff check .
22+
- name: Run ruff format check
23+
run: uv run ruff format --check .

.github/workflows/test.yaml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ jobs:
1111
- '3.10'
1212
- '3.11'
1313
- '3.12'
14+
- '3.13'
1415
tox_env: ['sqlalchemy14', 'sqlalchemy2']
15-
#include:
16-
# - os: 'ubuntu-20.04'
17-
# python-version: '3.6'
18-
# tox_env: 'sqlalchemy14'
1916
runs-on: ${{ matrix.os }}
2017
services:
2118
postgres:
@@ -54,10 +51,12 @@ jobs:
5451
- 1433:1433
5552
steps:
5653
- uses: actions/checkout@v4
54+
- name: Set up uv
55+
uses: astral-sh/setup-uv@v3
5756
- name: Set up Python
58-
uses: actions/setup-python@v5
59-
with:
60-
python-version: ${{ matrix.python-version }}
57+
run: uv python install ${{ matrix.python-version }}
58+
- name: Create virtual environment
59+
run: uv venv
6160
- name: Install MS SQL stuff
6261
run: bash .ci/install_mssql.sh
6362
- name: Add hstore extension to the sqlalchemy_utils_test database
@@ -67,21 +66,23 @@ jobs:
6766
PGPORT: 5432
6867
run: psql -U postgres -d sqlalchemy_utils_test -c 'CREATE EXTENSION hstore;'
6968
- name: Install tox
70-
run: pip install tox
69+
run: uv pip install tox
7170
- name: Run tests
7271
env:
7372
SQLALCHEMY_UTILS_TEST_POSTGRESQL_PASSWORD: postgres
74-
run: tox -e ${{ matrix.tox_env }}
73+
run: uv run tox -e ${{ matrix.tox_env }}
7574

7675
docs:
7776
runs-on: 'ubuntu-latest'
7877
steps:
7978
- uses: actions/checkout@v4
79+
- name: Set up uv
80+
uses: astral-sh/setup-uv@v3
8081
- name: Set up Python
81-
uses: actions/setup-python@v5
82-
with:
83-
python-version: '3.12'
82+
run: uv python install 3.13
83+
- name: Create virtual environment
84+
run: uv venv
8485
- name: Install tox
85-
run: pip install tox
86+
run: uv pip install tox
8687
- name: Build documentation
87-
run: tox -e docs
88+
run: uv run tox -e docs

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Unreleased changes
1313
- Make documentation builds reproducible.
1414
- Test documentation builds in CI.
1515
- Fix Pendulum parsing of datetime instances with timezones. (#755)
16+
- Migrate to `uv <https://docs.astral.sh/uv/>`_ for dependency management and package installation, improving build performance and reproducibility. (#780)
17+
- Migrate to `ruff <https://docs.astral.sh/ruff/>`_ for code linting and formatting, replacing flake8 with a faster Rust-based tool. (#780)
1618

1719
0.41.2 (2024-03-22)
1820
^^^^^^^^^^^^^^^^^^^

conftest.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@
1010
from sqlalchemy.orm import declarative_base, sessionmaker, synonym_for
1111
from sqlalchemy.orm.session import close_all_sessions
1212

13-
from sqlalchemy_utils import (
14-
aggregates,
15-
coercion_listener,
16-
i18n,
17-
InstrumentedList
18-
)
13+
from sqlalchemy_utils import aggregates, coercion_listener, i18n, InstrumentedList
1914
from sqlalchemy_utils.functions.orm import _get_class_registry
2015
from sqlalchemy_utils.types.pg_composite import remove_composite_listeners
2116

@@ -34,7 +29,7 @@ def count_sql_calls(conn, cursor, statement, parameters, context, executemany):
3429

3530

3631
def get_locale():
37-
class Locale():
32+
class Locale:
3833
territories = {'FI': 'Finland'}
3934

4035
return Locale()
@@ -66,13 +61,11 @@ def mysql_db_user():
6661

6762

6863
@pytest.fixture
69-
def postgresql_dsn(postgresql_db_user, postgresql_db_password, postgresql_db_host,
70-
db_name):
64+
def postgresql_dsn(
65+
postgresql_db_user, postgresql_db_password, postgresql_db_host, db_name
66+
):
7167
return 'postgresql://{}:{}@{}/{}'.format(
72-
postgresql_db_user,
73-
postgresql_db_password,
74-
postgresql_db_host,
75-
db_name
68+
postgresql_db_user, postgresql_db_password, postgresql_db_host, db_name
7669
)
7770

7871

@@ -103,21 +96,24 @@ def mssql_db_user():
10396

10497
@pytest.fixture
10598
def mssql_db_password():
106-
return os.environ.get('SQLALCHEMY_UTILS_TEST_MSSQL_PASSWORD',
107-
'Strong_Passw0rd')
99+
return os.environ.get('SQLALCHEMY_UTILS_TEST_MSSQL_PASSWORD', 'Strong_Passw0rd')
108100

109101

110102
@pytest.fixture
111103
def mssql_db_driver():
112-
driver = os.environ.get('SQLALCHEMY_UTILS_TEST_MSSQL_DRIVER',
113-
'ODBC Driver 18 for SQL Server')
104+
driver = os.environ.get(
105+
'SQLALCHEMY_UTILS_TEST_MSSQL_DRIVER', 'ODBC Driver 18 for SQL Server'
106+
)
114107
return driver.replace(' ', '+')
115108

116109

117110
@pytest.fixture
118111
def mssql_dsn(mssql_db_user, mssql_db_password, mssql_db_driver, db_name):
119-
return 'mssql+pyodbc://{}:{}@localhost/{}?driver={}&TrustServerCertificate=yes'\
120-
.format(mssql_db_user, mssql_db_password, db_name, mssql_db_driver)
112+
return (
113+
'mssql+pyodbc://{}:{}@localhost/{}?driver={}&TrustServerCertificate=yes'.format(
114+
mssql_db_user, mssql_db_password, db_name, mssql_db_driver
115+
)
116+
)
121117

122118

123119
@pytest.fixture
@@ -158,12 +154,12 @@ class User(Base):
158154
__tablename__ = 'user'
159155
id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
160156
name = sa.Column(sa.Unicode(255))
157+
161158
return User
162159

163160

164161
@pytest.fixture
165162
def Category(Base):
166-
167163
class Category(Base):
168164
__tablename__ = 'category'
169165
id = sa.Column(sa.Integer, primary_key=True)
@@ -200,6 +196,7 @@ def name_alias(self):
200196
@property
201197
def name_synonym(self):
202198
return self.name
199+
203200
return Category
204201

205202

@@ -214,11 +211,9 @@ class Article(Base):
214211
category = sa.orm.relationship(
215212
Category,
216213
primaryjoin=category_id == Category.id,
217-
backref=sa.orm.backref(
218-
'articles',
219-
collection_class=InstrumentedList
220-
)
214+
backref=sa.orm.backref('articles', collection_class=InstrumentedList),
221215
)
216+
222217
return Article
223218

224219

pyproject.toml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
[build-system]
2+
requires = ["setuptools>=45", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "SQLAlchemy-Utils"
7+
version = "0.42.0"
8+
description = "Various utility functions for SQLAlchemy."
9+
readme = "README.rst"
10+
license = {text = "BSD"}
11+
authors = [
12+
{name = "Konsta Vesterinen", email = "konsta@fastmonkeys.com"},
13+
{name = "Ryan Leckey"},
14+
{name = "Janne Vanhala"},
15+
{name = "Vesa Uimonen"}
16+
]
17+
requires-python = ">=3.9"
18+
classifiers = [
19+
"Environment :: Web Environment",
20+
"Intended Audience :: Developers",
21+
"License :: OSI Approved :: BSD License",
22+
"Operating System :: OS Independent",
23+
"Programming Language :: Python",
24+
"Programming Language :: Python :: 3.9",
25+
"Programming Language :: Python :: 3.10",
26+
"Programming Language :: Python :: 3.11",
27+
"Programming Language :: Python :: 3.12",
28+
"Programming Language :: Python :: 3.13",
29+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
30+
"Topic :: Software Development :: Libraries :: Python Modules",
31+
]
32+
dependencies = [
33+
"SQLAlchemy>=1.4",
34+
]
35+
36+
[project.urls]
37+
Homepage = "https://github.com/kvesteri/sqlalchemy-utils"
38+
39+
[project.optional-dependencies]
40+
test = [
41+
"pytest==7.4.4",
42+
"Pygments>=1.2",
43+
"Jinja2>=2.3",
44+
"docutils>=0.10",
45+
"flexmock>=0.9.7",
46+
"psycopg>=3.1.8",
47+
"psycopg2>=2.5.1",
48+
"psycopg2cffi>=2.8.1",
49+
"pg8000>=1.12.4",
50+
"pytz>=2014.2",
51+
"python-dateutil>=2.6",
52+
"backports.zoneinfo;python_version<\"3.9\"",
53+
"pymysql",
54+
"flake8>=2.4.0",
55+
"isort>=4.2.2",
56+
"pyodbc",
57+
]
58+
babel = ["Babel>=1.3"]
59+
arrow = ["arrow>=0.3.4"]
60+
pendulum = ["pendulum>=2.0.5"]
61+
intervals = ["intervals>=0.7.1"]
62+
phone = ["phonenumbers>=5.9.2"]
63+
password = ["passlib >= 1.6, < 2.0"]
64+
color = ["colour>=0.0.4"]
65+
timezone = ["python-dateutil"]
66+
url = ["furl >= 0.4.1"]
67+
encrypted = ["cryptography>=0.6"]
68+
test_all = [
69+
"pytest==7.4.4",
70+
"Pygments>=1.2",
71+
"Jinja2>=2.3",
72+
"docutils>=0.10",
73+
"flexmock>=0.9.7",
74+
"psycopg>=3.1.8",
75+
"psycopg2>=2.5.1",
76+
"psycopg2cffi>=2.8.1",
77+
"pg8000>=1.12.4",
78+
"pytz>=2014.2",
79+
"python-dateutil>=2.6",
80+
"backports.zoneinfo;python_version<\"3.9\"",
81+
"pymysql",
82+
"flake8>=2.4.0",
83+
"isort>=4.2.2",
84+
"pyodbc",
85+
"Babel>=1.3",
86+
"arrow>=0.3.4",
87+
"pendulum>=2.0.5",
88+
"intervals>=0.7.1",
89+
"phonenumbers>=5.9.2",
90+
"passlib >= 1.6, < 2.0",
91+
"colour>=0.0.4",
92+
"python-dateutil",
93+
"furl >= 0.4.1",
94+
"cryptography>=0.6",
95+
]
96+
dev = [
97+
"ruff>=0.1.0",
98+
"tox>=4.0.0",
99+
]
100+
101+
[tool.ruff]
102+
exclude = [
103+
".eggs",
104+
".git",
105+
".tox",
106+
".venv",
107+
"__pycache__",
108+
"build",
109+
"dist",
110+
"docs",
111+
"migrations",
112+
"tests",
113+
"venv",
114+
]
115+
116+
[tool.ruff.lint]
117+
select = ["E4", "E7", "E9", "F"]
118+
ignore = ["E231", "E402", "E702", "E501", "F403", "F541", "E713"]
119+
120+
[tool.ruff.lint.per-file-ignores]
121+
"__init__.py" = ["F401"]
122+
"tests/*" = ["F401", "F811"]
123+
124+
[tool.ruff.lint.isort]
125+
known-first-party = ["sqlalchemy_utils"]
126+
127+
[tool.ruff.format]
128+
quote-style = "single"
129+
indent-style = "space"
130+
skip-magic-trailing-comma = false
131+
line-ending = "auto"

setup.cfg

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

0 commit comments

Comments
 (0)