From cab30e17c51a61161fdef91f0675395d40f59ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Robert?= Date: Wed, 14 Aug 2024 12:37:18 +0200 Subject: [PATCH] DOC: auto check pre-commit examples use latest stable version --- .github/workflows/ci.yml | 17 +++++++++++++++++ pyproject.toml | 5 +---- scripts/check_readme.py | 40 ++++++++++++++++++++++++++++++++++++++++ src/inifix/__init__.py | 5 ++++- 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 scripts/check_readme.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25d9752..ee67eb3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -149,3 +149,20 @@ jobs: - name: Run mypy run: mypy src/inifix + + + check-readme: + runs-on: ubuntu-latest + name: check README.md + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.x + + - run: python scripts/check_readme.py diff --git a/pyproject.toml b/pyproject.toml index fa90849..c5ea26e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "inifix" +version = "5.0.1" description = "An I/O library for Pluto-style ini files." authors = [ { name = "C.M.T. Robert" }, @@ -16,10 +17,6 @@ classifiers = [ "Typing :: Typed", ] requires-python = ">=3.10" -dynamic = ["version"] - -[tool.setuptools.dynamic] -version = {attr = "inifix.__version__"} [project.license] text = "GPL-3.0" diff --git a/scripts/check_readme.py b/scripts/check_readme.py new file mode 100644 index 0000000..e0389d4 --- /dev/null +++ b/scripts/check_readme.py @@ -0,0 +1,40 @@ +import re +import sys +from difflib import unified_diff +from pathlib import Path + +import tomllib + +REV_REGEXP = re.compile(r"rev:\s+v.*") +STABLE_VER_REGEXP = re.compile(r"^\d\.*\d\.\d$") +ROOT = Path(__file__).parents[1] +README = ROOT / "README.md" +PYPROJECT_TOML = ROOT / "pyproject.toml" + + +def main() -> int: + text = README.read_text() + + with open(PYPROJECT_TOML, "rb") as fh: + current_version = tomllib.load(fh)["project"]["version"] + + if not STABLE_VER_REGEXP.match(current_version): + return 0 + + if text == (expected := REV_REGEXP.sub(f"rev: v{current_version}", text)): + return 0 + + diff = "\n".join( + line.removesuffix("\n") + for line in unified_diff( + text.splitlines(), + expected.splitlines(), + fromfile=str(PYPROJECT_TOML), + ) + ) + print(diff, file=sys.stderr) + return 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/src/inifix/__init__.py b/src/inifix/__init__.py index dee75f4..435dafb 100644 --- a/src/inifix/__init__.py +++ b/src/inifix/__init__.py @@ -5,4 +5,7 @@ from .validation import validate_inifile_schema from .format import format_string -__version__ = "5.0.1" +from importlib.metadata import version + +__version__ = version("inifix") +del version