Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
name: Python linting
on: [push, pull_request]
jobs:
test:
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']
python-version: ['3.13']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: pip install tox
- name: Run linting
run: tox -e flake8,isort
- name: Set up uv
uses: astral-sh/setup-uv@v3
- name: Set up Python
run: uv python install ${{ matrix.python-version }}
- name: Create virtual environment
run: uv venv
- name: Install dependencies
run: uv pip install -e ".[dev]"
- name: Run ruff check
run: uv run ruff check .
- name: Run ruff format check
run: uv run ruff format --check .
29 changes: 15 additions & 14 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ jobs:
- '3.10'
- '3.11'
- '3.12'
- '3.13'
tox_env: ['sqlalchemy14', 'sqlalchemy2']
#include:
# - os: 'ubuntu-20.04'
# python-version: '3.6'
# tox_env: 'sqlalchemy14'
runs-on: ${{ matrix.os }}
services:
postgres:
Expand Down Expand Up @@ -54,10 +51,12 @@ jobs:
- 1433:1433
steps:
- uses: actions/checkout@v4
- name: Set up uv
uses: astral-sh/setup-uv@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Create virtual environment
run: uv venv
- name: Install MS SQL stuff
run: bash .ci/install_mssql.sh
- name: Add hstore extension to the sqlalchemy_utils_test database
Expand All @@ -67,21 +66,23 @@ jobs:
PGPORT: 5432
run: psql -U postgres -d sqlalchemy_utils_test -c 'CREATE EXTENSION hstore;'
- name: Install tox
run: pip install tox
run: uv pip install tox
- name: Run tests
env:
SQLALCHEMY_UTILS_TEST_POSTGRESQL_PASSWORD: postgres
run: tox -e ${{ matrix.tox_env }}
run: uv run tox -e ${{ matrix.tox_env }}

docs:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v4
- name: Set up uv
uses: astral-sh/setup-uv@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
run: uv python install 3.13
- name: Create virtual environment
run: uv venv
- name: Install tox
run: pip install tox
run: uv pip install tox
- name: Build documentation
run: tox -e docs
run: uv run tox -e docs
6 changes: 0 additions & 6 deletions .isort.cfg

This file was deleted.

27 changes: 6 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,15 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.2
hooks:
- id: flake8

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort

# Allow tox to run isort as a linter.
- id: isort
alias: isort-check
args: [--check]
stages: [manual]

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py39-plus]
- id: ruff
args: [--fix]
- id: ruff-format
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ Unreleased changes

- Drop support for Python 3.7 and 3.8.
- Drop support for sqlalchemy 1.3.
- Add support for Python 3.12.
- Add support for Python 3.12 and 3.13.
- Add a Read the Docs configuration file.
- Make documentation builds reproducible.
- Test documentation builds in CI.
- Fix Pendulum parsing of datetime instances with timezones. (#755)
- Migrate to `uv <https://docs.astral.sh/uv/>`_ for dependency management and package installation, improving build performance and reproducibility. (#780)
- Migrate to `ruff <https://docs.astral.sh/ruff/>`_ for code linting and formatting, replacing flake8 with a faster Rust-based tool. (#780)

0.41.2 (2024-03-22)
^^^^^^^^^^^^^^^^^^^
Expand Down
43 changes: 19 additions & 24 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
from sqlalchemy.orm import declarative_base, sessionmaker, synonym_for
from sqlalchemy.orm.session import close_all_sessions

from sqlalchemy_utils import (
aggregates,
coercion_listener,
i18n,
InstrumentedList
)
from sqlalchemy_utils import aggregates, coercion_listener, i18n, InstrumentedList
from sqlalchemy_utils.functions.orm import _get_class_registry
from sqlalchemy_utils.types.pg_composite import remove_composite_listeners

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


def get_locale():
class Locale():
class Locale:
territories = {'FI': 'Finland'}

return Locale()
Expand Down Expand Up @@ -66,13 +61,11 @@ def mysql_db_user():


@pytest.fixture
def postgresql_dsn(postgresql_db_user, postgresql_db_password, postgresql_db_host,
db_name):
def postgresql_dsn(
postgresql_db_user, postgresql_db_password, postgresql_db_host, db_name
):
return 'postgresql://{}:{}@{}/{}'.format(
postgresql_db_user,
postgresql_db_password,
postgresql_db_host,
db_name
postgresql_db_user, postgresql_db_password, postgresql_db_host, db_name
)


Expand Down Expand Up @@ -103,21 +96,24 @@ def mssql_db_user():

@pytest.fixture
def mssql_db_password():
return os.environ.get('SQLALCHEMY_UTILS_TEST_MSSQL_PASSWORD',
'Strong_Passw0rd')
return os.environ.get('SQLALCHEMY_UTILS_TEST_MSSQL_PASSWORD', 'Strong_Passw0rd')


@pytest.fixture
def mssql_db_driver():
driver = os.environ.get('SQLALCHEMY_UTILS_TEST_MSSQL_DRIVER',
'ODBC Driver 18 for SQL Server')
driver = os.environ.get(
'SQLALCHEMY_UTILS_TEST_MSSQL_DRIVER', 'ODBC Driver 18 for SQL Server'
)
return driver.replace(' ', '+')


@pytest.fixture
def mssql_dsn(mssql_db_user, mssql_db_password, mssql_db_driver, db_name):
return 'mssql+pyodbc://{}:{}@localhost/{}?driver={}&TrustServerCertificate=yes'\
.format(mssql_db_user, mssql_db_password, db_name, mssql_db_driver)
return (
'mssql+pyodbc://{}:{}@localhost/{}?driver={}&TrustServerCertificate=yes'.format(
mssql_db_user, mssql_db_password, db_name, mssql_db_driver
)
)


@pytest.fixture
Expand Down Expand Up @@ -158,12 +154,12 @@ class User(Base):
__tablename__ = 'user'
id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
name = sa.Column(sa.Unicode(255))

return User


@pytest.fixture
def Category(Base):

class Category(Base):
__tablename__ = 'category'
id = sa.Column(sa.Integer, primary_key=True)
Expand Down Expand Up @@ -200,6 +196,7 @@ def name_alias(self):
@property
def name_synonym(self):
return self.name

return Category


Expand All @@ -214,11 +211,9 @@ class Article(Base):
category = sa.orm.relationship(
Category,
primaryjoin=category_id == Category.id,
backref=sa.orm.backref(
'articles',
collection_class=InstrumentedList
)
backref=sa.orm.backref('articles', collection_class=InstrumentedList),
)

return Article


Expand Down
132 changes: 132 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
[build-system]
requires = ["setuptools>=45", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "SQLAlchemy-Utils"
version = "0.42.0"
description = "Various utility functions for SQLAlchemy."
readme = "README.rst"
license = {text = "BSD"}
authors = [
{name = "Konsta Vesterinen", email = "konsta@fastmonkeys.com"},
{name = "Ryan Leckey"},
{name = "Janne Vanhala"},
{name = "Vesa Uimonen"}
]
requires-python = ">=3.9"
classifiers = [
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [
"SQLAlchemy>=1.4",
]

[project.urls]
Homepage = "https://github.com/kvesteri/sqlalchemy-utils"

[project.optional-dependencies]
test = [
"pytest==7.4.4",
"Pygments>=1.2",
"Jinja2>=2.3",
"docutils>=0.10",
"flexmock>=0.9.7",
"psycopg>=3.1.8",
"psycopg2>=2.5.1",
"psycopg2cffi>=2.8.1",
"pg8000>=1.12.4",
"pytz>=2014.2",
"python-dateutil>=2.6",
"backports.zoneinfo;python_version<\"3.9\"",
"pymysql",
"flake8>=2.4.0",
"isort>=4.2.2",
"pyodbc",
]
babel = ["Babel>=1.3"]
arrow = ["arrow>=0.3.4"]
pendulum = ["pendulum>=2.0.5"]
intervals = ["intervals>=0.7.1"]
phone = ["phonenumbers>=5.9.2"]
password = ["passlib >= 1.6, < 2.0"]
color = ["colour>=0.0.4"]
timezone = ["python-dateutil"]
url = ["furl >= 0.4.1"]
encrypted = ["cryptography>=0.6"]
test_all = [
"pytest==7.4.4",
"Pygments>=1.2",
"Jinja2>=2.3",
"docutils>=0.10",
"flexmock>=0.9.7",
"psycopg>=3.1.8",
"psycopg2>=2.5.1",
"psycopg2cffi>=2.8.1",
"pg8000>=1.12.4",
"pytz>=2014.2",
"python-dateutil>=2.6",
"backports.zoneinfo;python_version<\"3.9\"",
"pymysql",
"flake8>=2.4.0",
"isort>=4.2.2",
"pyodbc",
"Babel>=1.3",
"arrow>=0.3.4",
"pendulum>=2.0.5",
"intervals>=0.7.1",
"phonenumbers>=5.9.2",
"passlib >= 1.6, < 2.0",
"colour>=0.0.4",
"python-dateutil",
"furl >= 0.4.1",
"cryptography>=0.6",
]
dev = [
"ruff>=0.12.0",
"tox>=4.0.0",
"pre-commit>=4.2.0",
]

[tool.ruff]
exclude = [
".eggs",
".git",
".tox",
".venv",
"__pycache__",
"build",
"dist",
"docs",
"migrations",
"tests",
"venv",
]

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F"]
ignore = ["E231", "E402", "E702", "E501", "F403", "F541", "E713"]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"tests/*" = ["F401", "F811"]

[tool.ruff.lint.isort]
known-first-party = ["sqlalchemy_utils"]

[tool.ruff.format]
quote-style = "single"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
Loading