Skip to content

Commit

Permalink
Fix changelog check
Browse files Browse the repository at this point in the history
  • Loading branch information
hejamu committed Apr 3, 2024
1 parent 561b998 commit a656518
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
32 changes: 21 additions & 11 deletions devtools/check_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
1 change: 1 addition & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Changelog
=========

* Change handling of CHANGELOG checks

v0.1.30 (2024-04-03)
------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a656518

Please sign in to comment.