Debian Codegraph @

testing/web-platform/tests/tools/third_party/attrs/.github/CONTRIBUTING.md

raw
1 # How To Contribute
2
3 Thank you for considering contributing to *attrs*!
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/python-attrs/attrs/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 ## Support
15
16 In case you'd like to help out but don't want to deal with GitHub, there's a great opportunity:
17 help your fellow developers on [Stack Overflow](https://stackoverflow.com/questions/tagged/python-attrs)!
18
19 The official tag is `python-attrs` and helping out in support frees us up to improve *attrs* instead!
20
21
22 ## Workflow
23
24 - No contribution is too small!
25 Please submit as many fixes for typos and grammar bloopers as you can!
26 - Try to limit each pull request to *one* change only.
27 - Since we squash on merge, it's up to you how you handle updates to the `main` branch.
28 Whether you prefer to rebase on `main` or merge `main` into your branch, do whatever is more comfortable for you.
29 - *Always* add tests and docs for your code.
30 This is a hard rule; patches with missing tests or documentation won't be merged.
31 - Make sure your changes pass our [CI].
32 You won't get any feedback until it's green unless you ask for it.
33 - For the CI to pass, the coverage must be 100%.
34 If you have problems to test something, open anyway and ask for advice.
35 In some situations, we may agree to add an `# pragma: no cover`.
36 - Once you've addressed review feedback, make sure to bump the pull request with a short note, so we know you're done.
37 - Don’t break backwards-compatibility.
38
39
40 ## Local Development Environment
41
42 You can (and should) run our test suite using [*tox*].
43 However, you’ll probably want a more traditional environment as well.
44
45 First, create a [virtual environment](https://virtualenv.pypa.io/) so you don't break your system-wide Python installation.
46 We recommend using the Python version from the `.python-version-default` file in project's root directory.
47
48 If you're using [*direnv*](https://direnv.net), you can automate the creation of a virtual environment with the correct Python version by adding the following `.envrc` to the project root after you've cloned it to your computer:
49
50 ```bash
51 layout python python$(cat .python-version-default)
52 ```
53
54 If you're using tools that understand `.python-version` files like [*pyenv*](https://github.com/pyenv/pyenv) does, you can make it a link to the `.python-version-default` file.
55
56 ---
57
58 Then, [fork](https://github.com/python-attrs/attrs/fork) the repository on GitHub.
59
60 Clone the fork to your computer:
61
62 ```console
63 $ git clone [email protected]:<your-username>/attrs.git
64 ```
65
66 Or if you prefer to use Git via HTTPS:
67
68 ```console
69 $ git clone https://github.com/<your-username>/attrs.git
70 ```
71
72 Then add the *attrs* repository as *upstream* remote:
73
74 ```console
75 $ git remote add -t main -m main --tags upstream https://github.com/python-attrs/attrs.git
76 ```
77
78 The next step is to sync your local copy with the upstream repository:
79
80 ```console
81 $ git fetch upstream
82 ```
83
84 This is important to obtain eventually missing tags, which are needed to install the development version later on.
85 See [#1104](https://github.com/python-attrs/attrs/issues/1104) for more information.
86
87 Change into the newly created directory and after activating a virtual environment install an editable version of *attrs* along with its tests and docs requirements:
88
89 ```console
90 $ cd attrs
91 $ python -m pip install --upgrade pip wheel # PLEASE don't skip this step
92 $ python -m pip install -e '.[dev]'
93 ```
94
95 At this point,
96
97 ```console
98 $ python -m pytest
99 ```
100
101 should work and pass.
102 You can *significantly* speed up the test suite by passing `-n auto` to *pytest* which activates [*pytest-xdist*](https://github.com/pytest-dev/pytest-xdist) and takes advantage of all your CPU cores.
103
104 For documentation, you can use:
105
106 ```console
107 $ tox run -e docs-serve
108 ```
109
110 This will build the documentation, and then watch for changes and rebuild it whenever you save a file.
111
112 To just build the documentation and run doctests, use:
113
114 ```console
115 $ tox run -e docs
116 ```
117
118 You will find the built documentation in `docs/_build/html`.
119
120
121 ---
122
123 To file a pull request, create a new branch on top of the upstream repository's `main` branch:
124
125 ```console
126 $ git fetch upstream
127 $ git checkout -b my_topical_branch upstream/main
128 ```
129
130 Make your changes, push them to your fork (the remote *origin*):
131
132 ```console
133 $ git push -u origin
134 ```
135
136 and publish the PR in GitHub's web interface!
137
138 After your pull request is merged and the branch is no longer needed, delete it:
139
140 ```console
141 $ git checkout main
142 $ git push --delete origin my_topical_branch && git branch -D my_topical_branch
143 ```
144
145 Before starting to work on your next pull request, run the following command to sync your local repository with the remote *upstream*:
146
147 ```console
148 $ git fetch upstream -u main:main
149 ```
150
151 ---
152
153 To avoid committing code that violates our style guide, we strongly advise you to install [*pre-commit*] and its hooks:
154
155 ```console
156 $ pre-commit install
157 ```
158
159 This is not strictly necessary, because our [*tox*] file contains an environment that runs:
160
161 ```console
162 $ pre-commit run --all-files
163 ```
164
165 and our CI has integration with [pre-commit.ci](https://pre-commit.ci).
166 But it's way more comfortable to run it locally and *git* catching avoidable errors.
167
168
169 ## Code
170
171 - Obey [PEP 8](https://peps.python.org/pep-0008/) and [PEP 257](https://peps.python.org/pep-0257/).
172 We use the `"""`-on-separate-lines style for docstrings:
173
174 ```python
175 def func(x):
176 """
177 Do something.
178
179 :param str x: A very important parameter.
180
181 :rtype: str
182 """
183 ```
184 - If you add or change public APIs, tag the docstring using `.. versionadded:: 16.0.0 WHAT` or `.. versionchanged:: 16.2.0 WHAT`.
185 - We use [Ruff](https://github.com/astral-sh/ruff) to sort our imports, and we use [Black](https://github.com/psf/black) with line length of 79 characters to format our code.
186 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.
187 If you don't, [CI] will catch it for you – but that seems like a waste of your time!
188
189
190 ## Tests
191
192 - Write your asserts as `expected == actual` to line them up nicely:
193
194 ```python
195 x = f()
196
197 assert 42 == x.some_attribute
198 assert "foo" == x._a_private_attribute
199 ```
200
201 - To run the test suite, all you need is a recent [*tox*].
202 It will ensure the test suite runs with all dependencies against all Python versions just as it will in our [CI].
203 If you lack some Python versions, you can can always limit the environments like `tox run -e py38,py39`, or make it a non-failure using `tox run --skip-missing-interpreters`.
204
205 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.
206 - Write [good test docstrings](https://jml.io/pages/test-docstrings.html).
207 - To ensure new features work well with the rest of the system, they should be also added to our [*Hypothesis*](https://hypothesis.readthedocs.io/) testing strategy, which can be found in `tests/strategies.py`.
208 - If you've changed or added public APIs, please update our type stubs (files ending in `.pyi`).
209
210
211 ## Documentation
212
213 - Use [semantic newlines] in [reStructuredText](https://www.sphinx-doc.org/en/stable/usage/restructuredtext/basics.html) and [Markdown](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax) files (files ending in `.rst` and `.md`):
214
215 ```rst
216 This is a sentence.
217 This is another sentence.
218 ```
219
220 - 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:
221
222 ```rst
223 Last line of previous section.
224
225
226 Header of New Top Section
227 -------------------------
228
229 Header of New Section
230 ^^^^^^^^^^^^^^^^^^^^^
231
232 First line of new section.
233 ```
234
235 - If you add a new feature, demonstrate its awesomeness on the [examples page](https://github.com/python-attrs/attrs/blob/main/docs/examples.md)!
236
237
238 ### Changelog
239
240 If your change is noteworthy, there needs to be a changelog entry so our users can learn about it!
241
242 To avoid merge conflicts, we use the [*Towncrier*](https://pypi.org/project/towncrier) package to manage our changelog.
243 *towncrier* uses independent *Markdown* files for each pull request – so called *news fragments* – instead of one monolithic changelog file.
244 On release, those news fragments are compiled into our [`CHANGELOG.md`](https://github.com/python-attrs/attrs/blob/main/CHANGELOG.md).
245
246 You don't need to install *Towncrier* yourself, you just have to abide by a few simple rules:
247
248 - For each pull request, add a new file into `changelog.d` with a filename adhering to the `pr#.(change|deprecation|breaking).md` schema:
249 For example, `changelog.d/42.change.md` for a non-breaking change that is proposed in pull request #42.
250 - As with other docs, please use [semantic newlines] within news fragments.
251 - Wrap symbols like modules, functions, or classes into backticks so they are rendered in a `monospace font`.
252 - Wrap arguments into asterisks like in docstrings:
253 `Added new argument *an_argument*.`
254 - If you mention functions or other callables, add parentheses at the end of their names:
255 `attrs.func()` or `attrs.Class.method()`.
256 This makes the changelog a lot more readable.
257 - Prefer simple past tense or constructions with "now".
258 For example:
259
260 + Added `attrs.validators.func()`.
261 + `attrs.func()` now doesn't crash the Large Hadron Collider anymore when passed the *foobar* argument.
262 - If you want to reference multiple issues, copy the news fragment to another filename.
263 *Towncrier* will merge all news fragments with identical contents into one entry with multiple links to the respective pull requests.
264
265 Example entries:
266
267 ```md
268 Added `attrs.validators.func()`.
269 The feature really *is* awesome.
270 ```
271
272 or:
273
274 ```md
275 `attrs.func()` now doesn't crash the Large Hadron Collider anymore when passed the *foobar* argument.
276 The bug really *was* nasty.
277 ```
278
279 ---
280
281 `tox run -e changelog` will render the current changelog to the terminal if you have any doubts.
282
283
284 ## Governance
285
286 *attrs* is maintained by [team of volunteers](https://github.com/python-attrs) that is always open to new members that share our vision of a fast, lean, and magic-free library that empowers programmers to write better code with less effort.
287 If you'd like to join, just get a pull request merged and ask to be added in the very same pull request!
288
289 **The simple rule is that everyone is welcome to review/merge pull requests of others but nobody is allowed to merge their own code.**
290
291 [Hynek Schlawack] acts reluctantly as the [BDFL](https://en.wikipedia.org/wiki/Benevolent_dictator_for_life) and has the final say over design decisions.
292
293
294 [CI]: https://github.com/python-attrs/attrs/actions?query=workflow%3ACI
295 [Hynek Schlawack]: https://hynek.me/about/
296 [*pre-commit*]: https://pre-commit.com/
297 [*tox*]: https://tox.wiki/
298 [semantic newlines]: https://rhodesmill.org/brandon/2012/one-sentence-per-line/