Skip to content

Commit

Permalink
Native TOML support for tox (#460)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
paddyroddy and dstansby authored Oct 14, 2024
1 parent 0b32c99 commit a867d7b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 66 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
cache-dependency-path: pyproject.toml

- name: Install dependencies
run: python -m pip install tox tox-gh-actions
run: python -m pip install tox tox-gh

- name: Run tests
run: tox
run: tox run
env:
OS: ${{ matrix.os }}
TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }}
48 changes: 22 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,27 @@ spaces_indent_inline_array = 4
trailing_comma_inline_array = true
overrides."project.classifiers".inline_arrays = false
overrides."tool.coverage.paths.source".inline_arrays = false
overrides."tool.tox.env_run_base.commands".inline_arrays = false

[tool.tox]
legacy_tox_ini = """
[gh-actions]
python =
3.11: py311
3.12: py312
3.13: py313
[gh-actions:env]
OS =
ubuntu-latest: linux
macos-latest: macos
windows-latest: windows
[testenv]
skip_install = true
description =
Test package creation
deps =
cookiecutter
pytest
commands =
pytest {posargs}
[tox]
env_list = py3{11,12,13}-{linux,macos,windows}
"""
env_list = [
"py311",
"py312",
"py313",
]
env_run_base = {commands = [
[
"pytest",
"{posargs}",
],
], deps = [
"cookiecutter",
"pytest",
], description = "Test package creation", skip_install = true}
gh.python = {"3.11" = [
"py311",
], "3.12" = [
"py312",
], "3.13" = [
"py313",
]}
9 changes: 5 additions & 4 deletions tests/test_package_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def test_package_generation(
# Check main files and directories inside
expected_files: set[pathlib.Path] = {
pathlib.Path(),
pathlib.Path(".git"),
pathlib.Path(".github"),
pathlib.Path(".github/ISSUE_TEMPLATE"),
pathlib.Path(".github/ISSUE_TEMPLATE/bug_report.yml"),
Expand Down Expand Up @@ -79,9 +78,11 @@ def test_package_generation(
}

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

assert actual_files == expected_files
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.project_slug}}/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
cache-dependency-path: pyproject.toml

- name: Install dependencies
run: python -m pip install tox tox-gh-actions
run: python -m pip install tox tox-gh

- name: Test with tox
run: tox
run: tox run
63 changes: 32 additions & 31 deletions {{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,36 +111,37 @@ spaces_indent_inline_array = 4
trailing_comma_inline_array = true
overrides."project.classifiers".inline_arrays = false
overrides."tool.coverage.paths.source".inline_arrays = false
overrides."tool.tox.env.docs.commands".inline_arrays = false
overrides."tool.tox.env_run_base.commands".inline_arrays = false

[tool.tox]
legacy_tox_ini = """
[gh-actions]
python =
{%- for python_version in range(
cookiecutter.min_python_version | replace('3.', '') | int,
cookiecutter.max_python_version | replace('3.', '') | int + 1
) %}
3.{{python_version}}: py3{{python_version}}
{%- endfor %}
[testenv]
commands =
pytest --cov --cov-report=xml
extras =
test
[testenv:docs]
commands =
mkdocs build --strict
extras =
docs
[tox]
env_list =
{%- for python_version in range(
cookiecutter.min_python_version | replace('3.', '') | int,
cookiecutter.max_python_version | replace('3.', '') | int + 1
) %}
py3{{python_version}}
{%- endfor %}
"""
env_list = [
{%- for python_version in range(
cookiecutter.min_python_version | replace('3.', '') | int,
cookiecutter.max_python_version | replace('3.', '') | int + 1
) %}
"py3{{python_version}}",
{%- endfor %}
]
env_run_base = {commands = [
[
"pytest",
"--cov",
"--cov-report=xml",
],
], extras = [
"test",
]}
env.docs = {commands = [
"mkdocs",
"build",
"--strict",
], extras = [
"docs",
]}
{%- for python_version in range(
cookiecutter.min_python_version | replace('3.', '') | int,
cookiecutter.max_python_version | replace('3.', '') | int + 1
) %}
gh.python."3.{{python_version}}" = ["py3{{python_version}}"]
{%- endfor %}

0 comments on commit a867d7b

Please sign in to comment.