Skip to content

Commit 12b99f9

Browse files
committed
DOC: Add docs for using and applying style/linting tools
1 parent 07100ea commit 12b99f9

File tree

1 file changed

+53
-15
lines changed

1 file changed

+53
-15
lines changed

doc/source/devel/devguide.rst

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,6 @@ advise that you enable merge summaries within git:
9595

9696
See :ref:`configure-git` for more detail.
9797

98-
Pre-commit hooks
99-
----------------
100-
101-
NiBabel uses pre-commit_ to help committers validate their changes
102-
before committing. To enable these, you can use pipx_::
103-
104-
pipx run pre-commit install
105-
106-
Or install and run::
107-
108-
python -m pip install pre-commit
109-
pre-commit install
110-
111-
11298
Testing
11399
=======
114100

@@ -139,6 +125,55 @@ full set of optional dependencies that are available for 64-bit
139125
interpreters. If you are using 32-bit Python, replace ``-x64`` with ``-x86``.
140126

141127

128+
Style guide
129+
===========
130+
131+
To ensure code consistency and readability, NiBabel has adopted the following
132+
tools:
133+
134+
* blue_ - An auto-formatter that aims to reduce diffs to relevant lines
135+
* isort_ - An import sorter that groups stdlib, third-party and local imports.
136+
* flake8_ - A style checker that can catch (but generally not fix) common
137+
errors in code.
138+
* codespell_ - A spell checker targeted at source code.
139+
* pre-commit_ - A pre-commit hook manager that runs the above and various
140+
other checks/fixes.
141+
142+
While some amount of personal preference is involved in selecting and
143+
configuring auto-formatters, their value lies in largely eliminating the
144+
need to think or argue about style.
145+
With pre-commit turned on, you can write in the style that works for you,
146+
and the NiBabel style will be adopted prior to the commit.
147+
148+
To apply our style checks uniformly, simply run::
149+
150+
tox -e style,spellcheck
151+
152+
To fix any issues found::
153+
154+
tox -e style-fix
155+
tox -e spellcheck -- -w
156+
157+
Occasionally, codespell has a false positive. To ignore the suggestion, add
158+
the intended word to ``tool.codespell.ignore-words-list`` in ``pyproject.toml``.
159+
However, the ignore list is a blunt instrument and could cause a legitimate
160+
misspelling to be missed. Consider choosing a word that does not trigger
161+
codespell before adding it to the ignore list.
162+
163+
Pre-commit hooks
164+
----------------
165+
166+
NiBabel uses pre-commit_ to help committers validate their changes
167+
before committing. To enable these, you can use pipx_::
168+
169+
pipx run pre-commit install
170+
171+
Or install and run::
172+
173+
python -m pip install pre-commit
174+
pre-commit install
175+
176+
142177
Changelog
143178
=========
144179

@@ -168,6 +203,9 @@ Please see `our community guidelines
168203
<https://github.com/nipy/nibabel/blob/master/.github/CODE_OF_CONDUCT.md>`_.
169204
Other projects call these guidelines the "code of conduct".
170205

171-
.. _tox: https://tox.wiki
206+
.. _blue: https://blue.readthedocs.io/
207+
.. _codespell: https://github.com/codespell-project/codespell
208+
.. _flake8: https://flake8.pycqa.org/
172209
.. _pipx: https://pypa.github.io/pipx/
173210
.. _precommit: https://pre-commit.com/
211+
.. _tox: https://tox.wiki/

0 commit comments

Comments
 (0)