Skip to content

Commit a867d7b

Browse files
paddyroddydstansby
andauthored
Native TOML support for tox (#460)
Fixes #455. In order to do this, have also switched from `tox-gh-actions` to `tox-gh`. Has been tested in astro-informatics/sleplet#420, astro-informatics/sleplet#421. - [x] Will need to check if templating works correctly --------- Co-authored-by: David Stansby <[email protected]>
1 parent 0b32c99 commit a867d7b

5 files changed

Lines changed: 64 additions & 66 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ jobs:
4040
cache-dependency-path: pyproject.toml
4141

4242
- name: Install dependencies
43-
run: python -m pip install tox tox-gh-actions
43+
run: python -m pip install tox tox-gh
4444

4545
- name: Run tests
46-
run: tox
46+
run: tox run
4747
env:
48-
OS: ${{ matrix.os }}
48+
TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }}

pyproject.toml

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,27 @@ spaces_indent_inline_array = 4
3838
trailing_comma_inline_array = true
3939
overrides."project.classifiers".inline_arrays = false
4040
overrides."tool.coverage.paths.source".inline_arrays = false
41+
overrides."tool.tox.env_run_base.commands".inline_arrays = false
4142

4243
[tool.tox]
43-
legacy_tox_ini = """
44-
[gh-actions]
45-
python =
46-
3.11: py311
47-
3.12: py312
48-
3.13: py313
49-
50-
[gh-actions:env]
51-
OS =
52-
ubuntu-latest: linux
53-
macos-latest: macos
54-
windows-latest: windows
55-
56-
[testenv]
57-
skip_install = true
58-
description =
59-
Test package creation
60-
deps =
61-
cookiecutter
62-
pytest
63-
commands =
64-
pytest {posargs}
65-
66-
[tox]
67-
env_list = py3{11,12,13}-{linux,macos,windows}
68-
"""
44+
env_list = [
45+
"py311",
46+
"py312",
47+
"py313",
48+
]
49+
env_run_base = {commands = [
50+
[
51+
"pytest",
52+
"{posargs}",
53+
],
54+
], deps = [
55+
"cookiecutter",
56+
"pytest",
57+
], description = "Test package creation", skip_install = true}
58+
gh.python = {"3.11" = [
59+
"py311",
60+
], "3.12" = [
61+
"py312",
62+
], "3.13" = [
63+
"py313",
64+
]}

tests/test_package_generation.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def test_package_generation(
4646
# Check main files and directories inside
4747
expected_files: set[pathlib.Path] = {
4848
pathlib.Path(),
49-
pathlib.Path(".git"),
5049
pathlib.Path(".github"),
5150
pathlib.Path(".github/ISSUE_TEMPLATE"),
5251
pathlib.Path(".github/ISSUE_TEMPLATE/bug_report.yml"),
@@ -79,9 +78,11 @@ def test_package_generation(
7978
}
8079

8180
actual_files = get_all_files_folders(test_project_dir)
82-
# Filter out anything under .git/ to make comparison easier
83-
actual_files = actual_files - {
84-
a for a in actual_files if len(a.parts) > 1 and a.parts[0] == ".git"
81+
# Filter out anything under specific directories to make comparison easier
82+
actual_files = {
83+
a
84+
for a in actual_files
85+
if not (a.parts and (a.parts[0] == ".git" or "__pycache__" in a.parts))
8586
}
8687

8788
assert actual_files == expected_files

{{cookiecutter.project_slug}}/.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
cache-dependency-path: pyproject.toml
4040

4141
- name: Install dependencies
42-
run: python -m pip install tox tox-gh-actions
42+
run: python -m pip install tox tox-gh
4343

4444
- name: Test with tox
45-
run: tox
45+
run: tox run

{{cookiecutter.project_slug}}/pyproject.toml

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -111,36 +111,37 @@ spaces_indent_inline_array = 4
111111
trailing_comma_inline_array = true
112112
overrides."project.classifiers".inline_arrays = false
113113
overrides."tool.coverage.paths.source".inline_arrays = false
114+
overrides."tool.tox.env.docs.commands".inline_arrays = false
115+
overrides."tool.tox.env_run_base.commands".inline_arrays = false
114116

115117
[tool.tox]
116-
legacy_tox_ini = """
117-
[gh-actions]
118-
python =
119-
{%- for python_version in range(
120-
cookiecutter.min_python_version | replace('3.', '') | int,
121-
cookiecutter.max_python_version | replace('3.', '') | int + 1
122-
) %}
123-
3.{{python_version}}: py3{{python_version}}
124-
{%- endfor %}
125-
126-
[testenv]
127-
commands =
128-
pytest --cov --cov-report=xml
129-
extras =
130-
test
131-
132-
[testenv:docs]
133-
commands =
134-
mkdocs build --strict
135-
extras =
136-
docs
137-
138-
[tox]
139-
env_list =
140-
{%- for python_version in range(
141-
cookiecutter.min_python_version | replace('3.', '') | int,
142-
cookiecutter.max_python_version | replace('3.', '') | int + 1
143-
) %}
144-
py3{{python_version}}
145-
{%- endfor %}
146-
"""
118+
env_list = [
119+
{%- for python_version in range(
120+
cookiecutter.min_python_version | replace('3.', '') | int,
121+
cookiecutter.max_python_version | replace('3.', '') | int + 1
122+
) %}
123+
"py3{{python_version}}",
124+
{%- endfor %}
125+
]
126+
env_run_base = {commands = [
127+
[
128+
"pytest",
129+
"--cov",
130+
"--cov-report=xml",
131+
],
132+
], extras = [
133+
"test",
134+
]}
135+
env.docs = {commands = [
136+
"mkdocs",
137+
"build",
138+
"--strict",
139+
], extras = [
140+
"docs",
141+
]}
142+
{%- for python_version in range(
143+
cookiecutter.min_python_version | replace('3.', '') | int,
144+
cookiecutter.max_python_version | replace('3.', '') | int + 1
145+
) %}
146+
gh.python."3.{{python_version}}" = ["py3{{python_version}}"]
147+
{%- endfor %}

0 commit comments

Comments
 (0)