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