contributing.md
This file
Path
docs/contributing.md
223 lines · 7.5 KiB · Markdown
Last changed by
Update contributing docs (#1011)Yeray Diaz Diazbefore adoption3196be9
History of this fileTake it
The walk stopped after 200 commits: lines older than c337938 point at it.
asyncio: Don't wait for the stream to close (#640)Florimond Mancabefore adoptionc337938
lines 1–86why, one step back1# Contributing23Thank you for being interested in contributing to HTTPX.4There are many ways you can contribute to the project:56- Try HTTPX and [report bugs/issues you find](https://github.com/encode/httpx/issues/new)7- [Implement new features](https://github.com/encode/httpx/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)8- [Review Pull Requests of others](https://github.com/encode/httpx/pulls)9- Write documentation10- Participate in discussions1112## Reporting Bugs or Other Issues1314Found something that HTTPX should support?15Stumbled upon some unexpected behavior?1617Feel free to open an issue at the18[issue tracker](https://github.com/encode/httpx/issues).19Try to be more descriptive as you can and in case of a bug report,20provide as much information as possible like:2122- OS platform23- Python version24- Installed dependencies and versions (`python -m pip freeze`)25- Code snippet26- Error traceback2728## Development2930To start developing HTTPX create a **fork** of the31[HTTPX repository](https://github.com/encode/httpx) on GitHub.3233Then clone your fork with the following command replacing `YOUR-USERNAME` with34your GitHub username:3536```shell37$ git clone https://github.com/YOUR-USERNAME/httpx38```3940You can now install the project and its dependencies using:4142```shell43$ cd httpx44$ scripts/install45```4647## Testing and Linting4849We use custom shell scripts to automate testing, linting,50and documentation building workflow.5152To run the tests, use:5354```shell55$ scripts/test56```5758!!! warning59 The test suite spawns testing servers on ports **8000** and **8001**.60 Make sure these are not in use, so the tests can run properly.6162You can run a single test script like this:6364```shell65$ scripts/test -- tests/test_multipart.py66```6768To run the code auto-formatting:6970```shell71$ scripts/lint72```7374Lastly, to run code checks separately (they are also run as part of `scripts/test`), run:7576```shell77$ scripts/check78```7980## Documenting8182Documentation pages are located under the `docs/` folder.8384To run the documentation site locally (useful for previewing changes), use:8586```shellUpdate contributing docs (#1011)Yeray Diaz Diazbefore adoption3196be9
line 87why, one step back87$ scripts/docsasyncio: Don't wait for the stream to close (#640)Florimond Mancabefore adoptionc337938
lines 88–95why, one step back88```8990## Resolving Build / Travis Failures9192Once you've submitted your pull request, the test suite will automatically run, and the results will show up in GitHub.93If the test suite fails, you'll want to click through to the "Details" link, and try to identify why the test suite failed.9495<p align="center" style="margin: 0 0 10px">Update contributing docs (#1011)Yeray Diaz Diazbefore adoption3196be9
line 96why, one step back96 <img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail.png" alt='Failing PR commit status'>asyncio: Don't wait for the stream to close (#640)Florimond Mancabefore adoptionc337938
lines 97–103why, one step back97</p>9899Here are some common ways the test suite can fail:100101### Check Job Failed102103<p align="center" style="margin: 0 0 10px">Update contributing docs (#1011)Yeray Diaz Diazbefore adoption3196be9
line 104why, one step back104 <img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail-check.png" alt='Failing GitHub action lint job'>asyncio: Don't wait for the stream to close (#640)Florimond Mancabefore adoptionc337938
lines 105–124why, one step back105</p>106107This job failing means there is either a code formatting issue or type-annotation issue.108You can look at the job output to figure out why it's failed or within a shell run:109110```shell111$ scripts/check112```113114It may be worth it to run `$ scripts/lint` to attempt auto-formatting the code115and if that job succeeds commit the changes.116117### Docs Job Failed118119This job failing means the documentation failed to build. This can happen for120a variety of reasons like invalid markdown or missing configuration within `mkdocs.yml`.121122### Python 3.X Job Failed123124<p align="center" style="margin: 0 0 10px">Update contributing docs (#1011)Yeray Diaz Diazbefore adoption3196be9
line 125why, one step back125 <img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail-test.png" alt='Failing GitHub action test job'>asyncio: Don't wait for the stream to close (#640)Florimond Mancabefore adoptionc337938
lines 126–133why, one step back126</p>127128This job failing means the unit tests failed or not all code paths are covered by unit tests.129130If tests are failing you will see this message under the coverage report:131132`=== 1 failed, 435 passed, 1 skipped, 1 xfailed in 11.09s ===`133Update contributing docs (#1011)Yeray Diaz Diazbefore adoption3196be9
lines 134–135why, one step back134If tests succeed but coverage doesn't reach our current threshold, you will see this135message under the coverage report:asyncio: Don't wait for the stream to close (#640)Florimond Mancabefore adoptionc337938
lines 136–153why, one step back136137`FAIL Required test coverage of 100% not reached. Total coverage: 99.00%`138139## Releasing140141*This section is targeted at HTTPX maintainers.*142143Before releasing a new version, create a pull request that includes:144145- **An update to the changelog**:146 - We follow the format from [keepachangelog](https://keepachangelog.com/en/1.0.0/).147 - [Compare](https://github.com/encode/httpx/compare/) `master` with the tag of the latest release, and list all entries that are of interest to our users:148 - Things that **must** go in the changelog: added, changed, deprecated or removed features, and bug fixes.149 - Things that **should not** go in the changelog: changes to documentation, tests or tooling.150 - Try sorting entries in descending order of impact / importance.151 - Keep it concise and to-the-point. 🎯152- **A version bump**: see `__version__.py`.153Update contributing docs (#1011)Yeray Diaz Diazbefore adoption3196be9
line 154why, one step back154For an example, see [#1006](https://github.com/encode/httpx/pull/1006).asyncio: Don't wait for the stream to close (#640)Florimond Mancabefore adoptionc337938
line 155why, one step back155Update contributing docs (#1011)Yeray Diaz Diazbefore adoption3196be9
lines 156–166why, one step back156Once the release PR is merged, create a157[new release](https://github.com/encode/httpx/releases/new) including:158159- Tag version like `0.13.3`.160- Release title `Version 0.13.3`161- Description copied from the changelog.162163Once created this release will be automatically uploaded to PyPI.164165If something goes wrong with the PyPI job the release can be published using the166`scripts/publish` script.Document dev proxy setup (#933)Yeray Diaz Diazbefore adoptionafbd4c8
lines 167–223why, one step back167168## Development proxy setup169170To test and debug requests via a proxy it's best to run a proxy server locally.171Any server should do but HTTPCore's test suite uses172[`mitmproxy`](https://mitmproxy.org/) which is written in Python, it's fully173featured and has excellent UI and tools for introspection of requests.174175You can install `mitmproxy` using `pip install mitmproxy` or [several176other ways](https://docs.mitmproxy.org/stable/overview-installation/).177178`mitmproxy` does require setting up local TLS certificates for HTTPS requests,179as its main purpose is to allow developers to inspect requests that pass through180it. We can set them up follows:1811821. [`pip install trustme-cli`](https://github.com/sethmlarson/trustme-cli/).1832. `trustme-cli -i example.org www.example.org`, assuming you want to test184connecting to that domain, this will create three files: `server.pem`,185`server.key` and `client.pem`.1863. `mitmproxy` requires a PEM file that includes the private key and the187certificate so we need to concatenate them:188`cat server.key server.pem > server.withkey.pem`.1894. Start the proxy server `mitmproxy --certs server.withkey.pem`, or use the190[other mitmproxy commands](https://docs.mitmproxy.org/stable/) with different191UI options.192193At this point the server is ready to start serving requests, you'll need to194configure HTTPX as described in the195[proxy section](https://www.python-httpx.org/advanced/#http-proxying) and196the [SSL certificates section](https://www.python-httpx.org/advanced/#ssl-certificates),197this is where our previously generated `client.pem` comes in:198199```200import httpx201202proxies = {"all": "http://127.0.0.1:8080/"}203204with httpx.Client(proxies=proxies, verify="/path/to/client.pem") as client:205 response = client.get("https://example.org")206 print(response.status_code) # should print 200207```208209Note, however, that HTTPS requests will only succeed to the host specified210in the SSL/TLS certificate we generated, HTTPS requests to other hosts will211raise an error like:212213```214ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate215verify failed: Hostname mismatch, certificate is not valid for216'duckduckgo.com'. (_ssl.c:1108)217```218219If you want to make requests to more hosts you'll need to regenerate the220certificates and include all the hosts you intend to connect to in the221seconds step, i.e.222223`trustme-cli -i example.org www.example.org duckduckgo.com www.duckduckgo.com`