contributing.md
This file
Path
docs/contributing.md
237 lines · 8.3 KiB · Markdown
Last changed by
Allow passing additional pytest args to scripts/test (#1710)Florimond Mancabefore adoption3d192ae
History of this fileTake it
The walk stopped after 200 commits: lines older than ca5f524 point at it.
Add raw_path to scope in ASGITransport (#1357)Simon Willisonbefore adoptionca5f524
lines 1–14why, 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?Refine project workflow (#1534)Tom Christiebefore adoption437b55c
line 15why, one step back15Stumbled upon some unexpected behaviour?Add raw_path to scope in ASGITransport (#1357)Simon Willisonbefore adoptionca5f524
line 16why, one step back16Refine project workflow (#1534)Tom Christiebefore adoption437b55c
lines 17–21why, one step back17Contributions should generally start out with [a discussion](https://github.com/encode/httpx/discussions).18Possible bugs may be raised as a "Potential Issue" discussion, feature requests may19be raised as an "Ideas" discussion. We can then determine if the discussion needs20to be escalated into an "Issue" or not, or if we'd consider a pull request.21Add raw_path to scope in ASGITransport (#1357)Simon Willisonbefore adoptionca5f524
lines 22–29why, one step back22Try to be more descriptive as you can and in case of a bug report,23provide as much information as possible like:2425- OS platform26- Python version27- Installed dependencies and versions (`python -m pip freeze`)28- Code snippet29- Error tracebackRefine project workflow (#1534)Tom Christiebefore adoption437b55c
lines 30–38why, one step back3031You should always try to reduce any examples to the *simplest possible case*32that demonstrates the issue.3334Some possibly useful tips for narrowing down potential issues...3536- Does the issue exist on HTTP/1.1, or HTTP/2, or both?37- Does the issue exist with `Client`, `AsyncClient`, or both?38- When using `AsyncClient` does the issue exist when using `asyncio` or `trio`, or both?Add raw_path to scope in ASGITransport (#1357)Simon Willisonbefore adoptionca5f524
lines 39–73why, one step back3940## Development4142To start developing HTTPX create a **fork** of the43[HTTPX repository](https://github.com/encode/httpx) on GitHub.4445Then clone your fork with the following command replacing `YOUR-USERNAME` with46your GitHub username:4748```shell49$ git clone https://github.com/YOUR-USERNAME/httpx50```5152You can now install the project and its dependencies using:5354```shell55$ cd httpx56$ scripts/install57```5859## Testing and Linting6061We use custom shell scripts to automate testing, linting,62and documentation building workflow.6364To run the tests, use:6566```shell67$ scripts/test68```6970!!! warning71 The test suite spawns testing servers on ports **8000** and **8001**.72 Make sure these are not in use, so the tests can run properly.73Allow passing additional pytest args to scripts/test (#1710)Florimond Mancabefore adoption3d192ae
line 74why, one step back74Any additional arguments will be passed to `pytest`. See the [pytest documentation](https://docs.pytest.org/en/latest/how-to/usage.html) for more information.Add raw_path to scope in ASGITransport (#1357)Simon Willisonbefore adoptionca5f524
line 75why, one step back75Allow passing additional pytest args to scripts/test (#1710)Florimond Mancabefore adoption3d192ae
lines 76–77why, one step back76For example, to run a single test script:77Add raw_path to scope in ASGITransport (#1357)Simon Willisonbefore adoptionca5f524
line 78why, one step back78```shellAllow passing additional pytest args to scripts/test (#1710)Florimond Mancabefore adoption3d192ae
line 79why, one step back79$ scripts/test tests/test_multipart.pyAdd raw_path to scope in ASGITransport (#1357)Simon Willisonbefore adoptionca5f524
lines 80–103why, one step back80```8182To run the code auto-formatting:8384```shell85$ scripts/lint86```8788Lastly, to run code checks separately (they are also run as part of `scripts/test`), run:8990```shell91$ scripts/check92```9394## Documenting9596Documentation pages are located under the `docs/` folder.9798To run the documentation site locally (useful for previewing changes), use:99100```shell101$ scripts/docs102```103Remove stale reference to "Travis" (#1440)Florimond Mancabefore adoption7f9bb5f
line 104why, one step back104## Resolving Build / CI FailuresAdd raw_path to scope in ASGITransport (#1357)Simon Willisonbefore adoptionca5f524
lines 105–237why, one step back105106Once you've submitted your pull request, the test suite will automatically run, and the results will show up in GitHub.107If the test suite fails, you'll want to click through to the "Details" link, and try to identify why the test suite failed.108109<p align="center" style="margin: 0 0 10px">110 <img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail.png" alt='Failing PR commit status'>111</p>112113Here are some common ways the test suite can fail:114115### Check Job Failed116117<p align="center" style="margin: 0 0 10px">118 <img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail-check.png" alt='Failing GitHub action lint job'>119</p>120121This job failing means there is either a code formatting issue or type-annotation issue.122You can look at the job output to figure out why it's failed or within a shell run:123124```shell125$ scripts/check126```127128It may be worth it to run `$ scripts/lint` to attempt auto-formatting the code129and if that job succeeds commit the changes.130131### Docs Job Failed132133This job failing means the documentation failed to build. This can happen for134a variety of reasons like invalid markdown or missing configuration within `mkdocs.yml`.135136### Python 3.X Job Failed137138<p align="center" style="margin: 0 0 10px">139 <img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail-test.png" alt='Failing GitHub action test job'>140</p>141142This job failing means the unit tests failed or not all code paths are covered by unit tests.143144If tests are failing you will see this message under the coverage report:145146`=== 1 failed, 435 passed, 1 skipped, 1 xfailed in 11.09s ===`147148If tests succeed but coverage doesn't reach our current threshold, you will see this149message under the coverage report:150151`FAIL Required test coverage of 100% not reached. Total coverage: 99.00%`152153## Releasing154155*This section is targeted at HTTPX maintainers.*156157Before releasing a new version, create a pull request that includes:158159- **An update to the changelog**:160 - We follow the format from [keepachangelog](https://keepachangelog.com/en/1.0.0/).161 - [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:162 - Things that **must** go in the changelog: added, changed, deprecated or removed features, and bug fixes.163 - Things that **should not** go in the changelog: changes to documentation, tests or tooling.164 - Try sorting entries in descending order of impact / importance.165 - Keep it concise and to-the-point. 🎯166- **A version bump**: see `__version__.py`.167168For an example, see [#1006](https://github.com/encode/httpx/pull/1006).169170Once the release PR is merged, create a171[new release](https://github.com/encode/httpx/releases/new) including:172173- Tag version like `0.13.3`.174- Release title `Version 0.13.3`175- Description copied from the changelog.176177Once created this release will be automatically uploaded to PyPI.178179If something goes wrong with the PyPI job the release can be published using the180`scripts/publish` script.181182## Development proxy setup183184To test and debug requests via a proxy it's best to run a proxy server locally.185Any server should do but HTTPCore's test suite uses186[`mitmproxy`](https://mitmproxy.org/) which is written in Python, it's fully187featured and has excellent UI and tools for introspection of requests.188189You can install `mitmproxy` using `pip install mitmproxy` or [several190other ways](https://docs.mitmproxy.org/stable/overview-installation/).191192`mitmproxy` does require setting up local TLS certificates for HTTPS requests,193as its main purpose is to allow developers to inspect requests that pass through194it. We can set them up follows:1951961. [`pip install trustme-cli`](https://github.com/sethmlarson/trustme-cli/).1972. `trustme-cli -i example.org www.example.org`, assuming you want to test198connecting to that domain, this will create three files: `server.pem`,199`server.key` and `client.pem`.2003. `mitmproxy` requires a PEM file that includes the private key and the201certificate so we need to concatenate them:202`cat server.key server.pem > server.withkey.pem`.2034. Start the proxy server `mitmproxy --certs server.withkey.pem`, or use the204[other mitmproxy commands](https://docs.mitmproxy.org/stable/) with different205UI options.206207At this point the server is ready to start serving requests, you'll need to208configure HTTPX as described in the209[proxy section](https://www.python-httpx.org/advanced/#http-proxying) and210the [SSL certificates section](https://www.python-httpx.org/advanced/#ssl-certificates),211this is where our previously generated `client.pem` comes in:212213```214import httpx215216proxies = {"all": "http://127.0.0.1:8080/"}217218with httpx.Client(proxies=proxies, verify="/path/to/client.pem") as client:219 response = client.get("https://example.org")220 print(response.status_code) # should print 200221```222223Note, however, that HTTPS requests will only succeed to the host specified224in the SSL/TLS certificate we generated, HTTPS requests to other hosts will225raise an error like:226227```228ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate229verify failed: Hostname mismatch, certificate is not valid for230'duckduckgo.com'. (_ssl.c:1108)231```232233If you want to make requests to more hosts you'll need to regenerate the234certificates and include all the hosts you intend to connect to in the235seconds step, i.e.236237`trustme-cli -i example.org www.example.org duckduckgo.com www.duckduckgo.com`