Skip to content

Commit e7010a2

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. Take advantage of the commit to include running the spell checker in the check matrix. Documentation: https://mypy.readthedocs.io/en/stable/index.html
1 parent a58c265 commit e7010a2

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

.github/workflows/test.yml

Lines changed: 25 additions & 0 deletions
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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ test = [
7373
"pytest-env",
7474
"pytest-xdist >= 1.28"
7575
]
76+
types = [
77+
"pandas-stubs",
78+
"types-setuptools",
79+
"scipy-stubs",
80+
"types-PyYAML",
81+
"types-tqdm",
82+
"pytest",
83+
"microsoft-python-type-stubs @ git+https://github.com/microsoft/python-type-stubs.git",
84+
]
7685

7786
antsopt = [
7887
"ConfigSpace",
@@ -122,6 +131,15 @@ version-file = "src/nifreeze/_version.py"
122131
# Developer tool configurations
123132
#
124133

134+
[[tool.mypy.overrides]]
135+
module = [
136+
"nipype.*",
137+
"nilearn.*",
138+
"nitransforms.*",
139+
"seaborn",
140+
]
141+
ignore_missing_imports = true
142+
125143
[tool.ruff]
126144
line-length = 99
127145
target-version = "py310"

tox.ini

Lines changed: 9 additions & 0 deletions
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 nifreeze
57+
4958
[testenv:spellcheck]
5059
description = Check spelling
5160
labels = check

0 commit comments

Comments
 (0)