From: Arie Bovenberg Date: Sun, 6 Feb 2022 21:37:02 +0000 (-0500) Subject: add slotscheck to CI X-Git-Tag: rel_2_0_0b1~495^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38cdd3946c337f3d917218cd1c8da67a971646ee;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git add slotscheck to CI As discussed in #7589, `slotscheck` can prevent slots-related mistakes from creeping back in. Plan for now is to have slotscheck part of the "lint" tests (renamed from pep8) that will run for CI and github actions. To support slotscheck's runtime nature, slotscheck is run twice, first with cython exts enabled and then with them disabled via new environment variable. Also added sqlalchemy[mypy] dependency to support slots checking the mypy plugin. Found and fixed one more `__slots__` issue by disabling C exts. Closes: #7670 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7670 Pull-request-sha: 3e77fe5449615a3c7c61ce9a1e4e79cd6636a89a Change-Id: I90cdd284cdcee316a38856ba94d72ffc98947c5a --- diff --git a/.github/workflows/run-on-pr.yaml b/.github/workflows/run-on-pr.yaml index 94db88ba0a..45f62d772c 100644 --- a/.github/workflows/run-on-pr.yaml +++ b/.github/workflows/run-on-pr.yaml @@ -84,8 +84,8 @@ jobs: - name: Run tests run: tox -e mypy ${{ matrix.pytest-args }} - run-pep8: - name: pep8-${{ matrix.python-version }} + run-lint: + name: lint-${{ matrix.python-version }} runs-on: ${{ matrix.os }} strategy: # run this job using this matrix, excluding some combinations below. @@ -115,7 +115,7 @@ jobs: pip list - name: Run tests - run: tox -e pep8 + run: tox -e lint # Arm emulation is quite slow (~20min) so for now just run it when merging to main # run-test-arm64: diff --git a/.github/workflows/run-test.yaml b/.github/workflows/run-test.yaml index 196e3c1b15..677721d7a6 100644 --- a/.github/workflows/run-test.yaml +++ b/.github/workflows/run-test.yaml @@ -156,8 +156,8 @@ jobs: - name: Run tests run: tox -e mypy ${{ matrix.pytest-args }} - run-pep8: - name: pep8-${{ matrix.python-version }} + run-lint: + name: lint-${{ matrix.python-version }} runs-on: ${{ matrix.os }} strategy: # run this job using this matrix, excluding some combinations below. @@ -187,7 +187,7 @@ jobs: pip list - name: Run tests - run: tox -e pep8 + run: tox -e lint run-pep484: name: pep484-${{ matrix.python-version }} diff --git a/lib/sqlalchemy/util/_has_cy.py b/lib/sqlalchemy/util/_has_cy.py index bf251b5b57..b09338f21e 100644 --- a/lib/sqlalchemy/util/_has_cy.py +++ b/lib/sqlalchemy/util/_has_cy.py @@ -1,11 +1,15 @@ +import os import typing if not typing.TYPE_CHECKING: - try: - from ..cyextension import util # noqa - except ImportError: + if os.environ.get("DISABLE_SQLALCHEMY_CEXT_RUNTIME"): HAS_CYEXTENSION = False else: - HAS_CYEXTENSION = True + try: + from ..cyextension import util # noqa + except ImportError: + HAS_CYEXTENSION = False + else: + HAS_CYEXTENSION = True else: HAS_CYEXTENSION = False diff --git a/lib/sqlalchemy/util/_py_collections.py b/lib/sqlalchemy/util/_py_collections.py index fd149d5bb4..9bf5c3546d 100644 --- a/lib/sqlalchemy/util/_py_collections.py +++ b/lib/sqlalchemy/util/_py_collections.py @@ -18,6 +18,8 @@ _VT = TypeVar("_VT", bound=Any) class ImmutableContainer: + __slots__ = () + def _immutable(self, *arg: Any, **kw: Any) -> NoReturn: raise TypeError("%s object is immutable" % self.__class__.__name__) diff --git a/pyproject.toml b/pyproject.toml index 042bab6bff..1006ad78c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,9 @@ line-length = 79 target-version = ['py37'] +[tool.slotscheck] +exclude-modules = '^sqlalchemy\.testing' + [tool.pytest.ini_options] addopts = "--tb native -v -r sfxX --maxfail=250 -p warnings -p logging --strict-markers" diff --git a/tox.ini b/tox.ini index 3e0c3496f1..b2a7a154d9 100644 --- a/tox.ini +++ b/tox.ini @@ -151,7 +151,7 @@ commands = pytest -m mypy {posargs} # thanks to https://julien.danjou.info/the-best-flake8-extensions/ -[testenv:pep8] +[testenv:lint] basepython = python3 deps= flake8 @@ -164,9 +164,28 @@ deps= pydocstyle pygments black==21.12b0 + slotscheck>=0.12,<0.13 + + # this is to satisfy the mypy plugin dependency + # when slotscheck imports sqlalchemy.mypy modules + sqlalchemy[mypy] +allowlist_externals = + env commands = flake8 ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py {posargs} black --check ./lib/ ./test/ ./examples/ setup.py doc/build/conf.py + # test with cython and without cython exts running + slotscheck -m sqlalchemy + env DISABLE_SQLALCHEMY_CEXT_RUNTIME=1 slotscheck -m sqlalchemy + + +# "pep8" env was renamed to "lint". +# Kept for backwards compatibility until rename is completed elsewhere. +[testenv:pep8] +basepython = {[testenv:lint]basepython} +deps = {[testenv:lint]deps} +allowlist_externals = {[testenv:lint]allowlist_externals} +commands = {[testenv:lint]commands} # command run in the github action when cext are active.