From a656518ee07f8878a65cb0653000c6d705a42233 Mon Sep 17 00:00:00 2001 From: hejamu Date: Wed, 3 Apr 2024 15:40:01 +0200 Subject: [PATCH] Fix changelog check --- devtools/check_changelog.py | 32 +++++++++++++++++++++----------- docs/CHANGELOG.rst | 1 + tox.ini | 3 ++- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/devtools/check_changelog.py b/devtools/check_changelog.py index 6cc79d1..bc46120 100644 --- a/devtools/check_changelog.py +++ b/devtools/check_changelog.py @@ -5,11 +5,10 @@ * additions are reported in CHANGELOG.rst """ +import os from pathlib import Path -folder = Path(__file__).resolve().parents[1] -changelog = Path('docs', 'CHANGELOG.rst') -contributing = Path('docs', 'CONTRIBUTING.rst') +import git class ChangelogError(Exception): @@ -18,13 +17,24 @@ class ChangelogError(Exception): pass -with open(Path(folder, changelog), 'r') as fin: +folder = Path(__file__).resolve().parents[1] +changelog = Path("docs", "CHANGELOG.rst") +contributing = Path("docs", "CONTRIBUTING.rst") + +repo = git.Repo(folder) + +if repo.active_branch.name == "main": + print("You are on the main branch. Nothing to check.") + exit(0) + +with open(Path(folder, changelog), "r") as fin: for line in fin: - if line.startswith('v'): + if line.startswith("v"): raise ChangelogError( - 'You have not updated the CHANGELOG file. ' - f'Please add a summary of your additions to {str(changelog)!r} ' - f'as described in {str(contributing)!r}.' - ) - elif line.startswith('*'): - break + "You have not updated the CHANGELOG file. " + f"Please add a summary of your additions to {str(changelog)!r} " + f"as described in {str(contributing)!r}." + ) + elif line.startswith("*"): + print("Changelog updated.") + exit(0) diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst index 4a77fdc..8d89f0e 100644 --- a/docs/CHANGELOG.rst +++ b/docs/CHANGELOG.rst @@ -2,6 +2,7 @@ Changelog ========= +* Change handling of CHANGELOG checks v0.1.30 (2024-04-03) ------------------------------------------ diff --git a/tox.ini b/tox.ini index dcc94bc..01e7e52 100644 --- a/tox.ini +++ b/tox.ini @@ -71,7 +71,6 @@ skip_install = true commands_pre = python {toxinidir}/devtools/clean_dist_check.py commands = python --version - python {toxinidir}/devtools/check_changelog.py python -m build twine check dist/*.whl twine check dist/*.tar.gz @@ -95,8 +94,10 @@ commands = usedevelop = true deps = -r{toxinidir}/devtools/docs_requirements.txt + gitpython commands = sphinx-build {posargs:-E} -b html docs/rst dist/docs + python {toxinidir}/devtools/check_changelog.py [testenv:safety] deps = safety