-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: check defined jobs in
tox.ini
(#251)
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |