This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
forked from canonical/snapcraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtox.ini
187 lines (171 loc) · 7.23 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
# Differences from the starbase tox.ini:
# * Uses requirements-devel.txt
# * No library code for pyright type checking
# * Documentation envs removed
# * Pytest uses wheel package
# * Legacy tests instead of integration tests
# * Additional test environment "noreq" runs all the tests without requirements.txt
# * lint-shellcheck includes spread-shellcheck.py
# * Additional ruff configuration for snapcraft_legacy
# * Include isort
# * Do not use tmpfs for a temporary directory as it does not support user xattrs
# * Legacy tests (inherited from integration tests) include coverage
# * Pylint included
[tox]
env_list = # Environments to run when called with no parameters.
lint-{black,ruff,isort,mypy,pylint,pyright,shellcheck,codespell,yaml}
test-py38
test-legacy-py38
minversion = 4.5
# Tox will use these requirements to bootstrap a venv if necessary.
# tox-igore-env-name-mismatch allows us to have one virtualenv for all linting.
# By setting requirements here, we make this INI file compatible with older
# versions of tox. Tox >= 3.8 will automatically provision the version provided
# inside of a virtual environment, so users of Ubuntu >= focal can simply
# install tox from apt. Older than that, the user gets an upgrade warning.
requires =
# renovate: datasource=pypi
tox-ignore-env-name-mismatch==0.2.0.post2
# Allow tox to access the user's $TMPDIR environment variable if set.
# This workaround is required to avoid circular dependencies for TMPDIR,
# since tox will otherwise attempt to use the environment's TMPDIR variable.
user_tmp_dir = {env:TMPDIR}
[testenv] # Default config for all environments. Overridable in each env.
# We have many tests that create temporary files. Unless the user has set a
# TMPDIR, this will prefer putting those temp files in $XDG_RUNTIME_DIR,
# which will speed up those tests since they'll run on a ramdisk.
env_tmp_dir = {user_tmp_dir:{work_dir}}/tox_tmp/{env_name}
set_env =
SNAPCRAFT_IGNORE_YAML_BINDINGS = 1
TMPDIR={env_tmp_dir}
COVERAGE_FILE={env_tmp_dir}/.coverage_{env_name}
[test] # Base configuration for unit and integration tests
deps = -r{tox_root}/requirements-devel.txt
package = wheel
allowlist_externals = mkdir
commands_pre = mkdir -p results
[testenv:test-{py38,py39,py310,py311,py312}] # Configuration for all tests using pytest
base = testenv, test
description = Run unit tests with pytest
labels =
py38, py310, py311: tests, unit-tests
commands = pytest {tty:--color=yes} --cov --cov-report=xml:results/coverage-{env_name}.xml --junit-xml=results/test-results-{env_name}.xml {posargs:tests/unit}
[testenv:test-legacy-{py38,py39,py310,py311,py312}]
base = testenv, test
description = Run legacy tests with pytest
labels =
py38, py310, py311: tests, integration-tests
commands = pytest {tty:--color=yes} --cov --cov-report=xml:results/coverage-{env_name}.xml --junit-xml=results/test-results-{env_name}.xml {posargs:tests/legacy}
[testenv:test-noreq]
base = testenv
description = Run all tests without using requirements.txt
package = wheel
deps = python-apt@http://archive.ubuntu.com/ubuntu/pool/main/p/python-apt/python-apt_2.4.0ubuntu1.tar.xz
extras = dev
allowlist_externals = mkdir
commands_pre = mkdir -p results
commands =
pytest {tty:--color=yes} --cov --cov-report=xml:results/coverage-{env_name}.xml --junit-xml=results/test-results-{env_name}.xml tests/unit {posargs}
pytest {tty:--color=yes} --junit-xml=results/legacy-test-results-{env_name}.xml tests/legacy {posargs}
[lint] # Standard linting configuration
package = editable
extras = dev
env_dir = {work_dir}/linting
runner = ignore_env_name_mismatch
[shellcheck]
find = git ls-files
filter = file --mime-type -Nnf- | grep shellscript | cut -f1 -d:
[testenv:lint-{black,ruff,docstyle,isort,shellcheck,codespell,yaml}]
description = Lint the source code
base = testenv, lint
labels = lint
allowlist_externals =
shellcheck: bash, xargs
commands_pre =
shellcheck: bash -c '{[shellcheck]find} | {[shellcheck]filter} > {env_tmp_dir}/shellcheck_files'
commands =
black: black --check --diff {tty:--color} {posargs} .
ruff: ruff --diff --respect-gitignore setup.py snapcraft tests tools
ruff: ruff --config snapcraft_legacy/ruff.toml snapcraft_legacy tests/legacy
isort: isort --check snapcraft snapcraft_legacy tests setup.py tools
docstyle: pydocstyle snapcraft
shellcheck: xargs -ra {env_tmp_dir}/shellcheck_files shellcheck
shellcheck: python3 tools/spread-shellcheck.py spread.yaml tests/spread/
codespell: codespell --toml {tox_root}/pyproject.toml {posargs}
yaml: yamllint {posargs} .
[testenv:lint-pylint]
description = Lint with pylint
base = testenv
labels = lint
deps = -r{tox_root}/requirements-devel.txt
package = editable
# This runs all commands even if the first fails.
# Not to be confused with ignore_outcome, which turns errors into warnings.
ignore_errors = true
commands =
pylint -j 0 snapcraft
pylint -j 0 tests --disable=invalid-name,missing-module-docstring,missing-function-docstring,duplicate-code,protected-access,unspecified-encoding,too-many-public-methods,too-many-arguments,too-many-lines,redefined-outer-name
[testenv:lint-{mypy,pyright}]
description = Static type checking
base = testenv
deps =
-r{tox_root}/requirements-devel.txt
env_dir = {work_dir}/typing
runner = ignore_env_name_mismatch
package = editable
extras = [dev, types]
labels = lint, type
allowlist_externals =
pyright: pyright
mypy: mkdir
commands_pre =
mypy: mkdir -p .mypy_cache
commands =
pyright: pyright {posargs}
mypy: mypy --install-types --non-interactive .
[testenv:format-{black,ruff,codespell}]
description = Automatically format source code
base = testenv, lint
labels = format
commands =
black: black {tty:--color} {posargs} .
ruff:
ruff --fix --respect-gitignore setup.py snapcraft tests tools
ruff --fix --config snapcraft_legacy/ruff.toml snapcraft_legacy tests/legacy
codespell: codespell --toml {tox_root}/pyproject.toml --write-changes {posargs}
[docs] # Sphinx documentation configuration
extras = docs
package = editable
no_package = true
env_dir = {work_dir}/docs
runner = ignore_env_name_mismatch
deps =
-r{tox_root}/requirements.txt
# renovate: datasource=pypi
Sphinx==6.1.3
# renovate: datasource=pypi
sphinx_design==0.4.1
# renovate: datasource=pypi
sphinx-copybutton==0.5.1
# renovate: datasource=pypi
sphinx-pydantic==0.1.1
# renovate: datasource=pypi
sphinx-toolbox==0.1.0
# renovate: datasource=pypi
sphinx-lint==0.6.7
[testenv:build-docs]
description = Build sphinx documentation
base = docs
allowlist_externals = bash
commands_pre = bash -c 'if [[ ! -e docs ]];then echo "No docs directory. Run `tox run -e sphinx-quickstart` to create one.;";return 1;fi'
# "-W" is to treat warnings as errors
commands = sphinx-build {posargs:-b html} -W {tox_root}/docs {tox_root}/docs/_build
[testenv:autobuild-docs]
description = Build documentation with an autoupdating server
base = docs
commands = sphinx-autobuild {posargs:-b html --open-browser --port 8080} -W --watch {tox_root}/snapcraft {tox_root}/snapcraft_legacy {tox_root}/docs {tox_root}/docs/_build
[testenv:lint-docs]
description = Lint the documentation with sphinx-lint
base = docs
commands = sphinx-lint --ignore docs/_build -e all {posargs} docs/
labels = lint