Skip to content

Commit

Permalink
FEAT: convert Tox config to native TOML (#475)
Browse files Browse the repository at this point in the history
* BREAK: rename to `read_tox_ini_config()`
* DX: add `coverage.xml` to `.gitignore`
* DX: define `tox` jobs in native TOML
* DX: ignore cSpell words in `.taplo.toml`
* DX: lower minimal test coverage to 30%
* DX: sort `env_run_base` first
* FEAT: convert Tox config to native TOML
* FIX: do not sort arrays under `tool.tox` table
* MAINT: modernize Tox config keywords
  https://tox.wiki/en/stable/config.html#core
* MAINT: move `{posargs}` closer to `pytest`
* MAINT: remove redundant `.vscode/.gitignore` exclusion
  • Loading branch information
redeboer authored Dec 26, 2024
1 parent 47f35ff commit dff4dc3
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 86 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
".gitpod.*",
".pre-commit-config.yaml",
".prettierignore",
".taplo.toml",
".vscode/*",
"codecov.yml",
"docs/_templates/*",
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ version.py
.mypy*/
.pytest_cache/
__pycache__/
coverage.xml
htmlcov/
oryx-build-commands.txt
prof/
Expand Down
7 changes: 7 additions & 0 deletions .taplo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ compact_inline_tables = true
indent_string = " "
reorder_arrays = true
reorder_keys = true

[[rule]]
include = ["**/pyproject.toml"]
keys = ["tool.tox"]

[rule.formatting]
reorder_arrays = false
167 changes: 90 additions & 77 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -280,85 +280,98 @@ sort_first = [
"project",
"tool.setuptools",
"tool.setuptools_scm",
"tool.tox.env_run_base",
]
spaces_indent_inline_array = 4
trailing_comma_inline_array = true

[tool.tox]
legacy_tox_ini = """
[tox]
envlist =
cov
doc
linkcheck
sty
skip_install = True
skip_missing_interpreters = True
skipsdist = True
[testenv]
allowlist_externals =
pytest
commands =
pytest {posargs}
description = Run all unit tests
passenv = *
[testenv:cov]
allowlist_externals =
pytest
commands =
pytest {posargs} \
--cov-fail-under=35 \
--cov-report=html \
--cov-report=xml \
--cov=compwa_policy
description = Compute test coverage
[testenv:doc]
allowlist_externals =
sphinx-build
commands =
sphinx-build \
--builder=html \
--fail-on-warning \
--keep-going \
--show-traceback \
docs/ docs/_build/html
description = Build documentation and API through Sphinx
[testenv:doclive]
allowlist_externals =
sphinx-autobuild
commands =
sphinx-autobuild \
--ignore=docs/_build \
--ignore=docs/api \
--open-browser \
--port=0 \
--re-ignore='.*\\.egg-info' \
--re-ignore='.*/__pycache__/.*' \
--watch=docs \
--watch=src \
docs/ docs/_build/html
description = Set up a server to directly preview changes to the HTML pages
[testenv:linkcheck]
allowlist_externals =
sphinx-build
commands =
sphinx-build \
--builder=linkcheck \
--show-traceback \
docs/ docs/_build/linkcheck
description = Check external links in the documentation (requires internet connection)
setenv =
PYTHONWARNINGS =
[testenv:sty]
allowlist_externals =
pre-commit
commands =
pre-commit run --all-files {posargs}
description = Perform all linting, formatting, and spelling checks
"""
env_list = [
"cov",
"doc",
"linkcheck",
"sty",
]
no_package = true
requires = ["tox>=4.19"]
skip_install = true
skip_missing_interpreters = true

[tool.tox.env_run_base]
allowlist_externals = ["pytest"]
commands = [
["pytest", "{posargs}"],
]
description = "Run all unit tests"
pass_env = ["*"]

[tool.tox.env.cov]
allowlist_externals = ["pytest"]
commands = [
[
"pytest",
"{posargs}",
"--cov-fail-under=30",
"--cov-report=html",
"--cov-report=xml",
"--cov=compwa_policy",
],
]
description = "Compute test coverage"

[tool.tox.env.doc]
allowlist_externals = ["sphinx-build"]
commands = [
[
"sphinx-build",
"--builder=html",
"--fail-on-warning",
"--keep-going",
"--show-traceback",
"docs/",
"docs/_build/html",
],
]
description = "Build documentation and API through Sphinx"

[tool.tox.env.doclive]
allowlist_externals = ["sphinx-autobuild"]
commands = [
[
"sphinx-autobuild",
"--ignore=docs/_build",
"--ignore=docs/api",
"--open-browser",
"--port=0",
"--re-ignore='.*\\.egg-info'",
"--re-ignore='.*/__pycache__/.*'",
"--watch=docs",
"--watch=src",
"docs/",
"docs/_build/html",
],
]
description = "Set up a server to directly preview changes to the HTML pages"

[tool.tox.env.linkcheck]
allowlist_externals = ["sphinx-build"]
commands = [
[
"sphinx-build",
"--builder=linkcheck",
"--show-traceback",
"docs/",
"docs/_build/linkcheck",
],
]
description = "Check external links in the documentation (requires internet connection)"
set_env = [
{PYTHONWARNINGS = ""},
]

[tool.tox.env.sty]
allowlist_externals = ["pre-commit"]
commands = [
["pre-commit", "run", "--all-files", "{posargs}"],
]
description = "Perform all linting, formatting, and spelling checks"
2 changes: 1 addition & 1 deletion src/compwa_policy/.template/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
".pre-commit-config.yaml",
".prettierignore",
".readthedocs.yml",
".taplo.toml",
".vscode/*",
".vscode/.gitignore",
"CITATION.cff",
"codecov.yml",
"Dockerfile",
Expand Down
7 changes: 7 additions & 0 deletions src/compwa_policy/.template/.taplo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ compact_inline_tables = true
indent_string = " "
reorder_arrays = true
reorder_keys = true

[[rule]]
include = ["**/pyproject.toml"]
keys = ["tool.tox"]

[rule.formatting]
reorder_arrays = false
6 changes: 3 additions & 3 deletions src/compwa_policy/check_dev_files/pixi/_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tomlkit import inline_table, string

from compwa_policy.check_dev_files.pixi._helpers import has_pixi_config
from compwa_policy.check_dev_files.tox import read_tox_config
from compwa_policy.check_dev_files.tox import read_tox_ini_config
from compwa_policy.errors import PrecommitError
from compwa_policy.utilities import CONFIG_PATH, append_safe, vscode
from compwa_policy.utilities.executor import Executor
Expand Down Expand Up @@ -179,7 +179,7 @@ def _import_conda_environment(config: ModifiablePyproject) -> None:


def _import_tox_tasks(config: ModifiablePyproject) -> None:
tox = read_tox_config()
tox = read_tox_ini_config()
if tox is None:
return
tox_jobs = __get_tox_job_names(tox)
Expand Down Expand Up @@ -295,7 +295,7 @@ def _install_package_editable(config: ModifiablePyproject) -> None:


def __outsource_pixi_tasks_to_tox(config: ModifiablePyproject) -> None:
tox = read_tox_config()
tox = read_tox_ini_config()
if tox is None:
return
blacklisted_jobs = {"sty"}
Expand Down
1 change: 1 addition & 0 deletions src/compwa_policy/check_dev_files/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def _update_tomlsort_config() -> None:
"project",
"tool.setuptools",
"tool.setuptools_scm",
"tool.tox.env_run_base",
]
expected_config = dict(
all=False,
Expand Down
Loading

0 comments on commit dff4dc3

Please sign in to comment.