Drop nox in favor of vanilla scripts (#566)

* Drop nox in favor of vanilla scripts

* Use named stages

* Fix attrs dependency resolution madness

* Add missing mkautodoc dev dependency

* Add missing install step on windows build

* Explicitly define stage order so that timed out Windows build runs last

* Add missing dev dependency on Black

* Clean up contributing guide

* Separate docs into docs-build and docs-serve
This commit is contained in:
Florimond Manca 2019-11-30 12:50:13 +01:00 committed by Tom Christie
parent 3218c35341
commit 8d55d78574
12 changed files with 138 additions and 142 deletions

1
.gitignore vendored
View File

@ -7,5 +7,4 @@ htmlcov/
site/
*.egg-info/
venv*/
.nox
.python-version

View File

@ -7,30 +7,36 @@ branches:
only:
- master
python:
- 3.6
- 3.7
- 3.8
stages:
- check
- docs
- test
matrix:
include:
- python: 3.7
env: NOX_SESSION=check
- python: 3.7
env: NOX_SESSION=docs
- python: 3.6
env: NOX_SESSION=test-3.6
- python: 3.7
env: NOX_SESSION=test-3.7
- python: 3.8
env: NOX_SESSION=test-3.8
dist: bionic # Required to get OpenSSL 1.1.1+
- os: windows
-
stage: check
python: 3.7
script: scripts/check
- stage: docs
python: 3.7
script: scripts/docs-build
- stage: test
os: windows
language: shell
python: 3.7
env:
PATH=/c/Python37:/c/Python37/Scripts:$PATH
NOX_SESSION=test-3.7
before_install:
- choco install python --version 3.7
- python -m pip install --upgrade pip
install: pip install -r requirements.txt
script: scripts/test
fast_finish: true
allow_failures:
@ -38,11 +44,7 @@ matrix:
# Some tests not yet resolved for Windows. (In progress)
- os: windows
install:
- pip install --upgrade nox
script:
- nox -s ${NOX_SESSION}
script: scripts/test
after_script:
- if [ -f .coverage ]; then

View File

@ -37,76 +37,45 @@ your GitHub username:
$ git clone https://github.com/YOUR-USERNAME/httpx
```
With the repository cloned you can access its folder, set up the
virtual environment, install the project requirements,
and then install HTTPX on edit mode:
You can now install the project and its dependencies using:
```shell
$ cd httpx
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -r test-requirements.txt
$ pip install -e .
$ scripts/install
```
!!! note
Feel free to replace this step with your development environment setup
(pyenv, pipenv, virtualenvwrapper, docker, etc).
## Testing and Linting
We use [nox](https://nox.thea.codes/en/stable/) to automate testing, linting,
and documentation building workflow. Make sure you have it installed
at your system before starting.
We use custom shell scripts to automate testing, linting,
and documentation building workflow.
Install `nox` with:
```shell
$ python3 -m pip install --user nox
```
Alternatively, use [pipx](https://github.com/pipxproject/pipx) if you prefer
to keep it into an isolated environment:
```shell
$ pipx install nox
```
Now, with nox installed, run the complete pipeline with:
```shell
$ nox
```
!!! warning
The test suite spawns a testing server at the port **8000**.
Make sure this isn't being used, so the tests can run properly.
To run the code auto-formatting separately:
```shell
$ nox -s lint
```
Also, if you need to run the tests only:
```shell
$ nox -s test
```
You can also run a single test script like this:
```shell
$ nox -s test -- tests/test_multipart.py
```
Lastly, to ensure you're on track to pass the CI build, run:
To run the tests, use:
```shell
$ scripts/test
```
This command is a light wrapper around `nox` that will run code style checks and test the code against all installed Python versions.
!!! warning
The test suite spawns testing servers on ports **8000** and **8001**.
Make sure these are not in use, so the tests can run properly.
You can run a single test script like this:
```shell
$ scripts/test -- tests/test_multipart.py
```
To run the code auto-formatting:
```shell
$ scripts/lint
```
Lastly, to run code checks separately (they are also run as part of `scripts/test`), run:
```shell
$ scripts/check
```
## Documenting
@ -115,7 +84,7 @@ Documentation pages are located under the `docs/` folder.
To run the documentation site locally (useful for previewing changes), use:
```shell
$ nox -s serve
$ scripts/docs-serve
```
## Resolving Build / Travis Failures
@ -129,7 +98,7 @@ If the test suite fails, you'll want to click through to the "Details" link, and
Here are some common ways the test suite can fail:
### NOX_SESSION=check Job Failed
### Check Job Failed
<p align="center" style="margin: 0 0 10px">
<img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/travis-fail-check.png" alt='Failing Travis lint job'>
@ -138,17 +107,19 @@ Here are some common ways the test suite can fail:
This job failing means there is either a code formatting issue or type-annotation issue.
You can look at the job output to figure out why it's failed or within a shell run:
`nox -s check`
```shell
$ scripts/check
```
It may be worth it to run `nox -s lint` to attempt auto-formatting the code
It may be worth it to run `$ scripts/lint` to attempt auto-formatting the code
and if that job succeeds commit the changes.
### NOX_SESSION=docs Job Failed
### Docs Job Failed
This job failing means the documentation failed to build. This can happen for
a variety of reasons like invalid markdown or missing configuration within `mkdocs.yml`.
### NOX_SESSION=test-3.X Job Failed
### Python 3.X Job Failed
<p align="center" style="margin: 0 0 10px">
<img src="https://raw.githubusercontent.com/encode/httpx/master/docs/img/travis-fail-test.png" alt='Failing Travis test job'>

View File

@ -1,55 +0,0 @@
import nox
nox.options.stop_on_first_error = True
nox.options.reuse_existing_virtualenvs = True
nox.options.keywords = "not serve"
source_files = ("httpx", "tools", "tests", "setup.py", "noxfile.py")
@nox.session
def lint(session):
session.install(
"--upgrade", "autoflake", "black", "flake8", "isort", "seed-isort-config"
)
session.run("autoflake", "--in-place", "--recursive", *source_files)
session.run("seed-isort-config", "--application-directories=httpx")
session.run("isort", "--project=httpx", "--recursive", "--apply", *source_files)
session.run("black", "--target-version=py36", *source_files)
check(session)
@nox.session
def check(session):
session.install(
"--upgrade", "black", "flake8", "flake8-bugbear", "flake8-pie", "isort", "mypy"
)
session.run("black", "--check", "--diff", "--target-version=py36", *source_files)
session.run("flake8", *source_files)
session.run("mypy", "httpx")
session.run(
"isort", "--check", "--diff", "--project=httpx", "--recursive", *source_files
)
@nox.session
def docs(session):
session.install("--upgrade", "mkdocs", "mkdocs-material", "mkautodoc>=0.1.0")
session.install("-e", ".")
session.run("mkdocs", "build")
@nox.session(reuse_venv=True)
def serve(session):
session.install("--upgrade", "mkdocs", "mkdocs-material")
session.run("mkdocs", "serve")
@nox.session(python=["3.6", "3.7", "3.8"])
def test(session):
session.install("--upgrade", "-r", "test-requirements.txt")
session.run("python", "-m", "pytest", *session.posargs)

View File

@ -3,11 +3,16 @@
# Optional
brotlipy==0.7.*
autoflake
black
cryptography
flake8
flake8-bugbear
flake8-pie
isort
mkdocs
mkautodoc
mkdocs-material
mypy
pytest
pytest-asyncio
@ -16,3 +21,6 @@ pytest-cov
trio
trustme
uvicorn
seed-isort-config
attrs>=19.2 # See: https://github.com/encode/httpx/pull/566#issuecomment-559862665

14
scripts/check Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh -e
export PREFIX=""
if [ -d 'venv' ] ; then
export PREFIX="venv/bin/"
fi
export SOURCE_FILES="httpx tests"
set -x
${PREFIX}black --check --diff --target-version=py36 $SOURCE_FILES
${PREFIX}flake8 $SOURCE_FILES
${PREFIX}mypy httpx
${PREFIX}isort --check --diff --project=httpx --recursive $SOURCE_FILES

10
scripts/docs-build Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh -e
export PREFIX=""
if [ -d 'venv' ] ; then
export PREFIX="venv/bin/"
fi
set -x
${PREFIX}mkdocs build

10
scripts/docs-serve Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh -e
export PREFIX=""
if [ -d 'venv' ] ; then
export PREFIX="venv/bin/"
fi
set -x
${PREFIX}mkdocs serve

15
scripts/install Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh -e
export PREFIX="venv/bin/"
set -x
python -m venv venv
${PREFIX}python -m pip install -U pip
${PREFIX}python -m pip install -r requirements.txt
set +x
echo
echo "Success! You can now activate your virtual environment using:"
echo "source ${PREFIX}activate"

14
scripts/lint Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh -e
export PREFIX=""
if [ -d 'venv' ] ; then
export PREFIX="venv/bin/"
fi
export SOURCE_FILES="httpx tests"
set -x
${PREFIX}autoflake --in-place --recursive $SOURCE_FILES
${PREFIX}seed-isort-config --application-directories=httpx
${PREFIX}isort --project=httpx --recursive --apply $SOURCE_FILES
${PREFIX}black --target-version=py36 $SOURCE_FILES

View File

@ -1,6 +1,14 @@
#!/bin/sh -e
export PREFIX=""
if [ -d 'venv' ] ; then
export PREFIX="venv/bin/"
fi
set -x
nox -s check
nox -s test
if [ -z $CI ]; then
scripts/check
fi
${PREFIX}pytest $@

View File

@ -14,7 +14,7 @@ combine_as_imports = True
force_grid_wrap = 0
include_trailing_comma = True
known_first_party = httpx,httpxprof,tests
known_third_party = brotli,certifi,chardet,click,cryptography,h11,h2,hstspreload,nox,pytest,requests,rfc3986,setuptools,tqdm,trio,trustme,uvicorn
known_third_party = brotli,certifi,chardet,click,cryptography,h11,h2,hstspreload,pytest,rfc3986,setuptools,tqdm,trio,trustme,uvicorn
line_length = 88
multi_line_output = 3