Skip to content

Commit eefcf9e

Browse files
committed
pre-commit, contribution guideline, script/test now creates one virtualenv using -m venv
1 parent 12a76ea commit eefcf9e

File tree

7 files changed

+114
-44
lines changed

7 files changed

+114
-44
lines changed

.github/workflows/publish.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
run: check-manifest
4040
- name: twine check
4141
run: twine check dist/*
42+
- name: script/test install_check_version
43+
run: stages=venv,check_version script/test
4244

4345
- uses: actions/upload-artifact@v2
4446
with:

.github/workflows/style.yaml

+3-6
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ jobs:
2828
- name: pip install
2929
run: pip install black isort -r requirements-test.txt
3030
- name: isort
31-
run: isort --check python2/ python3/ tests/ || echo FIXME
31+
run: isort --check python3/ tests/ || echo FIXME
3232
- name: black
33-
run: black --check --diff python2/ python3/ tests/ || echo FIXME
34-
- name: flake8 python2/
35-
run: flake8 python2/
36-
- name: flake8 python3/ tests/
37-
run: flake8 python3/ tests/
33+
run: black --check --diff python3/ tests/ || echo FIXME
34+
- run: stages=venv,style script/test

.github/workflows/test.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
- { py: 3.7, ignore-error: false }
2323
- { py: 3.8, ignore-error: false }
2424
- { py: 3.9, ignore-error: false }
25+
- { py: "3.10", ignore-error: false }
26+
- { py: "3.11", ignore-error: false }
2527
- { py: 3.x, ignore-error: true }
2628
- { py: pypy2, ignore-error: false }
2729
- { py: pypy3, ignore-error: false }
@@ -46,7 +48,7 @@ jobs:
4648
- run: pip install tox-gh
4749
if: startsWith(matrix.py, '3.') && matrix.py >= '3.6'
4850
- run: pip install 'codecov>=2.0.15' -r requirements-test.txt
49-
- run: script/test -sv
51+
- run: stages=venv,test script/test -sv
5052
- run: codecov --flags=$(echo ${{ matrix.py }} |tr -d -- '-.')
5153

5254
test_py37_openssl11:

.pre-commit-config.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.3.0
6+
hooks:
7+
- id: check-added-large-files
8+
- id: check-ast
9+
- id: check-executables-have-shebangs
10+
- id: check-merge-conflict
11+
- id: check-shebang-scripts-are-executable
12+
- id: check-toml
13+
- id: check-yaml
14+
# - id: end-of-file-fixer
15+
# - id: trailing-whitespace
16+
17+
# TODO enable after py2/3 merge and initial black/isort run
18+
# - repo: https://github.com/asottile/pyupgrade
19+
# rev: v3.1.0
20+
# hooks:
21+
# - id: pyupgrade
22+
23+
- repo: local
24+
hooks:
25+
- id: pre-commit-validate-config
26+
name: validate pre-commit config
27+
files: "^.pre-commit-config.yaml$"
28+
types: [yaml]
29+
entry: pre-commit validate-config
30+
language: system
31+
fail_fast: true
32+
33+
- id: test
34+
name: run code style and unit tests
35+
types_or: [text, python, shell, toml, yaml]
36+
exclude: "^(build|dist|doc|python2|ref|venv[^/]*?)/"
37+
entry: script/test -sv
38+
language: system
39+
pass_filenames: false
40+
require_serial: true

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Introduction
44
httplib2 is a comprehensive HTTP client library, httplib2.py supports many
55
features left out of other HTTP libraries.
66

7+
If you want to help this project by bug report or code change, [contribution guidelines](contributing.md) may contain useful information.
8+
79
### HTTP and HTTPS
810

911
HTTPS support is only available if the socket module was

contributing.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Welcome
2+
3+
You have come to the right place if you want to support httplib2 by doing. Thank you!
4+
5+
- [Reporting security / sensitive issues](SECURITY.md)
6+
- [Regular issues](https://github.com/httplib2/httplib2/issues?q=) please try to find existing solution first, search without issue/open filters.
7+
- If you intend to propose code change, there is no need to open an issue first. Pull request is more than enough. `git diff` in message is fine too.
8+
- Tests use TLS certificates/keys generated by `script/generate-tls`
9+
10+
11+
## Submitting changes (pull request policy)
12+
13+
- Run `pre-commit install` once to setup hooks that detect/fix common style issues and run unit tests. [pre-commit website](https://pre-commit.com/)
14+
- If you don't want pre-commit hooks, please run `script/test` before commit
15+
- Test is required, or at least coverage must not decrease
16+
- One commit is strongly preferred, except for very big changes
17+
- Feel free to append yourself into __contributors__
18+
- Commit message should follow the following formula:
19+
20+
>subsystem: description of why the change is useful
21+
>
22+
>optional details
23+
>
24+
>links to related issues or websites
25+
26+
The why part is very important. Diff already says what is changed. Explain why.

script/test

+38-37
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,62 @@ if [[ -z "${CI:-}" ]] && [[ -t 1 ]] ; then
88
fi
99
test_flags=(
1010
$@
11-
$flag_forked
11+
"$flag_forked"
1212
tests/
1313
)
14+
if [[ -n "${CI:-}" ]] ; then
15+
test_flags+=(--fulltrace)
16+
fi
17+
: "${stages="venv,style,test,check_version"}"
1418

1519
main() {
1620
cd "$( dirname "${BASH_SOURCE[0]}" )/.."
17-
if [[ -n "${CI:-}" ]] ; then
18-
case "${test_group-}" in
19-
package)
20-
# TODO: sdist bdist_wheel
21-
# but wheels don't roll well with our 2/3 split code base
22-
python setup.py sdist
23-
install_check_version "pip"
24-
;;
25-
*)
26-
pip install -e .
27-
httplib2_test_still_run_skipped=1 pytest --fulltrace -k test_303 $@ tests/ || true
28-
httplib2_test_still_run_skipped=1 pytest --fulltrace -k test_head_301 $@ tests/ || true
29-
pytest --fulltrace ${test_flags[@]}
30-
;;
31-
esac
32-
else
33-
if [[ ! -d ./venv-27 ]] ; then
34-
virtualenv --python=python2.7 ./venv-27
35-
fi
36-
if [[ ! -d ./venv-36 ]] ; then
37-
virtualenv --python=python3.6 ./venv-36
38-
fi
21+
if enabled venv && [[ -z "${CI:-}${VIRTUAL_ENV:-}" ]] ; then
22+
echo "environment: neither CI nor existing virtualenv, using \`python -m venv ./venv\`" >&2
23+
[[ -x venv/bin/pip ]] || python -m venv venv
24+
source venv/bin/activate
25+
fi
3926

40-
./venv-27/bin/pip install -e . -r requirements-test.txt
41-
./venv-27/bin/pytest ${test_flags[@]}
42-
./venv-36/bin/pip install -e . -r requirements-test.txt
43-
./venv-36/bin/pytest ${test_flags[@]}
27+
if enabled style ; then
28+
pip install black isort
29+
grep -E 'flake8' <requirements-test.txt |xargs pip install
30+
# TODO enable after py2/3 merge and initial black/isort run
31+
# isort python3/ tests/
32+
# black python3/ tests/
33+
flake8 python3/ tests/
34+
fi
4435

45-
# FIXME: too many errors
46-
# ./venv-27/bin/flake8 python2/
47-
# ./venv-36/bin/flake8 python3/ tests/
36+
if enabled test ; then
37+
pip install -e . -r requirements-test.txt
38+
if [[ -n "${CI:-}" ]] ; then
39+
httplib2_test_still_run_skipped=1 pytest --fulltrace -k test_303 "$@" tests/ || true
40+
httplib2_test_still_run_skipped=1 pytest --fulltrace -k test_head_301 "$@" tests/ || true
41+
fi
42+
pytest --fulltrace "${test_flags[@]}"
43+
fi
4844

45+
if enabled check_version ; then
4946
# TODO: sdist bdist_wheel
5047
# but wheels don't roll well with our 2/3 split code base
51-
./venv-36/bin/python setup.py sdist
52-
install_check_version "./venv-27/bin/pip"
53-
install_check_version "./venv-36/bin/pip"
48+
python setup.py sdist
49+
install_check_version
5450
fi
51+
5552
rm -rf ./_httplib2_test_cache
5653
}
5754

55+
enabled() {
56+
[[ ",${stages}," = *,$1,* ]] || return 1
57+
}
58+
5859
install_check_version() {
59-
local pip="$1"
60-
$pip install dist/httplib2*
60+
# FIXME replace gz with whl after py2/3 merge
61+
pip install dist/httplib2*gz
6162
version_source=$(python setup.py --version)
62-
version_installed=$($pip show httplib2 |fgrep Version: |cut -d' ' -f2)
63+
version_installed=$(pip show httplib2 |grep -F Version: |cut -d' ' -f2)
6364
if [[ "$version_source" != "$version_installed" ]] ; then
6465
echo "error: installed package version=$version_installed does not match source=$version_source" >&2
65-
exit 1
66+
return 1
6667
fi
6768
}
6869

0 commit comments

Comments
 (0)