@@ -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
5074Configuration
5175+++++++++++++
@@ -74,6 +98,24 @@ Ensure ``isort`` is configured with compatibility for ``black``:
7498For 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^^^^^^^^^
79121No initial configuration of ``pyupgrade `` is required.
0 commit comments