-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtox.ini
214 lines (203 loc) · 9.35 KB
/
tox.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
[tox]
# This is the order how tox runs the tests when used interactively during development.
# Run the tests which uncover issues most often first! For example:
# 1. python 2.7 and 3.10 coverage test for changed, but not covered lines and mypy check
# 2. python 3.6 test and pylint warnings from changed lines
# 3. pytype (needs Python 3.8 for best results)
# 4. pyre and pyright checks, pytest test report as markdown for GitHub Actions summary
envlist = py38-covcombine-check, py311-lint-test, py310-pytype, py311-pyre-mdreport
isolated_build = true
skip_missing_interpreters = true
requires =
# The latest versions of tox need 'py>=1.11.0' and this is not stated in the deps of tox-4.5.1.
py>=1.11.0
# Use tox==4.5.1: tox>=4 is needed for reading the extras from pyproject.toml
# while tox>=4.5.2 depends on virutalenv>=20.23, which breaks Python 2.7:
tox==4.5.1; python_version >= '3.7'
tox-gh-actions; python_version >= '3.7'
# virtualenv-20.22 breaks using python2.7 for the `py27` virtualenv with tox and newer
# versions even break py36(which is also EOL) because py36 does not support
# from __future__ import annotations
virtualenv<20.22
[test]
description = Run pytest in this environment with --cov for use in other stages
extras = test
commands =
# https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md
# https://github.com/actions/toolkit/blob/main/docs/commands.md#problem-matchers
echo "::add-matcher::.github/workflows/PYTHONWARNINGS-problemMatcher.json"
pytest --cov -v --new-first -x --show-capture=all -rA
sh -c 'if [ -n "{env:PYTEST_MD_REPORT_OUTPUT}" -a -n "{env:GITHUB_STEP_SUMMARY}" ];then \
mkdir -p $(dirname "{env:GITHUB_STEP_SUMMARY:.git/sum.md}"); \
sed "s/tests\(.*py\)/[&](&)/" \
{env:PYTEST_MD_REPORT_OUTPUT} >{env:GITHUB_STEP_SUMMARY:.git/sum.md};fi'
[testenv]
description = Run in a {basepython} virtualenv:
cov: {[cov]description}
covcombine: {[covcombine]description}
covcp: Copy the generated .converage and coverage.xml to the UPLOAD_DIR dir
fox: {[fox]description}
lint: {[lint]description}
mdreport: Make a test report (which is shown in the GitHub Actions Summary Page)
test: {[test]description}
# https://pypi.org/project/pyre-check/ pyre intro: https://youtu.be/0FSXS5kw2m4
pyre: Run pyre for static analyis, only passes using: tox -e py311-pyre
check: Run mypy for static analyis
pytype: Run pytype for static analyis, intro: https://youtu.be/abvW0mOrDiY
# checkers(mypy) need the pytest dependices as well:
extras =
{check,pytype}: {[check]extras}
{cov,covcp,covcombine,fox,check,lint,test,pytype,pyre,mdreport}: {[test]extras}
{cov,covcp,covcombine,fox}: {[cov]extras}
deps =
mdreport: pytest-md-report
{py27-test,py27-cov}: pyftpdlib
{py27-test,py27-cov}: pylint
{cov,covcp,covcombine,fox}: coverage[toml]
{cov,covcp,covcombine,fox}: diff-cover
{lint,fox}: {[lint]deps}
pyre: pyre-check
pyre: pyre-extensions
pyre: pyright
pytype: {[pytype]deps}
allowlist_externals =
{cov,covcp,covcombine,fox,check,lint,test,mdreport}: echo
{cov,covcp,covcombine,fox,check,lint,test,mdreport}: sh
{cov,covcp,covcombine,fox}: cp
{covcombine,fox}: tox
check: cat
fox: firefox
passenv =
{pytype,covcombine,lint,test}: GITHUB_STEP_SUMMARY
pytype: GITHUB_SERVER_URL
pytype: GITHUB_REPOSITORY
pytype: GITHUB_HEAD_REF
pytype: GITHUB_REF_NAME
test: PYTEST_ADDOPTS
test: PYTEST_XDIST_WORKER_COUNT
covcp: UPLOAD_DIR
covcp: HOME
check: MYPY_FORCE_COLOR
check: MYPY_FORCE_TERMINAL_WIDTH
pyre: PYRE_TYPESHED
{fox,check,pytype}: TERM
fox: DISPLAY
fox: XAUTHORITY
fox: DBUS_SESSION_BUS_ADDRESS
setenv =
LC_ALL=C # Ensure that xcp is tested without an locale (like XAPI plugins)
PYLINTHOME={envdir}/.pylinthome
PYTHONDEVMODE=yes # Enables development/resource checks: eg unclosed files and more
PYTHONPATH=stubs
# Inhibit dev-warnings on pytest plugins, but we enable dev-warnings in conftest.py
PYTHONWARNINGS=ignore # for our code, for full warnings except for pytest plugins
COVERAGE_FILE={envlogdir}/.coverage
mdreport: PYTEST_MD_REPORT=True
mdreport: PYTEST_MD_REPORT_VERBOSE=0
mdreport: PYTEST_MD_REPORT_COLOR=never
mdreport: PYTEST_MD_REPORT_OUTPUT={envlogdir}/pytest-md-report.md
mdreport: PYTEST_MD_REPORT_TEE=1
mdreport: PYTEST_MD_REPORT_ZEROS=empty
lint: ENVLOGDIR={envlogdir}
{[cov]setenv}
commands =
lint: {[lint]commands}
pyre: {[pyre]commands}
check: {[check]commands}
pytype: {[pytype]commands}
{cov,covcp,covcombine,check,fox,test,mdreport}: {[test]commands}
# covcombine shall not call [cov]commands: diff-cover shall check the combined cov:
{cov,covcp}: {[cov]commands}
{py27-test}: pylint --py3k --disable=no-absolute-import xcp/
covcp: cp -av {envlogdir}/coverage.xml {env:UPLOAD_DIR:.}
covcombine: {[covcombine]commands}
fox: {[covcombine]commands}
fox: {[lint]commands}
fox: {[fox]commands}
[cov]
description = Generate coverage html reports (incl. diff-cover) for this environment
setenv = PY3_DIFFCOVER_OPTIONS=--ignore-whitespace --show-uncovered
py27: PY3_DIFFCOVER_OPTIONS=
extras = coverage
test
commands =
coverage xml -o {envlogdir}/coverage.xml --fail-under {env:XCP_COV_MIN:68}
coverage html -d {envlogdir}/htmlcov
coverage html -d {envlogdir}/htmlcov-tests --fail-under {env:TESTS_COV_MIN:96} \
--include="tests/*"
diff-cover --compare-branch=origin/master --include-untracked \
{env:PY3_DIFFCOVER_OPTIONS} --fail-under {env:DIFF_COV_MIN:92} \
--html-report {envlogdir}/coverage-diff.html \
{envlogdir}/coverage.xml
[covcombine]
description = Generate combined coverage reports with py27-test coverage merged
commands =
tox -e py27-test
sh -c 'export COVERAGE_FILE=$COVERAGE_FILE-combined; \
coverage combine --keep {envlogdir}/../../py27-test/log/.coverage {envlogdir}/.coverage;\
coverage xml -o {envlogdir}/coverage.xml;\
coverage html -d {envlogdir}/htmlcov;\
coverage html -d {envlogdir}/htmlcov-tests --include="tests/*"'
sh -c '\
diff-cover --compare-branch=origin/master --ignore-staged --ignore-unstaged \
--ignore-whitespace --show-uncovered --fail-under {env:DIFF_COVCOMBINE_MIN:100} \
--html-report {envlogdir}/coverage-diff.html \
--markdown-report {envlogdir}/coverage-diff.md \
{envlogdir}/coverage.xml; EXIT_CODE=$?;echo $EXIT_CODE; \
GITHUB_STEP_SUMMARY={env:GITHUB_STEP_SUMMARY:.git/GITHUB_STEP_SUMMARY.md}; \
if [ -n "$GITHUB_STEP_SUMMARY" ]; then \
mkdir -p ${GITHUB_STEP_SUMMARY%/*};sed "/title/,/\/style/d" \
{envlogdir}/coverage-diff.html >>"$GITHUB_STEP_SUMMARY"; fi; \
exit $EXIT_CODE'
[lint]
description = Run pylint and fail on warnings remaining on lines in the diff to master
deps = pylint
diff-cover
pandas
tabulate
commands =
python pylint_runner.py xcp tests
diff-quality --compare-branch=origin/master --violations=pylint \
--ignore-whitespace --fail-under 100 \
--html-report {envlogdir}/pylint-diff.html {envlogdir}/pylint.txt
[fox]
description = Generate combined coverage html reports and open them in firefox
commands = firefox {envlogdir}/coverage-diff.html \
{envlogdir}/htmlcov/index.html \
{envlogdir}/htmlcov-tests/index.html \
{envlogdir}/pylint-warnings.txt \
{envlogdir}/pylint-warnings-on-changed-lines.txt \
{envlogdir}/pylint-diff.html
# Map the github python versions to fators to run only matching envs from [tox]:envlist
# See https://github.com/ymyzk/tox-gh-actions for details:
# https://github.com/ymyzk/tox-gh-actions#tox-gh-actions-configuration
# The benefit of using tox is that all versions can be run locally and
# the local venvs will be the same as the venvs created by tox on the GitHub runners:
[gh-actions]
python =
2.7: py27
3.6: py36
3.7: py37
3.8: py38
3.9: py39
3.10: py310
3.11: py311
[check]
extras = mypy
commands =
mypy --txt-report {envlogdir}
cat {envlogdir}/index.txt
[pycodestyle]
ignore = W191,W293,W504,E101,E126,E127,E201,E202,E203,E221,E222,E226,E227,E241,E251,E261,E262,E265,E301,E302,E303,E305,E722,W391,E401,E402,E741
max-line-length = 129
[pyre]
commands =
-pyright
[pytype]
deps = pytype
pandas
commands =
python3.10 -V # Needs python <= 3.10, and 3.10 is needed to parse new "|" syntax
pytype --version
# Runs pytype -j auto -k --config .github/workflows/pytype.cfg and parses the output:
python3 pytype_runner.py # When switching versions, update .github/workflows/pytype.cfg too!