forked from canonical/charmcraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtox.ini
116 lines (107 loc) · 4.13 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
[tox]
# Differences in tox configuration from starbase:
# 1. Docs not included
# 2. Charmcraft currently doesn't distinguish unit from integration tests
env_list = # Environments to run when called with no parameters.
format-{black,ruff,codespell}
pre-commit
lint-{black,ruff,mypy,pyright,shellcheck,codespell,yaml}
test-py3.10
# By default, only run tests on core22's Python 3.10
minversion = 4.6
# 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
# renovate: datasource=pypi
tox-gh==1.3.1
# 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:{env:XDG_RUNTIME_DIR:{work_dir}}}/tox_tmp/{env_name}
set_env =
TMPDIR={env_tmp_dir}
COVERAGE_FILE={env_tmp_dir}/.coverage_{env_name}
pass_env =
CI
CRAFT_*
PYTEST_ADDOPTS
[test] # Base configuration for unit and integration tests
package = editable
extras = dev
allowlist_externals = mkdir
commands_pre = mkdir -p {tox_root}/results
[testenv:{test}-py3.{10,11,12}] # Configuration for all tests using pytest
base = testenv, test
deps =
-rrequirements-dev.txt
-rrequirements-jammy.txt
description = Run tests with pytest
labels =
py3.{10,11,12}: tests
commands = pytest {tty:--color=yes} --cov={tox_root}/charmcraft --cov-config={tox_root}/pyproject.toml --cov-report=xml:{tox_root}/results/coverage-{env_name}.xml --junit-xml={tox_root}/results/test-results-{env_name}.xml {posargs}
[lint] # Standard linting configuration
package = editable
extras = lint
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,shellcheck,codespell,yaml}]
description = Lint the source code
base = testenv, lint
labels = lint
allowlist_externals =
shellcheck: bash, xargs
ruff: ruff
commands_pre =
shellcheck: bash -c '{[shellcheck]find} | {[shellcheck]filter} > {env_tmp_dir}/shellcheck_files'
commands =
black: black --check --diff {tty:--color} {posargs} .
ruff: ruff check --respect-gitignore {posargs:.}
shellcheck: xargs -ra {env_tmp_dir}/shellcheck_files shellcheck
codespell: codespell --toml {tox_root}/pyproject.toml {posargs}
yaml: yamllint {posargs} .
[testenv:lint-{mypy,pyright}]
description = Static type checking
base = testenv, lint
env_dir = {work_dir}/typing
extras = dev, types
labels = lint, type
allowlist_externals =
mypy: mkdir
commands_pre =
mypy: mkdir -p {tox_root}/.mypy_cache
commands =
pyright: pyright {posargs}
mypy: mypy --install-types --non-interactive {posargs}
[testenv:format-{black,ruff,codespell}]
description = Automatically format source code
base = testenv, lint
labels = format
allowlist_externals =
ruff: ruff
commands =
black: black {tty:--color} {posargs} .
ruff: ruff check --fix --respect-gitignore {posargs:.}
codespell: codespell --toml {tox_root}/pyproject.toml --write-changes {posargs}
[testenv:pre-commit]
base =
deps = pre-commit
package = skip
no_package = true
env_dir = {work_dir}/pre-commit
runner = ignore_env_name_mismatch
description = Run pre-commit on staged files or arbitrary pre-commit commands (tox run -e pre-commit -- [args])
commands = pre-commit {posargs:run}