Skip to content

Commit

Permalink
ENH: Add static type checking
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jhlegarreta committed Dec 20, 2024
1 parent a58c265 commit 8baa17c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8baa17c

Please sign in to comment.