summaryrefslogtreecommitdiffstats
path: root/CONTRIBUTING.md
diff options
context:
space:
mode:
Diffstat (limited to 'CONTRIBUTING.md')
-rw-r--r--CONTRIBUTING.md190
1 files changed, 190 insertions, 0 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 00000000..671a43fe
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,190 @@
1# Submitting Changes
2
3Here's a short overview of the process.
4
5* Make small logical changes.
6* [Provide a meaningful commit message][commit-message-style].
7* Make sure all code is under the Apache License, 2.0.
8* Publish your changes for review.
9 * `git push origin HEAD:refs/for/main`
10* Make corrections if requested.
11* [Verify your changes on Gerrit.](#verify)
12* [Send to the commit queue for testing & merging.](#cq)
13
14[TOC]
15
16## Long Version
17
18I wanted a file describing how to submit patches for repo,
19so I started with the one found in the core Git distribution
20(Documentation/SubmittingPatches), which itself was based on the
21patch submission guidelines for the Linux kernel.
22
23However there are some differences, so please review and familiarize
24yourself with the following relevant bits.
25
26
27## Make separate commits for logically separate changes.
28
29Unless your patch is really trivial, you should not be sending out a patch that
30was generated between your working tree and your commit head.
31Instead, always make a commit with a complete
32[commit message][commit-message-style] and generate a series of patches from
33your repository.
34It is a good discipline.
35
36Describe the technical detail of the change(s).
37
38If your description starts to get too long, that's a sign that you
39probably need to split up your commit to finer grained pieces.
40
41
42## Linting and formatting code
43
44Lint any changes by running:
45```sh
46$ tox -e lint -- file.py
47```
48
49And format with:
50```sh
51$ tox -e format -- file.py
52```
53
54Or format everything:
55```sh
56$ tox -e format
57```
58
59Repo uses [black](https://black.readthedocs.io/) with line length of 80 as its
60formatter and flake8 as its linter. Repo also follows
61[Google's Python Style Guide].
62
63There should be no new errors or warnings introduced.
64
65Warnings that cannot be avoided without going against the Google Style Guide
66may be suppressed inline individally using a `# noqa` comment as described
67in the [flake8 documentation].
68
69If there are many occurrences of the same warning, these may be suppressed for
70the entire project in the included `.flake8` file.
71
72[Google's Python Style Guide]: https://google.github.io/styleguide/pyguide.html
73[PEP 8]: https://www.python.org/dev/peps/pep-0008/
74[flake8 documentation]: https://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html#in-line-ignoring-errors
75
76## Running tests
77
78We use [pytest](https://pytest.org/) and [tox](https://tox.readthedocs.io/) for
79running tests. You should make sure to install those first.
80
81To run the full suite against all supported Python versions, simply execute:
82```sh
83$ tox -p auto
84```
85
86We have [`./run_tests`](./run_tests) which is a simple wrapper around `pytest`:
87```sh
88# Run the full suite against the default Python version.
89$ ./run_tests
90# List each test as it runs.
91$ ./run_tests -v
92
93# Run a specific unittest module (and all tests in it).
94$ ./run_tests tests/test_git_command.py
95
96# Run a specific testsuite in a specific unittest module.
97$ ./run_tests tests/test_editor.py::EditString
98
99# Run a single test.
100$ ./run_tests tests/test_editor.py::EditString::test_cat_editor
101
102# List all available tests.
103$ ./run_tests --collect-only
104
105# Run a single test using substring match.
106$ ./run_tests -k test_cat_editor
107```
108
109The coverage isn't great currently, but it should still be run for all commits.
110Adding more unittests for changes you make would be greatly appreciated :).
111Check out the [tests/](./tests/) subdirectory for more details.
112
113
114## Check the license
115
116repo is licensed under the Apache License, 2.0.
117
118Because of this licensing model *every* file within the project
119*must* list the license that covers it in the header of the file.
120Any new contributions to an existing file *must* be submitted under
121the current license of that file. Any new files *must* clearly
122indicate which license they are provided under in the file header.
123
124Please verify that you are legally allowed and willing to submit your
125changes under the license covering each file *prior* to submitting
126your patch. It is virtually impossible to remove a patch once it
127has been applied and pushed out.
128
129
130## Sending your patches.
131
132Do not email your patches to anyone.
133
134Instead, login to the Gerrit Code Review tool at:
135
136 https://gerrit-review.googlesource.com/
137
138Ensure you have completed one of the necessary contributor
139agreements, providing documentation to the project maintainers that
140they have right to redistribute your work under the Apache License:
141
142 https://gerrit-review.googlesource.com/#/settings/agreements
143
144Ensure you have obtained an HTTP password to authenticate:
145
146 https://gerrit-review.googlesource.com/new-password
147
148Ensure that you have the local commit hook installed to automatically
149add a ChangeId to your commits:
150
151 curl -Lo `git rev-parse --git-dir`/hooks/commit-msg https://gerrit-review.googlesource.com/tools/hooks/commit-msg
152 chmod +x `git rev-parse --git-dir`/hooks/commit-msg
153
154If you have already committed your changes you will need to amend the commit
155to get the ChangeId added.
156
157 git commit --amend
158
159Push your patches over HTTPS to the review server, possibly through
160a remembered remote to make this easier in the future:
161
162 git config remote.review.url https://gerrit-review.googlesource.com/git-repo
163 git config remote.review.push HEAD:refs/for/main
164
165 git push review
166
167You will be automatically emailed a copy of your commits, and any
168comments made by the project maintainers.
169
170
171## Make changes if requested
172
173The project maintainer who reviews your changes might request changes to your
174commit. If you make the requested changes you will need to amend your commit
175and push it to the review server again.
176
177
178## Verify your changes on Gerrit {#verify}
179
180After you receive a Code-Review+2 from the maintainer, select the Verified
181button on the Gerrit page for the change. This verifies that you have tested
182your changes and notifies the maintainer that they are ready to be submitted.
183
184## Merge your changes via the commit queue {#cq}
185
186Once a change is ready to be merged, select the Commit-Queue+2 setting on the
187Gerrit page for it. This tells the CI system to test the change, and if it
188passes all the checks, automatically merges it.
189
190[commit-message-style]: https://chris.beams.io/posts/git-commit/