Skip to content

Commit ece5df5

Browse files
authored
Setup tox to run checks locally and in CI (pelme#132)
* Formatting and sorting * Split deps into multiple groups So that tox can install as few packages as possible. * Setup tox + tox-uv for local testing * Use tox in CI jobs
1 parent f7d854d commit ece5df5

2 files changed

Lines changed: 146 additions & 74 deletions

File tree

.github/workflows/main.yml

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ on:
66
branches: [main]
77

88
jobs:
9-
pre-commit:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v4
13-
- uses: astral-sh/setup-uv@v6
14-
with:
15-
python-version: "3.13"
16-
- run: uv run pre-commit run --all-files
17-
189
build:
1910
runs-on: ubuntu-latest
2011
steps:
@@ -24,46 +15,49 @@ jobs:
2415
fetch-depth: 0
2516
- uses: hynek/build-and-inspect-python-package@v2
2617

27-
pytest:
28-
runs-on: ubuntu-latest
29-
strategy:
30-
fail-fast: false
31-
matrix:
32-
python-version:
33-
- "3.10"
34-
- "3.11"
35-
- "3.12"
36-
- "3.13"
37-
- "3.14"
38-
steps:
39-
- uses: actions/checkout@v4
40-
- uses: astral-sh/setup-uv@v6
41-
with:
42-
python-version: ${{ matrix.python-version }}
43-
- run: uv run pytest
44-
45-
mypy:
46-
runs-on: ubuntu-latest
18+
tests:
4719
strategy:
4820
fail-fast: false
4921
matrix:
50-
python-version: ["3.10", "3.11", "3.12", "3.13"]
51-
steps:
52-
- uses: actions/checkout@v4
53-
- uses: astral-sh/setup-uv@v6
54-
with:
55-
python-version: ${{ matrix.python-version }}
56-
- run: uv run mypy
57-
58-
pyright:
22+
include:
23+
- name: pytest (3.10)
24+
python: "3.10"
25+
tox: "3.10"
26+
- name: pytest (3.11)
27+
python: "3.11"
28+
tox: "3.11"
29+
- name: pytest (3.12)
30+
python: "3.12"
31+
tox: "3.12"
32+
- name: pytest (3.13)
33+
python: "3.13"
34+
tox: "3.13"
35+
coverage: true
36+
- name: pytest (3.14)
37+
python: "3.14"
38+
tox: "3.14"
39+
- name: mypy
40+
python: "3.13"
41+
tox: mypy
42+
- name: pyright
43+
python: "3.13"
44+
tox: pyright
45+
- name: ruff format
46+
python: "3.13"
47+
tox: ruff-format
48+
- name: ruff check
49+
python: "3.13"
50+
tox: ruff-check
51+
- name: docs
52+
python: "3.13"
53+
tox: docs
54+
name: ${{ matrix.name }}
5955
runs-on: ubuntu-latest
60-
strategy:
61-
fail-fast: false
62-
matrix:
63-
python-version: ["3.10", "3.11", "3.12", "3.13"]
6456
steps:
6557
- uses: actions/checkout@v4
6658
- uses: astral-sh/setup-uv@v6
6759
with:
68-
python-version: ${{ matrix.python-version }}
69-
- run: uv run pyright
60+
python-version: ${{ matrix.python }}
61+
activate-environment: true
62+
- run: uv pip install tox tox-uv
63+
- run: tox -e ${{ matrix.tox }}

pyproject.toml

Lines changed: 108 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ dependencies = [
99
"typing_extensions>=4.13.2 ; python_version<'3.13'",
1010
]
1111
readme = "docs/README.md"
12-
authors = [
13-
{ name="Andreas Pelme", email="andreas@pelme.se" },
14-
]
12+
authors = [{ name = "Andreas Pelme", email = "andreas@pelme.se" }]
1513
license = "MIT"
1614
classifiers = [
1715
"Programming Language :: Python :: 3",
@@ -25,21 +23,29 @@ classifiers = [
2523
[dependency-groups]
2624
dev = [
2725
"pre-commit",
28-
"mypy",
29-
"pyright",
30-
"pytest",
26+
"tox>=4.21.2",
27+
"tox-uv>=1.23.2",
28+
{ include-group = "docs" },
29+
{ include-group = "mypy" },
30+
{ include-group = "pyright" },
31+
{ include-group = "ruff" },
32+
{ include-group = "tests" },
33+
]
34+
docs = ["mkdocs-material==9.5.12"]
35+
mypy = ["mypy"]
36+
pyright = ["pyright"]
37+
ruff = ["ruff"]
38+
tests = [
3139
"black",
32-
"ruff",
3340
"django",
3441
"django-stubs",
35-
"jinja2",
36-
"starlette",
3742
"httpx",
43+
"jinja2",
3844
"markdown",
39-
"pytest-doctestplus"
40-
]
41-
docs = [
42-
"mkdocs-material==9.5.12",
45+
"pytest",
46+
"pytest-doctestplus",
47+
"ruff",
48+
"starlette",
4349
]
4450

4551
[project.urls]
@@ -51,38 +57,110 @@ Issues = "https://github.com/pelme/htpy/issues"
5157
[project.scripts]
5258
html2htpy = "htpy.html2htpy:main"
5359

60+
5461
[build-system]
5562
requires = ["setuptools>=64", "setuptools-scm>=8"]
5663
build-backend = "setuptools.build_meta"
5764

5865
[tool.setuptools_scm]
5966

60-
[tool.ruff]
61-
line-length = 100
62-
lint.select = [
63-
"F", # Pyflakes
64-
"E", # pycodestyle error
65-
"W", # pycodestyle warning
66-
"I", # isort
67-
"B", # flake8-bugbear
68-
"C4", # flake8-comprehensions
69-
"TCH", # flake8-type-checking
70-
"RUF100", # yesqa equivalence
71-
"UP", # pyupgrade
72-
"TID", # flake8-tidy-imports
73-
]
74-
lint.ignore = [
75-
"B904",
76-
]
7767

7868
[tool.mypy]
7969
strict = true
8070
packages = ["htpy", "tests"]
8171
exclude = ["examples", "scripts"]
8272

73+
8374
[tool.pyright]
8475
include = ["htpy", "tests"]
8576
strict = ["htpy", "tests"]
8677

78+
8779
[tool.pytest.ini_options]
8880
addopts = "--doctest-glob='docs/*.md'"
81+
82+
83+
[tool.ruff]
84+
line-length = 100
85+
86+
[tool.ruff.lint]
87+
select = [
88+
"F", # Pyflakes
89+
"E", # pycodestyle error
90+
"W", # pycodestyle warning
91+
"I", # isort
92+
"B", # flake8-bugbear
93+
"C4", # flake8-comprehensions
94+
"TCH", # flake8-type-checking
95+
"RUF100", # yesqa equivalence
96+
"UP", # pyupgrade
97+
"TID", # flake8-tidy-imports
98+
]
99+
ignore = ["B904"]
100+
101+
102+
[tool.tox]
103+
env_list = [
104+
"3.10",
105+
"3.11",
106+
"3.12",
107+
"3.13",
108+
"3.14",
109+
"docs",
110+
"mypy",
111+
"pyright",
112+
"ruff-format",
113+
"ruff-check",
114+
]
115+
116+
[tool.tox.env_run_base]
117+
package = "wheel"
118+
wheel_build_env = ".pkg"
119+
dependency_groups = ["tests"]
120+
commands = [
121+
[
122+
"pytest",
123+
"--basetemp={envtmpdir}",
124+
"tests", # unit tests
125+
"{envsitepackagesdir}/htpy", # doctests
126+
{ replace = "posargs", extend = true },
127+
],
128+
]
129+
130+
[tool.tox.env.docs]
131+
dependency_groups = ["docs"]
132+
commands = [["mkdocs", "build", "--site-dir={envtmpdir}"]]
133+
134+
[tool.tox.env.mypy]
135+
dependency_groups = ["tests", "mypy"]
136+
commands = [
137+
[
138+
"mypy",
139+
{ replace = "posargs", default = [
140+
"htpy",
141+
"tests",
142+
], extend = true },
143+
],
144+
]
145+
146+
[tool.tox.env.pyright]
147+
dependency_groups = ["tests", "pyright"]
148+
commands = [
149+
[
150+
"pyright",
151+
{ replace = "posargs", default = [
152+
"htpy",
153+
"tests",
154+
], extend = true },
155+
],
156+
]
157+
158+
[tool.tox.env.ruff-format]
159+
skip_install = true
160+
dependency_groups = ["ruff"]
161+
commands = [["ruff", "format", "--check", "{posargs:.}"]]
162+
163+
[tool.tox.env.ruff-check]
164+
skip_install = true
165+
dependency_groups = ["ruff"]
166+
commands = [["ruff", "check", "{posargs:.}"]]

0 commit comments

Comments
 (0)