]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add slotscheck to CI
authorArie Bovenberg <a.c.bovenberg@gmail.com>
Sun, 6 Feb 2022 21:37:02 +0000 (16:37 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 7 Feb 2022 18:51:11 +0000 (13:51 -0500)
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

.github/workflows/run-on-pr.yaml
.github/workflows/run-test.yaml
lib/sqlalchemy/util/_has_cy.py
lib/sqlalchemy/util/_py_collections.py
pyproject.toml
tox.ini

index 94db88ba0a275acbcb311d4f6d919ba9ed5acee7..45f62d772c654cb2a832c41df6cdc79a01a82519 100644 (file)
@@ -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:
index 196e3c1b15ae9ac18ad74ef47751b53b8f4a3fb4..677721d7a6152c11e2f098eac622a710b38f01de 100644 (file)
@@ -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 }}
index bf251b5b57843fb6815153c7ff26a747f7039fa9..b09338f21eb347fa1c242f9e5418c82084749401 100644 (file)
@@ -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
index fd149d5bb465af78f5f358372117c5db9a286847..9bf5c3546d4812471c986a40fcc67e5d0941a219 100644 (file)
@@ -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__)
 
index 042bab6bfff86463a88cf79fd14b6bbdfaae923b..1006ad78c082f29af4689b8ac365ce589e320336 100644 (file)
@@ -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 3e0c3496f197e441631f0b414cd6e37650294f6d..b2a7a154d946aac586dce8ad7a95cce5a64daada 100644 (file)
--- 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.