CONTRIBUTING.md
This file
Path
.github/CONTRIBUTING.md
235 lines · 8.1 KiB · Markdown
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than 4dec569 point at it.
Add httpx-auth and pytest-httpx to third party documentation (#1560)Colin Bounouarbefore adoption4dec569
lines 1–235why, 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 behaviour?1617Contributions 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.2122Try 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 traceback3031You 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?3940## 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.7374You can run a single test script like this:7576```shell77$ scripts/test -- tests/test_multipart.py78```7980To run the code auto-formatting:8182```shell83$ scripts/lint84```8586Lastly, to run code checks separately (they are also run as part of `scripts/test`), run:8788```shell89$ scripts/check90```9192## Documenting9394Documentation pages are located under the `docs/` folder.9596To run the documentation site locally (useful for previewing changes), use:9798```shell99$ scripts/docs100```101102## Resolving Build / CI Failures103104Once you've submitted your pull request, the test suite will automatically run, and the results will show up in GitHub.105If the test suite fails, you'll want to click through to the "Details" link, and try to identify why the test suite failed.106107<p align="center" style="margin: 0 0 10px">108 <img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail.png" alt='Failing PR commit status'>109</p>110111Here are some common ways the test suite can fail:112113### Check Job Failed114115<p align="center" style="margin: 0 0 10px">116 <img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail-check.png" alt='Failing GitHub action lint job'>117</p>118119This job failing means there is either a code formatting issue or type-annotation issue.120You can look at the job output to figure out why it's failed or within a shell run:121122```shell123$ scripts/check124```125126It may be worth it to run `$ scripts/lint` to attempt auto-formatting the code127and if that job succeeds commit the changes.128129### Docs Job Failed130131This job failing means the documentation failed to build. This can happen for132a variety of reasons like invalid markdown or missing configuration within `mkdocs.yml`.133134### Python 3.X Job Failed135136<p align="center" style="margin: 0 0 10px">137 <img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/gh-actions-fail-test.png" alt='Failing GitHub action test job'>138</p>139140This job failing means the unit tests failed or not all code paths are covered by unit tests.141142If tests are failing you will see this message under the coverage report:143144`=== 1 failed, 435 passed, 1 skipped, 1 xfailed in 11.09s ===`145146If tests succeed but coverage doesn't reach our current threshold, you will see this147message under the coverage report:148149`FAIL Required test coverage of 100% not reached. Total coverage: 99.00%`150151## Releasing152153*This section is targeted at HTTPX maintainers.*154155Before releasing a new version, create a pull request that includes:156157- **An update to the changelog**:158 - We follow the format from [keepachangelog](https://keepachangelog.com/en/1.0.0/).159 - [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:160 - Things that **must** go in the changelog: added, changed, deprecated or removed features, and bug fixes.161 - Things that **should not** go in the changelog: changes to documentation, tests or tooling.162 - Try sorting entries in descending order of impact / importance.163 - Keep it concise and to-the-point. 🎯164- **A version bump**: see `__version__.py`.165166For an example, see [#1006](https://github.com/encode/httpx/pull/1006).167168Once the release PR is merged, create a169[new release](https://github.com/encode/httpx/releases/new) including:170171- Tag version like `0.13.3`.172- Release title `Version 0.13.3`173- Description copied from the changelog.174175Once created this release will be automatically uploaded to PyPI.176177If something goes wrong with the PyPI job the release can be published using the178`scripts/publish` script.179180## Development proxy setup181182To test and debug requests via a proxy it's best to run a proxy server locally.183Any server should do but HTTPCore's test suite uses184[`mitmproxy`](https://mitmproxy.org/) which is written in Python, it's fully185featured and has excellent UI and tools for introspection of requests.186187You can install `mitmproxy` using `pip install mitmproxy` or [several188other ways](https://docs.mitmproxy.org/stable/overview-installation/).189190`mitmproxy` does require setting up local TLS certificates for HTTPS requests,191as its main purpose is to allow developers to inspect requests that pass through192it. We can set them up follows:1931941. [`pip install trustme-cli`](https://github.com/sethmlarson/trustme-cli/).1952. `trustme-cli -i example.org www.example.org`, assuming you want to test196connecting to that domain, this will create three files: `server.pem`,197`server.key` and `client.pem`.1983. `mitmproxy` requires a PEM file that includes the private key and the199certificate so we need to concatenate them:200`cat server.key server.pem > server.withkey.pem`.2014. Start the proxy server `mitmproxy --certs server.withkey.pem`, or use the202[other mitmproxy commands](https://docs.mitmproxy.org/stable/) with different203UI options.204205At this point the server is ready to start serving requests, you'll need to206configure HTTPX as described in the207[proxy section](https://www.python-httpx.org/advanced/#http-proxying) and208the [SSL certificates section](https://www.python-httpx.org/advanced/#ssl-certificates),209this is where our previously generated `client.pem` comes in:210211```212import httpx213214proxies = {"all": "http://127.0.0.1:8080/"}215216with httpx.Client(proxies=proxies, verify="/path/to/client.pem") as client:217 response = client.get("https://example.org")218 print(response.status_code) # should print 200219```220221Note, however, that HTTPS requests will only succeed to the host specified222in the SSL/TLS certificate we generated, HTTPS requests to other hosts will223raise an error like:224225```226ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate227verify failed: Hostname mismatch, certificate is not valid for228'duckduckgo.com'. (_ssl.c:1108)229```230231If you want to make requests to more hosts you'll need to regenerate the232certificates and include all the hosts you intend to connect to in the233seconds step, i.e.234235`trustme-cli -i example.org www.example.org duckduckgo.com www.duckduckgo.com`