Skip to content

Commit b0981c3

Browse files
authored
Added documentation about installing pre-commit, as well as the default hooks. (#163)
1 parent 825119a commit b0981c3

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

docs/practices/precommit.rst

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,51 @@ Using pre-commit enables a quick check of your code before it's committed and ch
1010
by GitHub workflows. This cuts down on code feedback time, and allows for faster
1111
development. Additional documentation can be found `here <https://pre-commit.com/index.html>`_.
1212

13-
To configure pre-commit for your project, run the following command register
13+
To configure pre-commit for your project, run the following command to register
1414
pre-commit hooks with ``.git/hooks/pre-commit``.
1515

1616
.. code-block:: bash
1717
1818
pre-commit install
19+
20+
List of ``pre-commit`` hooks
21+
-----------------------------
22+
23+
The following is a list of pre-commit hooks that will be run each time you
24+
commit code locally. The configuration file that defines these hooks is called
25+
``.pre-commit-config.yaml``, you should feel free to update or remove any
26+
of these that are not useful for your project.
27+
28+
.. list-table:: Pre-commit hooks
29+
:widths: auto
30+
:header-rows: 1
31+
32+
* - **Hook name**
33+
- **Purpose**
34+
* - Check template version
35+
- Compare the current local template version against latest remote version and alert user if an update is recommended.
36+
* - Clear output from Jupyter notebooks
37+
- Clear output from Jupyter notebooks to avoid committing large binary files.
38+
* - Run unit tests
39+
- Run all unit tests that are discovered by pytest.
40+
* - Prevent main branch commits
41+
- Prevents accidental commits directly to the ``main`` (or ``master``) branches.
42+
* - Check for large files
43+
- Prevents committing very large files. The default file size threshold is 500kb and is configurable.
44+
* - Validate pyproject.toml
45+
- Verify pyproject.toml adheres to the required schema to avoid changes that would break the build.
46+
* - isort (python files in src/ and tests/)
47+
- Runs isort to sort and organize your python package imports. *(Optionally installed when project is created.)*
48+
* - pylint (python files in src/)
49+
- Runs pylint to enforce a particular code style on python files in the src/ directory. *(Optionally installed when project is created.)*
50+
* - pylint (python files in tests/)
51+
- Same as above, but for the tests/ directory. *(Optionally installed when project is created.)*
52+
* - black
53+
- Runs black to enforce a particular code style on python files in the src/ and tests/ directories. *(Optionally installed when project is created.)*
54+
* - mypy
55+
- Runs static type checking on python files in the src/ and tests/ directories. *(Optionally installed when project is created.)*
56+
* - Build documentation with Sphinx
57+
- Ensures that automatically generated documentation and, optionally, jupyter notebooks can be built successfully.
58+
59+
60+
Many other pre-commit hooks exist, a partial list can be found `here <https://pre-commit.com/hooks.html>`_.

docs/source/existing_project.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,15 @@ Use pre-commit
193193
..............
194194

195195
Install and use ``pre-commit``. It may seem annoying at first, but it will save
196-
you many cycles of "see a test fail on GitHub, make and push a change, hope the test passes".
196+
you many cycles of "see a test fail on GitHub, make and push a change, hope the
197+
test passes". Installation is easy!
197198

199+
.. code:: bash
200+
201+
>> pre-commit install
202+
203+
For more information about ``pre-commit`` including a list of the checks that
204+
will be run before each commit, check out :doc:`pre-commit <../practices/precommit>`.
198205

199206
Import sorting
200207
..............

docs/source/new_project.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ At this point, your new project is hydrated and ready for you to start coding. B
9090
Commit your new project locally
9191
-------------------------------------------------------------------------------
9292

93-
If you're interested in using pre-commit hooks to crosscheck your code before you commit it,
94-
now is a good time to set that up (it's just one command) - check out
95-
:doc:`pre-commit <../practices/precommit>`
96-
9793
Commit the project to your local version control like so to see the pre-commit checks run.
9894

9995
.. code-block:: bash
@@ -114,3 +110,18 @@ Create a new repository in GitHub: (`GitHub How-to <https://docs.github.com/en/g
114110
>> git push origin <local_branch_name>
115111
116112
Notice that when you create a PR in GitHub, a set of tests for Continuous Integration starts up to verify that the project can build successfully and that all the unit tests pass. Neato!
113+
114+
Install pre-commit
115+
----------------------------
116+
117+
Now that your project has been pushed to a GitHub remote repository, it's a good
118+
time to install ``pre-commit`` so that future commits will run a suite of checks
119+
before pushing code to the remote repository.
120+
Run the following command in your terminal.
121+
122+
.. code:: bash
123+
124+
>> pre-commit install
125+
126+
For more information about ``pre-commit`` including a list of the checks that
127+
will be run before each commit, please see :doc:`pre-commit <../practices/precommit>`.

0 commit comments

Comments
 (0)