Skip to content

Commit

Permalink
chore: Added pyproject.toml verification
Browse files Browse the repository at this point in the history
- Added makefile verification directive for the pyproject.toml config file.
  checks that project's name and version matches the tool.poetry's equivalent.
  • Loading branch information
abellotti committed Jun 3, 2024
1 parent e44aa14 commit 4225621
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
python-version: ["3.11", "3.12"]
type:
[
config-verify,
manpage-test,
lint,
test-coverage,
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ test-coverage:
poetry run coverage report --show-missing
poetry run coverage xml

# verify the pyproject.toml configuration file integrity
config-verify:
$(PYTHON) config-verify.py

# write a man page (roff format) with placeholders for names, version, and dates
update-man-template-roff:
@$(SPHINX_BUILD) -b man -q \
Expand Down
29 changes: 29 additions & 0 deletions config-verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""QPC pyproject toml file verification."""

import sys
from pathlib import Path
from tomllib import load

toml_path = Path(__file__).absolute().parent / "pyproject.toml"
with toml_path.open("rb") as toml_file:
toml_data = load(toml_file)
project = toml_data["project"]
tool_poetry = toml_data["tool"]["poetry"]

if project["name"] != tool_poetry["name"]:
print(
"Project name {n1} does not match tool.poetry name {n2}".format(
n1=project["name"], n2=tool_poetry["name"]
),
file=sys.stderr,
)
sys.exit(1)

if project["version"] != tool_poetry["version"]:
print(
"Project version {v1} does not match tool.poetry version {v2}".format(
v1=project["version"], v2=tool_poetry["version"]
),
file=sys.stderr,
)
sys.exit(1)

0 comments on commit 4225621

Please sign in to comment.