diff options
Diffstat (limited to 'CONTRIBUTING.md')
| -rw-r--r-- | CONTRIBUTING.md | 190 |
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 | |||
| 3 | Here'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 | |||
| 18 | I wanted a file describing how to submit patches for repo, | ||
| 19 | so I started with the one found in the core Git distribution | ||
| 20 | (Documentation/SubmittingPatches), which itself was based on the | ||
| 21 | patch submission guidelines for the Linux kernel. | ||
| 22 | |||
| 23 | However there are some differences, so please review and familiarize | ||
| 24 | yourself with the following relevant bits. | ||
| 25 | |||
| 26 | |||
| 27 | ## Make separate commits for logically separate changes. | ||
| 28 | |||
| 29 | Unless your patch is really trivial, you should not be sending out a patch that | ||
| 30 | was generated between your working tree and your commit head. | ||
| 31 | Instead, always make a commit with a complete | ||
| 32 | [commit message][commit-message-style] and generate a series of patches from | ||
| 33 | your repository. | ||
| 34 | It is a good discipline. | ||
| 35 | |||
| 36 | Describe the technical detail of the change(s). | ||
| 37 | |||
| 38 | If your description starts to get too long, that's a sign that you | ||
| 39 | probably need to split up your commit to finer grained pieces. | ||
| 40 | |||
| 41 | |||
| 42 | ## Linting and formatting code | ||
| 43 | |||
| 44 | Lint any changes by running: | ||
| 45 | ```sh | ||
| 46 | $ tox -e lint -- file.py | ||
| 47 | ``` | ||
| 48 | |||
| 49 | And format with: | ||
| 50 | ```sh | ||
| 51 | $ tox -e format -- file.py | ||
| 52 | ``` | ||
| 53 | |||
| 54 | Or format everything: | ||
| 55 | ```sh | ||
| 56 | $ tox -e format | ||
| 57 | ``` | ||
| 58 | |||
| 59 | Repo uses [black](https://black.readthedocs.io/) with line length of 80 as its | ||
| 60 | formatter and flake8 as its linter. Repo also follows | ||
| 61 | [Google's Python Style Guide]. | ||
| 62 | |||
| 63 | There should be no new errors or warnings introduced. | ||
| 64 | |||
| 65 | Warnings that cannot be avoided without going against the Google Style Guide | ||
| 66 | may be suppressed inline individally using a `# noqa` comment as described | ||
| 67 | in the [flake8 documentation]. | ||
| 68 | |||
| 69 | If there are many occurrences of the same warning, these may be suppressed for | ||
| 70 | the 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 | |||
| 78 | We use [pytest](https://pytest.org/) and [tox](https://tox.readthedocs.io/) for | ||
| 79 | running tests. You should make sure to install those first. | ||
| 80 | |||
| 81 | To run the full suite against all supported Python versions, simply execute: | ||
| 82 | ```sh | ||
| 83 | $ tox -p auto | ||
| 84 | ``` | ||
| 85 | |||
| 86 | We 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 | |||
| 109 | The coverage isn't great currently, but it should still be run for all commits. | ||
| 110 | Adding more unittests for changes you make would be greatly appreciated :). | ||
| 111 | Check out the [tests/](./tests/) subdirectory for more details. | ||
| 112 | |||
| 113 | |||
| 114 | ## Check the license | ||
| 115 | |||
| 116 | repo is licensed under the Apache License, 2.0. | ||
| 117 | |||
| 118 | Because of this licensing model *every* file within the project | ||
| 119 | *must* list the license that covers it in the header of the file. | ||
| 120 | Any new contributions to an existing file *must* be submitted under | ||
| 121 | the current license of that file. Any new files *must* clearly | ||
| 122 | indicate which license they are provided under in the file header. | ||
| 123 | |||
| 124 | Please verify that you are legally allowed and willing to submit your | ||
| 125 | changes under the license covering each file *prior* to submitting | ||
| 126 | your patch. It is virtually impossible to remove a patch once it | ||
| 127 | has been applied and pushed out. | ||
| 128 | |||
| 129 | |||
| 130 | ## Sending your patches. | ||
| 131 | |||
| 132 | Do not email your patches to anyone. | ||
| 133 | |||
| 134 | Instead, login to the Gerrit Code Review tool at: | ||
| 135 | |||
| 136 | https://gerrit-review.googlesource.com/ | ||
| 137 | |||
| 138 | Ensure you have completed one of the necessary contributor | ||
| 139 | agreements, providing documentation to the project maintainers that | ||
| 140 | they have right to redistribute your work under the Apache License: | ||
| 141 | |||
| 142 | https://gerrit-review.googlesource.com/#/settings/agreements | ||
| 143 | |||
| 144 | Ensure you have obtained an HTTP password to authenticate: | ||
| 145 | |||
| 146 | https://gerrit-review.googlesource.com/new-password | ||
| 147 | |||
| 148 | Ensure that you have the local commit hook installed to automatically | ||
| 149 | add 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 | |||
| 154 | If you have already committed your changes you will need to amend the commit | ||
| 155 | to get the ChangeId added. | ||
| 156 | |||
| 157 | git commit --amend | ||
| 158 | |||
| 159 | Push your patches over HTTPS to the review server, possibly through | ||
| 160 | a 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 | |||
| 167 | You will be automatically emailed a copy of your commits, and any | ||
| 168 | comments made by the project maintainers. | ||
| 169 | |||
| 170 | |||
| 171 | ## Make changes if requested | ||
| 172 | |||
| 173 | The project maintainer who reviews your changes might request changes to your | ||
| 174 | commit. If you make the requested changes you will need to amend your commit | ||
| 175 | and push it to the review server again. | ||
| 176 | |||
| 177 | |||
| 178 | ## Verify your changes on Gerrit {#verify} | ||
| 179 | |||
| 180 | After you receive a Code-Review+2 from the maintainer, select the Verified | ||
| 181 | button on the Gerrit page for the change. This verifies that you have tested | ||
| 182 | your changes and notifies the maintainer that they are ready to be submitted. | ||
| 183 | |||
| 184 | ## Merge your changes via the commit queue {#cq} | ||
| 185 | |||
| 186 | Once a change is ready to be merged, select the Commit-Queue+2 setting on the | ||
| 187 | Gerrit page for it. This tells the CI system to test the change, and if it | ||
| 188 | passes all the checks, automatically merges it. | ||
| 189 | |||
| 190 | [commit-message-style]: https://chris.beams.io/posts/git-commit/ | ||
