From f6714c8e090b9dd84ac4256ed74eefc1fe9cbddc Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 17 Nov 2025 16:32:54 -0500 Subject: [PATCH] update lint setup We are stuck on flake8 because we rely on many plugins with specific behaviors. The situation has calcified where: 1. the whole world uses ruff 2. nobody cares about import order linting or all the other stuff we do, and/or similar but not quite the same things are embedded deeply into ruff which would require us giving up a lot of our standards (like isort) 3. flake8 is absolutely never going to support pyproject. 4. flake8-pyproject works for this beyond that, for t string support we want to make it easy to get onto py3.14, so here we update black to the latest which appears to fix some missing symbols for py3.14 t strings. we should also migrate the remaining sqlalchemy test config from setup.cfg to pyproject.toml but that should likely be 2.1 only Change-Id: I896a7c839148d0ef516728c73baddc8eddf5ee96 --- .pre-commit-config.yaml | 4 +++- noxfile.py | 7 +++++-- pyproject.toml | 38 ++++++++++++++++++++++++++++++++++++-- setup.cfg | 31 ------------------------------- tox.ini | 12 ++++++++---- 5 files changed, 52 insertions(+), 40 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8d730ca2d4..eb11bc7a5b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/python/black - rev: 25.9.0 + rev: 25.11.0 hooks: - id: black @@ -15,7 +15,9 @@ repos: rev: 7.3.0 hooks: - id: flake8 + entry: python -m flake8p additional_dependencies: + - flake8-pyproject - flake8-import-order>=0.19.2 - flake8-import-single==0.1.5 - flake8-builtins diff --git a/noxfile.py b/noxfile.py index a548f44c9b..b025d08520 100644 --- a/noxfile.py +++ b/noxfile.py @@ -355,9 +355,12 @@ def test_pep8(session: nox.Session) -> None: session.install(*nox.project.dependency_groups(pyproject, "lint")) for cmd in [ - "flake8 ./lib/ ./test/ ./examples/ noxfile.py " + "flake8p ./lib/ ./test/ ./examples/ noxfile.py " "setup.py doc/build/conf.py", - "flake8 --extend-ignore='' ./lib/sqlalchemy/ext/asyncio " + # run "unused argument" lints on asyncio, as we have a lot of + # proxy methods here + "flake8p --ignore='' --select='U100,U101' " + "./lib/sqlalchemy/ext/asyncio " "./lib/sqlalchemy/orm/scoping.py", "black --check ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py", "slotscheck -m sqlalchemy", diff --git a/pyproject.toml b/pyproject.toml index c109841cbd..fda3fe9573 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -172,7 +172,8 @@ tests-mssql-asyncio = [ lint = [ {include-group = "tests-greenlet"}, - "flake8>=7.2.0", + "flake8>=7.3.0", + "flake8-pyproject", "flake8-import-order>=0.19.2", "flake8-import-single==0.1.5", "flake8-builtins", @@ -182,7 +183,7 @@ lint = [ "flake8-rst-docstrings", "pydocstyle<4.0.0", "pygments", - "black==25.9.0", + "black==25.11.0", "slotscheck>=0.17.0", "zimports>=0.6.3", # required by generate_tuple_map_overloads ] @@ -234,6 +235,39 @@ target-version = ['py310'] black-line-length = 79 +[tool.flake8] +show-source = false +enable-extensions = "G" + +# E203 is due to https://github.com/PyCQA/pycodestyle/issues/373 +ignore = [ + "A003","A005", + "D", + "E203","E305","E701","E704","E711","E712","E721","E722","E741", + "I300", + "N801","N802","N806", + "RST304","RST303","RST299","RST399", + "W503","W504","W601", + "U100","U101" +] + +exclude = [".venv",".git",".tox","dist","doc","*egg","build"] +import-order-style = "google" +application-import-names = ["sqlalchemy","test"] +per-file-ignores =[ + "**/__init__.py:F401", + "test/*:FA100", + "test/typing/plain_files/*:F821,E501,FA100", + "lib/sqlalchemy/events.py:F401", + "lib/sqlalchemy/schema.py:F401", + "lib/sqlalchemy/types.py:F401", + "lib/sqlalchemy/sql/expression.py:F401", + "lib/sqlalchemy/util/typing.py:F401" +] + +unused-arguments-ignore-stub-functions=true +unused-arguments-ignore-dunder=true + [tool.slotscheck] exclude-modules = ''' ^sqlalchemy\.testing diff --git a/setup.cfg b/setup.cfg index d66134a10f..4bbe7d0aab 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,34 +1,3 @@ -[flake8] -show-source = false -enable-extensions = G - -# E203 is due to https://github.com/PyCQA/pycodestyle/issues/373 -ignore = - A003,A005 - D, - E203,E305,E701,E704,E711,E712,E721,E722,E741, - I300, - N801,N802,N806, - RST304,RST303,RST299,RST399, - W503,W504,W601 -extend-ignore = - # keep in extend ignore so that they can be enabled in a subset of files in the tox run - U100,U101 -exclude = .venv,.git,.tox,dist,doc,*egg,build -import-order-style = google -application-import-names = sqlalchemy,test -per-file-ignores = - **/__init__.py:F401 - test/*:FA100 - test/typing/plain_files/*:F821,E501,FA100 - lib/sqlalchemy/events.py:F401 - lib/sqlalchemy/schema.py:F401 - lib/sqlalchemy/types.py:F401 - lib/sqlalchemy/sql/expression.py:F401 - lib/sqlalchemy/util/typing.py:F401 - -unused-arguments-ignore-stub-functions=true -unused-arguments-ignore-dunder=true [sqla_testing] requirement_cls = test.requirements:DefaultRequirements diff --git a/tox.ini b/tox.ini index a20bf25642..f59a600c86 100644 --- a/tox.ini +++ b/tox.ini @@ -249,6 +249,7 @@ extras= {[greenletextras]extras} deps= + flake8-pyproject flake8>=7.3.0 flake8-import-order>=0.19.2 flake8-builtins @@ -261,7 +262,7 @@ deps= # in case it requires a version pin pydocstyle pygments - black==25.9.0 + black==25.11.0 slotscheck>=0.17.0 # required by generate_tuple_map_overloads @@ -271,9 +272,12 @@ allowlist_externals = git sh commands = - flake8 ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py {posargs} - # run flake8-unused-arguments only on some files / modules - flake8 --extend-ignore='' ./lib/sqlalchemy/ext/asyncio ./lib/sqlalchemy/orm/scoping.py + flake8p ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py {posargs} + + # run "unused argument" lints on asyncio, as we have a lot of + # proxy methods here + flake8p --ignore='' --select='U100,U101' ./lib/sqlalchemy/ext/asyncio ./lib/sqlalchemy/orm/scoping.py + black --check ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py slotscheck -m sqlalchemy python ./tools/format_docs_code.py --check -- 2.47.3