nipy / nibabel

Python package to access a cacophony of neuro-imaging file formats
http://nipy.org/nibabel/
Other
649 stars 258 forks source link

TYP: Add a version stub to allow mypy to run without building #1210

Closed effigies closed 1 year ago

effigies commented 1 year ago

Thanks to @Factral in https://github.com/nipy/nibabel/pull/1208#issuecomment-1447182785 I realized that we could probably make the contribution process a little nicer to people not wanting to pip install -e or hatch build --hooks-only just to make the pre-commit hooks run cleanly.

This adds a _version.pyi that mypy will respect without even checking whether _version.py is present.

The biggest potential risk is setuptools-scm changing the contents of _version.py in the future, but that seems low and a thing we can deal with if it comes up.

No need to backport unless we get contributors to a maintenance branch.

Verifying: ```console ~/Projects/nipy ❯ git clone nibabel/.git nibabel-mypy-test Cloning into 'nibabel-mypy-test'... done. ~/Projects/nipy ❯ cd nibabel-mypy-test nibabel-mypy-test on typ/version_stub ❯ pre-commit install pre-commit installed at .git/hooks/pre-commit nibabel-mypy-test on typ/version_stub ❯ pre-commit run --all trim trailing whitespace.................................................Passed fix end of files.........................................................Passed check yaml...............................................................Passed check json...............................................................Passed check toml...............................................................Passed check for added large files..............................................Passed check for case conflicts.................................................Passed check for merge conflicts................................................Passed check vcs permalinks.....................................................Passed blue.....................................................................Passed isort....................................................................Passed flake8...................................................................Passed mypy.....................................................................Passed ``` Reverting to `master`: ```console ❯ git checkout master Branch 'master' set up to track remote branch 'master' from 'origin'. Switched to a new branch 'master' nibabel-mypy-test on master ❯ pre-commit run --all trim trailing whitespace.................................................Passed fix end of files.........................................................Passed check yaml...............................................................Passed check json...............................................................Passed check toml...............................................................Passed check for added large files..............................................Passed check for case conflicts.................................................Passed check for merge conflicts................................................Passed check vcs permalinks.....................................................Passed blue.....................................................................Passed isort....................................................................Passed flake8...................................................................Passed mypy.....................................................................Failed - hook id: mypy - exit code: 1 nibabel/pkg_info.py:9: error: Cannot find implementation or library stub for module named "nibabel._version" [import] nibabel/pkg_info.py:9: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports Found 1 error in 1 file (checked 107 source files) ```
codecov[bot] commented 1 year ago

Codecov Report

Patch coverage has no change and project coverage change: +0.08 :tada:

Comparison is base (3a4cc5e) 92.06% compared to head (cf43308) 92.14%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1210 +/- ## ========================================== + Coverage 92.06% 92.14% +0.08% ========================================== Files 97 97 Lines 12334 12334 Branches 2534 2534 ========================================== + Hits 11355 11365 +10 + Misses 655 647 -8 + Partials 324 322 -2 ``` | [Impacted Files](https://codecov.io/gh/nipy/nibabel/pull/1210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nipy) | Coverage Δ | | |---|---|---| | [nibabel/spatialimages.py](https://codecov.io/gh/nipy/nibabel/pull/1210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nipy#diff-bmliYWJlbC9zcGF0aWFsaW1hZ2VzLnB5) | `94.06% <0.00%> (+0.91%)` | :arrow_up: | | [nibabel/nicom/ascconv.py](https://codecov.io/gh/nipy/nibabel/pull/1210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nipy#diff-bmliYWJlbC9uaWNvbS9hc2Njb252LnB5) | `90.12% <0.00%> (+2.46%)` | :arrow_up: | | [nibabel/testing/\_\_init\_\_.py](https://codecov.io/gh/nipy/nibabel/pull/1210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nipy#diff-bmliYWJlbC90ZXN0aW5nL19faW5pdF9fLnB5) | `98.18% <0.00%> (+2.72%)` | :arrow_up: | | [nibabel/\_\_init\_\_.py](https://codecov.io/gh/nipy/nibabel/pull/1210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nipy#diff-bmliYWJlbC9fX2luaXRfXy5weQ==) | `100.00% <0.00%> (+3.17%)` | :arrow_up: | | [nibabel/pydicom\_compat.py](https://codecov.io/gh/nipy/nibabel/pull/1210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nipy#diff-bmliYWJlbC9weWRpY29tX2NvbXBhdC5weQ==) | `88.23% <0.00%> (+5.88%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nipy). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nipy)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.