Debian Codegraph @

docs/contributing.rst

raw
1 Contributing
2 ============
3
4 urllib3 is a community-maintained project and we happily accept contributions.
5
6 If you wish to add a new feature or fix a bug:
7
8 #. `Check for open issues <https://github.com/urllib3/urllib3/issues>`_ or open
9 a fresh issue to start a discussion around a feature idea or a bug. There is
10 a *Contributor Friendly* tag for issues that should be ideal for people who
11 are not very familiar with the codebase yet.
12 #. Check for `open pull requests <https://github.com/urllib3/urllib3/pulls>`_
13 addressing the same issue before starting work. We encourage you to share
14 feedback and suggestions in the existing pull request and issue. Duplicate
15 pull requests for the same issue, including alternative solutions, will be
16 rejected without review unless a maintainer has approved opening an
17 alternative pull request in advance.
18 #. Fork the `urllib3 repository on Github <https://github.com/urllib3/urllib3>`_
19 to start making your changes.
20 #. Write a test which shows that the bug was fixed or that the feature works
21 as expected.
22 #. Format your changes with black using command ``nox -rs format`` and lint your
23 changes using command ``nox -rs lint``.
24 #. Add a `changelog entry
25 <https://github.com/urllib3/urllib3/blob/main/changelog/README.rst>`__.
26 #. Send a pull request and bug the maintainer until it gets merged and published.
27
28
29 Setting up your development environment
30 ---------------------------------------
31
32 In order to setup the development environment all that you need is
33 `nox <https://nox.thea.codes/en/stable/index.html>`_ installed in your machine::
34
35 $ python -m pip install --user --upgrade nox
36
37
38 Running the tests
39 -----------------
40
41 We use some external dependencies, multiple interpreters and code coverage
42 analysis while running test suite. Our ``noxfile.py`` handles much of this for
43 you::
44
45 $ nox --reuse-existing-virtualenvs --sessions test-3.12 test-pypy3.11
46 [ Nox will create virtualenv if needed, install the specified dependencies, and run the commands in order.]
47
48
49 Note that for nox to test different interpreters, the interpreters must be on the
50 ``PATH`` first. Check with ``which`` to see if the interpreter is on the ``PATH``
51 like so::
52
53
54 $ which python3.12
55 ~/.pyenv/versions/3.12.1/bin/python3.12
56
57 $ which pypy3.11
58 ~/.pyenv/versions/pypy3.11-7.3.22/bin/pypy3.11
59
60
61 There is also a nox command for running all of our tests and multiple python
62 versions.::
63
64 $ nox --reuse-existing-virtualenvs --sessions test
65
66 Note that code coverage less than 100% is regarded as a failing run. Some
67 platform-specific tests are skipped unless run in that platform. To make sure
68 the code works in all of urllib3's supported platforms, you can run our ``nox``
69 suite::
70
71 $ nox --reuse-existing-virtualenvs --sessions test
72 [ Nox will create virtualenv if needed, install the specified dependencies, and run the commands in order.]
73 .......
74 .......
75 nox > Session test-3.10 was successful.
76 nox > Session test-3.11 was successful.
77 nox > Session test-3.12 was successful.
78 nox > Session test-3.13 was successful.
79 nox > Session test-3.14 was successful.
80 nox > Session test-3.15 was successful.
81 nox > Session test-pypy was successful.
82
83 Our test suite `runs continuously on GitHub Actions
84 <https://github.com/urllib3/urllib3/actions>`_ with every pull request.
85
86 To run specific tests or quickly re-run without nox recreating the env, do the following::
87
88 $ nox --reuse-existing-virtualenvs --sessions test-3.13 -- pyTestArgument1 pyTestArgument2 pyTestArgumentN
89 [ Nox will create virtualenv, install the specified dependencies, and run the commands in order.]
90 nox > Running session test-3.13
91 nox > Re-using existing virtual environment at .nox/test-3-13.
92 .......
93 .......
94 nox > Session test-3.13 was successful.
95
96 After the ``--`` indicator, any arguments will be passed to pytest.
97 To specify an exact test case the following syntax also works:
98 ``test/dir/module_name.py::TestClassName::test_method_name``
99 (eg.: ``test/with_dummyserver/test_https.py::TestHTTPS::test_simple``).
100 The following argument is another valid example to pass to pytest: ``-k test_methode_name``.
101 These are useful when developing new test cases and there is no point
102 re-running the entire test suite every iteration. It is also possible to
103 further parameterize pytest for local testing.
104
105 For all valid arguments, check `the pytest documentation
106 <https://docs.pytest.org/en/stable/usage.html#stopping-after-the-first-or-n-failures>`_.
107
108 Getting paid for your contributions
109 -----------------------------------
110
111 urllib3 has a `pool of money hosted on Open Collective <https://opencollective.com/urllib3#category-BUDGET>`_
112 which the team uses to pay contributors for their work. **That could be you, too!** If you complete all tasks in an issue
113 that is marked with the `"💰 Bounty $X00" label <https://github.com/urllib3/urllib3/issues?q=is%3Aopen+is%3Aissue+label%3A%22%F0%9F%92%B0+Bounty+%24100%22%2C%22%F0%9F%92%B0+Bounty+%24200%22%2C%22%F0%9F%92%B0+Bounty+%24300%22%2C%22%F0%9F%92%B0+Bounty+%24400%22%2C%22%F0%9F%92%B0+Bounty+%24500%22+no%3Aassignee>`_ then you're eligible to be paid for your work.
114
115 - Ensure that you're able to `receive funds from Open Collective for working on OSS <https://docs.opencollective.com/help/expenses-and-getting-paid/submitting-expenses>`_.
116 Consider your employment contract and taxes for possible restrictions.
117 - If an issue is already assigned to someone on GitHub then it's likely they've
118 made substantial progress on the issue and will be given the bounty.
119 If you're interested in bounties you should look for issues which
120 aren't assigned to anyone.
121 - **Don't "claim" issues or ask whether someone is already working on an issue.**
122 Instead, focus on researching and working on the tasks in the issue. Once you
123 have made considerable progress on the tasks in an issue we can assign your
124 account to the issue to ensure others don't start working on it in parallel.
125 - If you've been assigned to an issue and haven't made progress or given an update
126 in over a week you will be unassigned from the issue to allow others a chance
127 at solving the issue.
128 - The amount you will be paid for the completing an issue is shown in the label (either $100, $200, $300, etc).
129 - If you have questions about how to create an invoice on Open Collective
130 `try reading their FAQ <https://docs.opencollective.com/help/expenses-and-getting-paid/expenses>`_.
131 - If you have a proposal to work on urllib3 that's not listed in the issue tracker please open an issue
132 with your proposal and our team will discuss whether we'd pay for your work on your proposal.
133 - If you have other questions get in contact with a maintainer in the `urllib3 Discord channel <https://discord.gg/urllib3>`_ or via email.
134 - The list above isn't an exhaustive list of criteria or rules for how/when money is distributed.
135 **The final say on whether money will be distributed is up to maintainers.**
136
137 This program is an experiment so if you have positive or negative feedback on the process you can contact the maintainers through one of the above channels.
138
139 Note that this program isn't a "bug bounty" program, we don't distribute funds to reporters of bugs or security vulnerabilities at this time.
140
141 Running local proxies
142 ---------------------
143
144 If the feature you are developing involves a proxy, you can rely on scripts we have developed to run a proxy locally.
145
146 Run an HTTP proxy locally:
147
148 .. code-block:: bash
149
150 $ python -m dummyserver.proxy
151
152 Run an HTTPS proxy locally:
153
154 .. code-block:: bash
155
156 $ python -m dummyserver.https_proxy
157
158 Contributing to documentation
159 -----------------------------
160
161 You can build the docs locally using ``nox``:
162
163 .. code-block:: bash
164
165 $ nox -rs docs
166
167 While writing documentation you should follow these guidelines:
168
169 - Use the top-level ``urllib3.request()`` function for smaller code examples. For more involved examples use PoolManager, etc.
170 - Use double quotes for all strings. (Output, Declaration etc.)
171 - Use keyword arguments everywhere except for method and url. (ie ``http.request("GET", "https://example.com", headers={...})`` )
172 - Use HTTPS in URLs everywhere unless HTTP is needed.
173 - Rules for code examples and naming variables:
174
175 - ``PoolManager`` instances should be named ``http``. (ie ``http = urllib3.PoolManager(...)``)
176 - ``ProxyManager`` instances should be named ``proxy``.
177 - ``ConnectionPool`` instances should be named ``pool``.
178 - ``Connection`` instances should be named ``conn``.
179 - ``HTTPResponse`` instances should be named ``resp``.
180 - Only use ``example.com`` or ``httpbin.org`` for example URLs
181
182 - Comments within snippets should be useful, if what's being done is apparent
183 (such as parsing JSON, making a request) then it can be skipped for that section.
184 - Comments should always go above a code section rather than below with the exception of print
185 statements where the comment containing the result goes below.
186 - Imports should be their own section separated from the rest of the example with a line of whitespace.
187 - Imports should minimized if possible. Use import urllib3 instead of from urllib3 import X.
188 - Sort imports similarly to isort, standard library first and third-party (like urllib3) come after.
189 - No whitespace is required between the sections as normally would be in case of isort.
190 - Add print statements along with a comment below them showing the output, potentially compressed.
191 - This helps users using the copy-paste button immediately see the results from a script.
192
193 Releases
194 --------
195
196 A release candidate can be created by any contributor.
197
198 - Announce intent to release on Discord, see if anyone wants to include last minute
199 changes.
200 - Run ``towncrier build`` to update ``CHANGES.rst`` with the release notes, adjust as
201 necessary.
202 - Commit the changes to a ``release-X.Y.Z`` branch.
203 - Create a pull request and append ``&expand=1&template=release.md`` to the URL before
204 submitting in order to include our release checklist in the pull request description.
205 - Follow the checklist!