Skip to content

Commit 8baa17c

Browse files
committed
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
1 parent a58c265 commit 8baa17c

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

.github/workflows/test.yml

+25
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,28 @@ jobs:
8484
with:
8585
files: cov.xml
8686
token: ${{ secrets.CODECOV_TOKEN }}
87+
88+
checks:
89+
runs-on: 'ubuntu-latest'
90+
continue-on-error: true
91+
strategy:
92+
matrix:
93+
check: ['spellcheck', 'typecheck']
94+
95+
steps:
96+
- uses: actions/checkout@v4
97+
- name: Install the latest version of uv
98+
uses: astral-sh/setup-uv@v4
99+
# Can remove this once there is a traits release that supports 3.13
100+
- name: Set up Python ${{ matrix.python-version }}
101+
uses: actions/setup-python@v5
102+
with:
103+
python-version: 3.12
104+
- name: Install tox
105+
run: uv tool install tox --with=tox-uv
106+
- name: Show tox config
107+
run: tox c
108+
- name: Show tox config (this call)
109+
run: tox c -e ${{ matrix.check }}
110+
- name: Run check
111+
run: tox -e ${{ matrix.check }}

pyproject.toml

+16
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ test = [
7373
"pytest-env",
7474
"pytest-xdist >= 1.28"
7575
]
76+
types = [
77+
"pandas-stubs",
78+
"scipy-stubs",
79+
"pytest",
80+
"microsoft-python-type-stubs @ git+https://github.com/microsoft/python-type-stubs.git",
81+
]
7682

7783
antsopt = [
7884
"ConfigSpace",
@@ -122,6 +128,16 @@ version-file = "src/nifreeze/_version.py"
122128
# Developer tool configurations
123129
#
124130

131+
[[tool.mypy.overrides]]
132+
module = [
133+
"nipype.*",
134+
"nilearn.*",
135+
"nireports.*",
136+
"nitransforms.*",
137+
"seaborn",
138+
]
139+
ignore_missing_imports = true
140+
125141
[tool.ruff]
126142
line-length = 99
127143
target-version = "py310"

tox.ini

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ extras = doc
4646
commands =
4747
make -C docs/ SPHINXOPTS="-W -v" BUILDDIR="$HOME/docs" OUTDIR="${CURBRANCH:-html}" html
4848

49+
[testenv:typecheck]
50+
description = Run mypy type checking
51+
labels = check
52+
deps =
53+
mypy
54+
extras = types
55+
commands =
56+
mypy nireports
57+
4958
[testenv:spellcheck]
5059
description = Check spelling
5160
labels = check

0 commit comments

Comments
 (0)