|
| 1 | +# How To Contribute<sup>[1](#footnote-1)</sup> |
| 2 | + |
| 3 | +First off, thank you for considering contributing to `drf-user`! It's people |
| 4 | +like _you_ who make it such a great tool for everyone. |
| 5 | + |
| 6 | +This document intends to make contribution more accessible by codifying tribal |
| 7 | +knowledge and expectations. Don't be afraid to open half-finished PRs, and ask |
| 8 | +questions if something is unclear! |
| 9 | + |
| 10 | +## Workflow |
| 11 | + |
| 12 | +- No contribution is too small! Please submit as many fixes for typos and |
| 13 | + grammar bloopers as you can! |
| 14 | +- Try to limit each pull request to **_one_** change only. |
| 15 | +- Since we squash on merge, it's up to you how you handle updates to the master |
| 16 | + branch. Whether you prefer to rebase on master or merge master into your |
| 17 | + branch, do whatever is more comfortable for you. |
| 18 | +- _Always_ add tests and docs for your code. This is a hard rule; patches with |
| 19 | +missing tests or documentation will not be merged. |
| 20 | +<!-- * Make sure your changes pass our [CI](https://github.com/101loop/drf-user/actions?query=workflow%3ACI). You won't get any feedback until it's green unless you ask for it. --> |
| 21 | +- Once you've addressed review feedback, make sure to bump the pull request with |
| 22 | + a short note, so we know you're done. |
| 23 | +- Avoid breaking backwards compatibility. |
| 24 | + |
| 25 | +## Code |
| 26 | + |
| 27 | +- Obey [PEP 8](https://www.python.org/dev/peps/pep-0008/), |
| 28 | + [PEP 257](https://www.python.org/dev/peps/pep-0257/), and the |
| 29 | + [Google Python Style Guide](http://google.github.io/styleguide/pyguide.html) |
| 30 | + (mostly)<sup>[2](#footnote-2)</sup>. We use |
| 31 | + [restructuredtext](https://docutils.sourceforge.io/rst.html) syntax, and have |
| 32 | + a summary line starting the `"""` block: |
| 33 | + |
| 34 | + ```python |
| 35 | + def func(x): |
| 36 | + """Do something. |
| 37 | +
|
| 38 | + Maybe some more "something" context that can span |
| 39 | + multiple lines. |
| 40 | +
|
| 41 | + :param str x: A very important parameter. |
| 42 | + :rtype: str |
| 43 | + """ |
| 44 | + ``` |
| 45 | + |
| 46 | +- We follow |
| 47 | +[reorder_python_imports](https://github.com/asottile/reorder_python_imports) for |
| 48 | +sorting our imports. Similar to [isort](https://github.com/timothycrosley/isort) |
| 49 | +but uses static analysis more, and we follow the |
| 50 | +[Black](https://github.com/psf/black) code style with a line length of 88 |
| 51 | +characters. |
| 52 | +<!-- As long as you run our full tox suite before committing, or install our [pre-commit](https://pre-commit.com/) hooks (ideally you'll do both -- see [Local Development Environment](#local-development-environment)), you won't have to spend any time on formatting your code at all. If you don't, CI will catch it for you -- but that seems like a waste of your time! --> |
| 53 | + |
| 54 | +## Tests |
| 55 | + |
| 56 | +- Write your asserts as `expected == actual` to line them up nicely: |
| 57 | + |
| 58 | + ```python |
| 59 | + |
| 60 | + x = f() |
| 61 | + |
| 62 | + assert 42 == x.some_attribute |
| 63 | + assert "foo" == x._a_private_attribute |
| 64 | + ``` |
| 65 | + |
| 66 | +<!-- * To run the test suite, all you need is a recent [tox](https://tox.readthedocs.io/). It will ensure the test suite runs with all dependencies against all Python versions just as it will in our CI. If you lack some Python versions, you can can always limit the environments like ``tox -e py35,py36`` (in that case you may want to look into [pyenv](https://github.com/pyenv/pyenv), which makes it very easy to install many different Python versions in parallel). --> |
| 67 | + |
| 68 | +- Write [good test docstrings](https://jml.io/pages/test-docstrings.html). |
| 69 | + |
| 70 | +## Documentation |
| 71 | + |
| 72 | +Project-related documentation is written in |
| 73 | +[restructuredtext](https://docutils.sourceforge.io/rst.html) (`.rst`). |
| 74 | +GitHub-related project documentation (e.g. this file you're reading, |
| 75 | +`CONTRIBUTING.md`) is written in Markdown, as GitHub doesn't support `.rst` |
| 76 | +files for some of their features (e.g. automatically picking up the |
| 77 | +`CODE_OF_CONDUCT.md`) |
| 78 | + |
| 79 | +- If you start a new section, add two blank lines before and one blank line |
| 80 | + after the header, except if two headers follow immediately after each other: |
| 81 | + |
| 82 | + ```rst |
| 83 | + Last line of previous section. |
| 84 | +
|
| 85 | + Header of New Top Section |
| 86 | + ------------------------- |
| 87 | +
|
| 88 | + Header of New Section |
| 89 | + ^^^^^^^^^^^^^^^^^^^^^ |
| 90 | +
|
| 91 | + First line of new section. |
| 92 | + ``` |
| 93 | + |
| 94 | +- If you add a new feature, demonstrate its awesomeness under `usage.rst`! |
| 95 | + |
| 96 | +## Local Development Environment |
| 97 | + |
| 98 | +<!-- You can (and should) run our test suite using [tox](https://tox.readthedocs.io/). However, you’ll probably want a more traditional environment as well. We highly recommend to develop using the latest Python 3 release because `interrogate` tries to take advantage of modern features whenever possible. --> |
| 99 | + |
| 100 | +First create a [virtual environment](https://virtualenv.pypa.io/). It’s out of |
| 101 | +scope for this document to list all the ways to manage virtual environments in |
| 102 | +Python, but if you don’t already have a pet way, take some time to look at tools |
| 103 | +like [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv), |
| 104 | +[pew](https://github.com/berdario/pew), |
| 105 | +[virtualfish](https://virtualfish.readthedocs.io/), |
| 106 | +[virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/), and |
| 107 | +[pyenv-virtualenvwrapper](https://github.com/pyenv/pyenv-virtualenvwrapper). |
| 108 | + |
| 109 | +Next, get an up to date checkout of the `drf-user` repository: |
| 110 | + |
| 111 | +```sh |
| 112 | +$ git clone [email protected]:101loop/drf-user.git |
| 113 | +``` |
| 114 | + |
| 115 | +or if you want to use git via `https`: |
| 116 | + |
| 117 | +```sh |
| 118 | +$ git clone https://github.com/101loop/drf-user.git |
| 119 | +``` |
| 120 | + |
| 121 | +<!-- Change into the newly created directory and **after activating your virtual environment** install an editable version of `interrogate` along with its tests and docs requirements: |
| 122 | +
|
| 123 | +```sh |
| 124 | +(env) $ cd drf-user |
| 125 | +(env) $ pip install -e '.[dev]' |
| 126 | +``` |
| 127 | +
|
| 128 | +At this point, |
| 129 | +
|
| 130 | +```sh |
| 131 | +(env) $ python -m pytest |
| 132 | +``` |
| 133 | +
|
| 134 | +should work and pass, as should: |
| 135 | +
|
| 136 | +```sh |
| 137 | +(env) $ cd docs |
| 138 | +(env) $ make livehtml |
| 139 | +``` |
| 140 | +
|
| 141 | +The built documentation can then be found in [`localhost:8888`](http://localhost:8888). |
| 142 | +
|
| 143 | +To avoid committing code that violates our style guide, we advise you to install |
| 144 | +[pre-commit](https://pre-commit.com/) hooks: |
| 145 | +
|
| 146 | +```sh |
| 147 | +(env) $ pre-commit install |
| 148 | +``` |
| 149 | +
|
| 150 | +You can also run them anytime (as our `tox` does, but always run `tox` outside |
| 151 | +of a virtual environment): |
| 152 | +
|
| 153 | +```sh |
| 154 | +(env) $ pre-commit run --all-files |
| 155 | +``` |
| 156 | +--> |
| 157 | + |
| 158 | +Install your local copy into a virtualenv. Assuming you have already created |
| 159 | +virtualenv, this is how you set up your fork for local development: |
| 160 | + |
| 161 | +```sh |
| 162 | +(env) $ cd drf-user |
| 163 | +(env) $ make install |
| 164 | +``` |
| 165 | + |
| 166 | +Create a branch for local development: |
| 167 | + |
| 168 | +```sh |
| 169 | +$ git checkout -b name-of-your-bugfix-or-feature |
| 170 | +``` |
| 171 | + |
| 172 | +Now you can make your changes locally. |
| 173 | + |
| 174 | +When you're done making changes, check that your changes pass tests and code |
| 175 | +style should be aligned with Flake8 and Black: |
| 176 | + |
| 177 | +```sh |
| 178 | +$ make test-coverage |
| 179 | +$ make lint |
| 180 | +$ make format |
| 181 | +``` |
| 182 | + |
| 183 | +Commit your changes and push your branch to GitHub: |
| 184 | + |
| 185 | +```sh |
| 186 | +$ git add . |
| 187 | +$ git commit -m "Your detailed description of your changes." |
| 188 | +$ git push origin name-of-your-bugfix-or-feature |
| 189 | +``` |
| 190 | + |
| 191 | +Submit a pull request through the GitHub website. |
| 192 | + |
| 193 | +## Code of Conduct |
| 194 | + |
| 195 | +Please note that this project is released with a Contributor |
| 196 | +[Code of Conduct](https://github.com/101loop/drf-user/blob/master/CODE_OF_CONDUCT.md). |
| 197 | +By participating in this project you agree to abide by its terms. Please report |
| 198 | +any harm to `devs [at] 101loop.com` for anything you find appropriate. |
| 199 | + |
| 200 | +Thank you for considering contributing to `drf-user`! |
| 201 | + |
| 202 | +--- |
| 203 | + |
| 204 | +<a name="footnote-1">1</a>: This contribution guide has been taken from |
| 205 | +[interrogate](https://github.com/econchick/interrogate/). |
| 206 | + |
| 207 | +<a name="footnote-2">2</a>: Do to personal preference, this project differs from |
| 208 | +Google's style guide in a few ways: |
| 209 | + |
| 210 | +- Instead of using Google's approach for documenting |
| 211 | + [arguments, return/yields, and raises](http://google.github.io/styleguide/pyguide.html#383-functions-and-methods), |
| 212 | + use [restructuredtext](https://docutils.sourceforge.io/rst.html) syntax as |
| 213 | + recommended by [PEP-0258](https://www.python.org/dev/peps/pep-0258/). |
| 214 | +- Instead of |
| 215 | + [using `pylint`](http://google.github.io/styleguide/pyguide.html#21-lint), use |
| 216 | + [flake8](https://flake8.pycqa.org/en/latest/). |
| 217 | +- Instead of |
| 218 | + [using yapf](http://google.github.io/styleguide/pyguide.html#1-background), |
| 219 | + use [Black](https://github.com/psf/black). |
0 commit comments