|
| 1 | +# How To Contribute |
| 2 | + |
| 3 | +First off, thank you for considering contributing to *hatch-fancy-pypi-readme*! |
| 4 | +It's people like *you* who make it such a great tool for everyone. |
| 5 | + |
| 6 | +This document intends to make contribution more accessible by codifying tribal knowledge and expectations. |
| 7 | +Don't be afraid to open half-finished PRs, and ask questions if something is unclear! |
| 8 | + |
| 9 | +Please note that this project is released with a Contributor [Code of Conduct](https://github.com/hynek/hatch-fancy-pypi-readme/blob/main/.github/CODE_OF_CONDUCT.md). |
| 10 | +By participating in this project you agree to abide by its terms. |
| 11 | +Please report any harm to [Hynek Schlawack] in any way you find appropriate. |
| 12 | + |
| 13 | + |
| 14 | +## Workflow |
| 15 | + |
| 16 | +- No contribution is too small! |
| 17 | + Please submit as many fixes for typos and grammar bloopers as you can! |
| 18 | +- Try to limit each pull request to *one* change only. |
| 19 | +- Since we squash on merge, it's up to you how you handle updates to the main branch. |
| 20 | + Whether you prefer to rebase on main or merge main into your branch, do whatever is more comfortable for you. |
| 21 | +- *Always* add tests and docs for your code. |
| 22 | + This is a hard rule; patches with missing tests or documentation can't be merged. |
| 23 | +- Make sure your changes pass our [CI]. |
| 24 | + You won't get any feedback until it's green unless you ask for it. |
| 25 | + For the CI to pass, the coverage must be 100%. |
| 26 | + If you have problems to test something, open anyway and ask for advice. |
| 27 | + In some situations, we may agree to add an `# pragma: no cover`. |
| 28 | +- Once you've addressed review feedback, make sure to bump the pull request with a short note, so we know you're done. |
| 29 | +- Don’t break backwards-compatibility. |
| 30 | + |
| 31 | + |
| 32 | +## Local Development Environment |
| 33 | + |
| 34 | +You can (and should) run our test suite using [*tox*]. |
| 35 | +However, you’ll probably want a more traditional environment as well. |
| 36 | +We highly recommend to develop using the latest Python release because we try to take advantage of modern features whenever possible. |
| 37 | + |
| 38 | +First create a [virtual environment](https://virtualenv.pypa.io/) so you don't break your system-wide Python installation. |
| 39 | +It’s out of scope for this document to list all the ways to manage virtual environments in Python, but if you don’t already have a pet way, take some time to look at tools like [*direnv*](https://hynek.me/til/python-project-local-venvs/), [*virtualfish*](https://virtualfish.readthedocs.io/), and [*virtualenvwrapper*](https://virtualenvwrapper.readthedocs.io/). |
| 40 | + |
| 41 | +Next, get an up to date checkout of the *hatch-fancy-pypi-readme* repository: |
| 42 | + |
| 43 | +```console |
| 44 | +$ git clone git@github.com:hynek/hatch-fancy-pypi-readme.git |
| 45 | +``` |
| 46 | + |
| 47 | +or if you want to use git via `https`: |
| 48 | + |
| 49 | +```console |
| 50 | +$ git clone https://github.com/hynek/hatch-fancy-pypi-readme.git |
| 51 | +``` |
| 52 | + |
| 53 | +Change into the newly created directory and **after activating your virtual environment** install an editable version of *hatch-fancy-pypi-readme* along with its tests requirements: |
| 54 | + |
| 55 | +```console |
| 56 | +$ cd hatch-fancy-pypi-readme |
| 57 | +$ pip install --upgrade pip setuptools # PLEASE don't skip this step |
| 58 | +$ pip install -e '.[dev]' |
| 59 | +``` |
| 60 | + |
| 61 | +At this point, |
| 62 | + |
| 63 | +```console |
| 64 | +$ python -m pytest |
| 65 | +``` |
| 66 | + |
| 67 | +should work and pass. |
| 68 | + |
| 69 | +To avoid committing code that violates our style guide, we strongly advise you to install [*pre-commit*] and its hooks: |
| 70 | + |
| 71 | +```console |
| 72 | +$ pre-commit install |
| 73 | +``` |
| 74 | + |
| 75 | +This is not strictly necessary, because our [*tox*] file contains an environment that runs: |
| 76 | + |
| 77 | +```console |
| 78 | +$ pre-commit run --all-files |
| 79 | +``` |
| 80 | + |
| 81 | +But it's way more comfortable to run it locally and *git* catching avoidable errors. |
| 82 | + |
| 83 | + |
| 84 | +## Code |
| 85 | + |
| 86 | +- Obey [PEP 8](https://www.python.org/dev/peps/pep-0008/) and [PEP 257](https://www.python.org/dev/peps/pep-0257/). |
| 87 | + We use the `"""`-on-separate-lines style for docstrings: |
| 88 | + |
| 89 | + ```python |
| 90 | + def func(x): |
| 91 | + """ |
| 92 | + Do something. |
| 93 | +
|
| 94 | + :param str x: A very important parameter. |
| 95 | +
|
| 96 | + :rtype: str |
| 97 | + """ |
| 98 | + ``` |
| 99 | +- If you add or change public APIs, tag the docstring using `.. versionadded:: 16.0.0 WHAT` or `.. versionchanged:: 16.2.0 WHAT`. |
| 100 | +- We use [*isort*](https://github.com/PyCQA/isort) to sort our imports, and we use [*Black*](https://github.com/psf/black) with line length of 79 characters to format our code. |
| 101 | + As long as you run our full [*tox*] suite before committing, or install our [*pre-commit*] hooks (ideally you'll do both – see [*Local Development Environment*](#local-development-environment) above), you won't have to spend any time on formatting your code at all. |
| 102 | + If you don't, [CI] will catch it for you – but that seems like a waste of your time! |
| 103 | + |
| 104 | + |
| 105 | +## Tests |
| 106 | + |
| 107 | +- Write your asserts as `expected == actual` to line them up nicely: |
| 108 | + |
| 109 | + ```python |
| 110 | + x = f() |
| 111 | + |
| 112 | + assert 42 == x.some_attribute |
| 113 | + assert "foo" == x._a_private_attribute |
| 114 | + ``` |
| 115 | + |
| 116 | +- To run the test suite, all you need is a recent [*tox*]. |
| 117 | + It will ensure the test suite runs with all dependencies against all Python versions just as it will in our [CI]. |
| 118 | + If you lack some Python versions, you can can always limit the environments like `tox -e py38,py39`, or make it a non-failure using `tox --skip-missing-interpreters`. |
| 119 | + |
| 120 | + In that case you should look into [*asdf*](https://asdf-vm.com) or [*pyenv*](https://github.com/pyenv/pyenv), which make it very easy to install many different Python versions in parallel. |
| 121 | +- Write [good test docstrings](https://jml.io/pages/test-docstrings.html). |
| 122 | +- If you've changed or added public APIs, please update our type stubs (files ending in `.pyi`). |
| 123 | + |
| 124 | + |
| 125 | +## Documentation |
| 126 | + |
| 127 | +- Use [semantic newlines] in [*reStructuredText*] and *Markdown* files (files ending in `.rst` and `.md`): |
| 128 | + |
| 129 | + ```rst |
| 130 | + This is a sentence. |
| 131 | + This is another sentence. |
| 132 | + ``` |
| 133 | + |
| 134 | +- If you start a new section, add two blank lines before and one blank line after the header, except if two headers follow immediately after each other: |
| 135 | + |
| 136 | + ```rst |
| 137 | + Last line of previous section. |
| 138 | +
|
| 139 | +
|
| 140 | + Header of New Top Section |
| 141 | + ------------------------- |
| 142 | +
|
| 143 | + Header of New Section |
| 144 | + ^^^^^^^^^^^^^^^^^^^^^ |
| 145 | +
|
| 146 | + First line of new section. |
| 147 | + ``` |
| 148 | + |
| 149 | + |
| 150 | +### Changelog |
| 151 | + |
| 152 | +If your change is noteworthy, there needs to be a changelog entry in [`CHANGELOG.md`](https://github.com/hynek/hatch-fancy-pypi-readme/blob/main/CHANGELOG.md), so our users can learn about it! |
| 153 | + |
| 154 | +- The changelog follows the [*Keep a Changelog*](https://keepachangelog.com/en/1.0.0/) standard. |
| 155 | + Please add the best-fitting section if it's missing for the current release. |
| 156 | + We use the following order: `Security`, `Removed`, `Deprecated`, `Added`, `Changed`, `Fixed`. |
| 157 | +- As with other docs, please use [semantic newlines] in the changelog. |
| 158 | +- Make the last line a link to your pull request. |
| 159 | + You probably have to open the pull request first to know the number. |
| 160 | +- Wrap symbols like modules, functions, or classes into backticks so they are rendered in a `monospace font`. |
| 161 | +- Wrap arguments into asterisks like in docstrings: |
| 162 | + `Added new argument *an_argument*.` |
| 163 | +- If you mention functions or other callables, add parentheses at the end of their names: |
| 164 | + `hatch-fancy-pypi-readme.func()` or `hatch-fancy-pypi-readme.Class.method()`. |
| 165 | + This makes the changelog a lot more readable. |
| 166 | +- Prefer simple past tense or constructions with "now". |
| 167 | + For example: |
| 168 | + |
| 169 | + * Added `hatch-fancy-pypi-readme.func()`. |
| 170 | + * `hatch-fancy-pypi-readme.func()` now doesn't crash the Large Hadron Collider anymore when passed the *foobar* argument. |
| 171 | + |
| 172 | +#### Example entries |
| 173 | + |
| 174 | +```markdown |
| 175 | +- Added `hatch-fancy-pypi-readme.func()`. |
| 176 | + The feature really *is* awesome. |
| 177 | + [#1](https://github.com/hynek/hatch-fancy-pypi-readme/pull/1) |
| 178 | +``` |
| 179 | + |
| 180 | +or: |
| 181 | + |
| 182 | +```markdown |
| 183 | +- `hatch-fancy-pypi-readme.func()` now doesn't crash the Large Hadron Collider anymore when passed the *foobar* argument. |
| 184 | + The bug really *was* nasty. |
| 185 | + [#1](https://github.com/hynek/hatch-fancy-pypi-readme/pull/1) |
| 186 | +``` |
| 187 | + |
| 188 | + |
| 189 | +[CI]: https://github.com/hynek/hatch-fancy-pypi-readme/actions |
| 190 | +[Hynek Schlawack]: https://hynek.me/about/ |
| 191 | +[*pre-commit*]: https://pre-commit.com/ |
| 192 | +[*tox*]: https://https://tox.wiki/ |
| 193 | +[semantic newlines]: https://rhodesmill.org/brandon/2012/one-sentence-per-line/ |
| 194 | +[*reStructuredText*]: https://www.sphinx-doc.org/en/stable/usage/restructuredtext/basics.html |
0 commit comments