Skip to content

Commit

Permalink
FEAT: check defined jobs in tox.ini (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer authored Dec 9, 2023
1 parent f89021e commit 1da5980
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/repoma/check_dev_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
ruff,
setup_cfg,
toml,
tox,
update_pip_constraints,
vscode,
)
Expand Down Expand Up @@ -96,6 +97,7 @@ def main(argv: Sequence[str] | None = None) -> int:
executor(vscode.main, has_notebooks)
executor(gitpod.main, args.no_gitpod, dev_python_version)
executor(precommit.main)
executor(tox.main, has_notebooks)
return executor.finalize(exception=False)


Expand Down
46 changes: 46 additions & 0 deletions src/repoma/check_dev_files/tox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Check Tox configuration file."""

from __future__ import annotations

from configparser import ConfigParser
from pathlib import Path

from repoma.errors import PrecommitError
from repoma.utilities import CONFIG_PATH


def main(has_notebooks: bool) -> None:
if not CONFIG_PATH.tox.exists():
return
tox = _read_tox_config(CONFIG_PATH.tox)
_check_expected_sections(tox, has_notebooks)


def _read_tox_config(path: Path) -> ConfigParser:
config = ConfigParser()
config.read(path)
return config


def _check_expected_sections(tox: ConfigParser, has_notebooks: bool) -> None:
# cspell:ignore doclive docnb docnblive testenv
sections: set[str] = set(tox)
expected_sections: set[str] = set()
if Path("docs").exists():
expected_sections |= {
"testenv:doc",
"testenv:doclive",
}
if has_notebooks:
expected_sections |= {
"testenv:docnb",
"testenv:docnblive",
"testenv:nb",
}
missing_sections = expected_sections - sections
if missing_sections:
msg = (
f"{CONFIG_PATH.tox} is missing job definitions:"
f" {', '.join(sorted(missing_sections))}"
)
raise PrecommitError(msg)

0 comments on commit 1da5980

Please sign in to comment.