Skip to content

Commit 13bdb94

Browse files
committedApr 28, 2022
Add pre-commit description to contributing page
1 parent e8bd82e commit 13bdb94

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
 

‎CONTRIBUTING.rst

+66
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,69 @@ Development Guide
5353
Contributors should follow the recommendations made in the `SO Developer Guide`_.
5454

5555
.. _SO Developer Guide: https://simons1.princeton.edu/docs/so_dev_guide/
56+
57+
pre-commit
58+
``````````
59+
As a way to enforce development guide recommendations we have configured
60+
`pre-commit`_. While not required (yet), it is highly recommended you use this
61+
tool when contributing to socs. It will save both you and the reviewers time
62+
when submitting pull requests.
63+
64+
You should set this up before making and commiting your changes. To do so make
65+
sure the ``pre-commit`` package is installed (it is in ``requirements.txt``)::
66+
67+
$ pip install -r requirements.txt
68+
69+
Then run::
70+
71+
$ pre-commit install
72+
73+
This will install the configured git hooks and any dependencies. Now, whenever
74+
you commit the hooks will run. If there are issues you will see them in the
75+
output. This may automatically make changes to your staged files. These
76+
changes will be unstaged and need to be reviewed (typically with a ``git
77+
diff``), restaged, and recommitted. For example, if you have trailing
78+
whitespace on a line, pre-commit will prevent the commit and remove the
79+
whitespace. You will then stage the new changes with another ``git add <file>``
80+
and then re-run the commit. Here is the expected git output for this example:
81+
82+
.. code-block::
83+
84+
$ vim demo.py
85+
$ git status
86+
On branch koopman/test-pre-commit
87+
Changes not staged for commit:
88+
(use "git add <file>..." to update what will be committed)
89+
(use "git restore <file>..." to discard changes in working directory)
90+
modified: demo.py
91+
92+
no changes added to commit (use "git add" and/or "git commit -a")
93+
$ git add demo.py
94+
$ git commit
95+
Check python ast.........................................................Passed
96+
Fix End of Files.........................................................Passed
97+
Trim Trailing Whitespace.................................................Failed
98+
- hook id: trailing-whitespace
99+
- exit code: 1
100+
- files were modified by this hook
101+
102+
Fixing demo/demo.py
103+
104+
$ git status
105+
On branch koopman/test-pre-commit
106+
Changes to be committed:
107+
(use "git restore --staged <file>..." to unstage)
108+
modified: demo.py
109+
110+
Changes not staged for commit:
111+
(use "git add <file>..." to update what will be committed)
112+
(use "git restore <file>..." to discard changes in working directory)
113+
modified: demo.py
114+
$ git add -u
115+
$ git commit
116+
117+
**Note:** This is a new tool to this repo, and the flake8 output might still be
118+
somewhat strict. If there are warnings that you think should be ignored, please
119+
bring this up for discussion in a new issue.
120+
121+
.. _pre-commit: https://pre-commit.com/

0 commit comments

Comments
 (0)
Please sign in to comment.