Skip to content

Commit

Permalink
DOC: auto check pre-commit examples use latest stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Aug 14, 2024
1 parent 023f535 commit cab30e1
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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"
Expand Down
40 changes: 40 additions & 0 deletions scripts/check_readme.py
Original file line number Diff line number Diff line change
@@ -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())
5 changes: 4 additions & 1 deletion src/inifix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cab30e1

Please sign in to comment.