Skip to content

Commit 84b3a4a

Browse files
authored
Add tox (#23)
* Add and configure tox, address ruff config deprecation Signed-off-by: Federico Busetti <729029+febus982@users.noreply.github.com>
1 parent 7c8784b commit 84b3a4a

File tree

8 files changed

+124
-39
lines changed

8 files changed

+124
-39
lines changed

.bandit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ skips:
9494
### provided. It is not necessary to provide settings for every (or any) plugin
9595
### if the defaults are acceptable.
9696

97+
exclude_dirs: ['.tox']
98+
9799
any_other_function_with_shell_equals_true:
98100
no_shell:
99101
- os.execl

.idea/bootstrap-python-package.iml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Tox.xml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ ci-coverage:
1010
poetry run pytest --cov --cov-report lcov
1111

1212
typing:
13-
poetry run mypy
13+
tox -e typing
1414

1515
format:
16-
poetry run black --check .
16+
tox -e format
1717

1818
lint:
19-
poetry run ruff .
19+
tox -e lint
2020

2121
bandit:
22-
poetry run bandit -c .bandit.yml -r .
22+
tox -e bandit
2323

2424
format-fix:
2525
poetry run black .
@@ -34,7 +34,8 @@ update-dependencies:
3434
poetry update --with dev
3535

3636
fix: format-fix lint-fix
37-
check: typing format lint test bandit
37+
check:
38+
tox
3839

3940
docs:
4041
poetry run mkdocs serve

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
This template repository provides the boilerplate to create a python package.
1717
It is configured with all the following features:
1818

19-
* Test suite using [pytest](https://docs.pytest.org/en/7.4.x/)
19+
* Test suite using [tox](https://tox.wiki/en/latest/index.html) and [pytest](https://docs.pytest.org/en/7.4.x/)
2020
* Typing using [mypy](https://mypy.readthedocs.io/en/stable/)
2121
* Linting using [ruff](https://github.com/astral-sh/ruff)
2222
* Code formatter using [black](https://pypi.org/project/black/)
@@ -27,10 +27,6 @@ It is configured with all the following features:
2727
* releases on [PyPI](https://pypi.org)
2828
* GitHub pages documentation using [mkdocs](https://www.mkdocs.org)
2929

30-
This project doesn't currently use [tox](https://tox.wiki/en/4.11.4/index.html) or other matrix
31-
testing utilities. I prefer to run the tests only against the latest python locally, and run
32-
previous python versions directly in the CI pipeline.
33-
3430
## How to use this repository template to create a new package
3531

3632
* Create your github repository using this template. (The big green `Use this template` button)
@@ -84,7 +80,8 @@ All the common commands used during development can be run using make targets:
8480

8581
* `make dev-dependencies`: Install dev requirements
8682
* `make update-dependencies`: Update dev requirements
87-
* `make test`: Run test suite
88-
* `make check`: Run tests, code style and lint checks
8983
* `make fix`: Run code style and lint automatic fixes (where possible)
84+
* `make test`: Run test suite against system python version
85+
* `make check`: Run tests against all available python versions, code style and lint checks
86+
* `make type`, `make format`, `make lint`, `make bandit`: Run the relevant check
9087
* `make docs`: Render the mkdocs website locally

docs/index.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ It is configured with all the following features:
1414
* releases on [PyPI](https://pypi.org)
1515
* GitHub pages documentation using [mkdocs](https://www.mkdocs.org)
1616

17-
This project doesn't currently use [tox](https://tox.wiki/en/4.11.4/index.html) or other matrix
18-
testing utilities. I prefer to run the tests only against the latest python locally, and run
19-
previous python versions directly in the CI pipeline.
20-
2117
## How to use this repository template to create a new package
2218

2319
* Create your github repository using this template. (The big green `Use this template` button)
@@ -71,7 +67,8 @@ All the common commands used during development can be run using make targets:
7167

7268
* `make dev-dependencies`: Install dev requirements
7369
* `make update-dependencies`: Update dev requirements
74-
* `make test`: Run test suite
75-
* `make check`: Run tests, code style and lint checks
7670
* `make fix`: Run code style and lint automatic fixes (where possible)
71+
* `make test`: Run test suite against system python version
72+
* `make check`: Run tests against all available python versions, code style and lint checks
73+
* `make type`, `make format`, `make lint`, `make bandit`: Run the relevant check
7774
* `make docs`: Render the mkdocs website locally

pyproject.toml

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ classifiers = [
2828
]
2929

3030
[tool.poetry-dynamic-versioning]
31-
enable = true
31+
enable = false
3232

3333
[build-system]
3434
requires = ["poetry-core", "poetry-dynamic-versioning"]
3535
build-backend = "poetry_dynamic_versioning.backend"
3636

37+
############################
38+
### Package requirements ###
39+
############################
40+
3741
[tool.poetry.dependencies]
3842
python = ">=3.8,<3.13"
3943

@@ -57,17 +61,20 @@ pytest-cov = ">=4.0.0"
5761
pytest-factoryboy = ">=2.5.0"
5862
pytest-xdist = ">=3.0.2"
5963
ruff = ">=0.0.263"
64+
tox = ">=4.12.1"
6065

61-
[tool.pytest.ini_options]
62-
asyncio_mode = "auto"
63-
minversion = "6.0"
64-
addopts = "-n auto --cov-report=term-missing"
65-
testpaths = [
66-
"tests",
67-
]
66+
############################
67+
### Tools configuration ###
68+
############################
6869

69-
[tool.mypy]
70-
files = "bootstrap_python_package"
70+
[tool.black]
71+
target-version = ["py38", "py39", "py310", "py311", "py312"]
72+
extend-exclude = '''
73+
(
74+
/docs,
75+
.tox
76+
)
77+
'''
7178

7279
[tool.coverage.run]
7380
branch = true
@@ -83,17 +90,23 @@ exclude_also = [
8390
"\\.\\.\\.",
8491
]
8592

93+
[tool.mypy]
94+
files = "bootstrap_python_package"
95+
python_version = "3.8"
96+
97+
[tool.pytest.ini_options]
98+
asyncio_mode = "auto"
99+
minversion = "6.0"
100+
addopts = "-n auto --cov-report=term-missing"
101+
testpaths = [
102+
"tests",
103+
]
104+
86105
[tool.ruff]
106+
extend-exclude = ["docs", ".tox"]
107+
108+
[tool.ruff.lint]
87109
select = ["E", "F", "I"]
88-
extend-exclude = ["docs"]
89110

90-
[tool.ruff.per-file-ignores]
111+
[tool.ruff.lint.per-file-ignores]
91112
"__init__.py" = ["F401"]
92-
93-
[tool.black]
94-
target-version = ["py38", "py39", "py310", "py311", "py312"]
95-
extend-exclude = '''
96-
(
97-
/docs
98-
)
99-
'''

tox.ini

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[tox]
2+
min_version = 4.0
3+
env_list =
4+
py312
5+
py311
6+
py310
7+
py39
8+
py38
9+
typing
10+
format
11+
lint
12+
bandit
13+
14+
[testenv]
15+
allowlist_externals = poetry, pytest
16+
; Poetry is really bad in identifying running virtualenvs, so we can't use
17+
; directly poetry install. This is the best hacky way to install poetry
18+
; requirements inside tox.
19+
commands_pre =
20+
poetry export -f requirements.txt --output /tmp/requirements.txt --with dev
21+
pip install -Uqr /tmp/requirements.txt
22+
commands =
23+
pytest
24+
25+
[testenv:py312]
26+
; Run with coverage in one python version to check coverage percentage
27+
commands =
28+
pytest --cov
29+
30+
[testenv:typing]
31+
allowlist_externals = poetry, mypy
32+
; commands_pre is inherited from testenv
33+
commands =
34+
mypy
35+
36+
[testenv:format]
37+
allowlist_externals = poetry, black
38+
; commands_pre is inherited from testenv
39+
commands =
40+
black --check .
41+
42+
[testenv:lint]
43+
allowlist_externals = poetry, ruff
44+
; commands_pre is inherited from testenv
45+
commands =
46+
ruff .
47+
48+
[testenv:bandit]
49+
allowlist_externals = poetry, bandit
50+
; commands_pre is inherited from testenv
51+
commands =
52+
bandit -c .bandit.yml -r .

0 commit comments

Comments
 (0)