Skip to content

Commit fc46f6a

Browse files
committed
Move pre-commit information to formatting
1 parent cc181c0 commit fc46f6a

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

doc/user_guide/features/formatting_code/index.rst

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,36 @@ deterministic manner.
4040
| | | need to be re-formatted |
4141
+--------------------+------------------+------------------------------------+
4242

43-
`pre-commit`
43+
.. _pre_commit:
44+
45+
pre-commit
4446
++++++++++++
4547

46-
.. _formatting_configuration:
48+
`Pre-commit <https://pre-commit.com/>` is a framework that automatically runs
49+
configurable checks and fixes on code before Git commits and pushes.
50+
Included in the cookiecutter project template is a ``.pre-commit-config.yaml``, which
51+
uses the formatting :ref:`formatting_sessions`. For information on configuring and
52+
setting it up see :ref:`pre-commit_configuration`.
53+
54+
Once it's ready to use, the process is:
55+
56+
#. Make your code changes
57+
#. ``git add -u`` and ``git commit -m "<message>"``
58+
#. pre-commit performs checks on the changed files and produces an output like
4759

48-
TODO
60+
.. code-block:: bash
61+
62+
code-format..........................................(no files to check)Skipped
63+
check yaml...........................................(no files to check)Skipped
64+
fix end of files.........................................................Passed
65+
trim trailing whitespace.................................................Passed
66+
67+
* If all steps pass, then no action is needed.
68+
* If a step fails, then check the output further. If it was an automatic fix, then
69+
just add the altered file to your commit and execute your ``git commit`` line again.
70+
Otherwise, you will need to take on manual intervention.
71+
72+
.. _formatting_configuration:
4973

5074
Configuration
5175
+++++++++++++
@@ -74,6 +98,24 @@ Ensure ``isort`` is configured with compatibility for ``black``:
7498
For further configuration options, see
7599
`isort options <https://pycqa.github.io/isort/docs/configuration/options.html>`__.
76100

101+
.. _pre-commit_configuration:
102+
103+
pre-commit
104+
^^^^^^^^^^
105+
#. Add a :code:`.pre-commit-config.yaml` file to your project root
106+
107+
Feel free to get some inspiration from the Python toolbox itself:
108+
109+
.. literalinclude:: ../../../../project-template/{{cookiecutter.repo_name}}/.pre-commit-config.yaml
110+
:language: yaml
111+
112+
#. Enable pre-commit hooks for your workspace
113+
114+
.. code-block:: shell
115+
116+
poetry run -- pre-commit install --hook-type pre-commit --hook-type pre-push
117+
118+
77119
pyupgrade
78120
^^^^^^^^^
79121
No initial configuration of ``pyupgrade`` is required.

doc/user_guide/getting_started.rst

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,7 @@ straightforward, and you just can use the example ``noxfile.py`` below.
134134
5. Set up the pre-commit hooks [optional]
135135
+++++++++++++++++++++++++++++++++++++++++
136136

137-
#. Add a :code:`.pre-commit-config.yaml` file to your project root
138-
139-
If you want to reuse Nox sessions in the pre-commit hooks, feel free to get some inspiration from the Python toolbox itself:
140-
141-
.. literalinclude:: ../../project-template/{{cookiecutter.repo_name}}/.pre-commit-config.yaml
142-
:language: yaml
143-
144-
#. Enable pre-commit hooks for your workspace
145-
146-
.. code-block:: shell
147-
148-
poetry run -- pre-commit install --hook-type pre-commit --hook-type pre-push
137+
See :ref:`pre-commit_configuration` for the required steps.
149138

150139

151140
6. Set up deploying documentation (optional)

0 commit comments

Comments
 (0)