From 8baa17c8e8f73a8b88c54c13a709bd530801e78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Fri, 20 Dec 2024 10:19:11 -0500 Subject: [PATCH] ENH: Add static type checking Add static type checking: use `mypy` to ensure that variable and function calls are using the appropriate types. Configure and run `mypy` checks in CI, including the spell checking. Documentation: https://mypy.readthedocs.io/en/stable/index.html --- .github/workflows/test.yml | 25 +++++++++++++++++++++++++ pyproject.toml | 16 ++++++++++++++++ tox.ini | 9 +++++++++ 3 files changed, 50 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0293c50..1aa2ca5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -84,3 +84,28 @@ jobs: with: files: cov.xml token: ${{ secrets.CODECOV_TOKEN }} + + checks: + runs-on: 'ubuntu-latest' + continue-on-error: true + strategy: + matrix: + check: ['spellcheck', 'typecheck'] + + steps: + - uses: actions/checkout@v4 + - name: Install the latest version of uv + uses: astral-sh/setup-uv@v4 + # Can remove this once there is a traits release that supports 3.13 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: 3.12 + - name: Install tox + run: uv tool install tox --with=tox-uv + - name: Show tox config + run: tox c + - name: Show tox config (this call) + run: tox c -e ${{ matrix.check }} + - name: Run check + run: tox -e ${{ matrix.check }} diff --git a/pyproject.toml b/pyproject.toml index 7cefdca..4c9c7a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,6 +73,12 @@ test = [ "pytest-env", "pytest-xdist >= 1.28" ] +types = [ + "pandas-stubs", + "scipy-stubs", + "pytest", + "microsoft-python-type-stubs @ git+https://github.com/microsoft/python-type-stubs.git", +] antsopt = [ "ConfigSpace", @@ -122,6 +128,16 @@ version-file = "src/nifreeze/_version.py" # Developer tool configurations # +[[tool.mypy.overrides]] +module = [ + "nipype.*", + "nilearn.*", + "nireports.*", + "nitransforms.*", + "seaborn", +] +ignore_missing_imports = true + [tool.ruff] line-length = 99 target-version = "py310" diff --git a/tox.ini b/tox.ini index 77371e1..a7c652e 100644 --- a/tox.ini +++ b/tox.ini @@ -46,6 +46,15 @@ extras = doc commands = make -C docs/ SPHINXOPTS="-W -v" BUILDDIR="$HOME/docs" OUTDIR="${CURBRANCH:-html}" html +[testenv:typecheck] +description = Run mypy type checking +labels = check +deps = + mypy +extras = types +commands = + mypy nireports + [testenv:spellcheck] description = Check spelling labels = check