Skip to content

Commit

Permalink
More linting, replace itertools.batched with itertoolz.partition
Browse files Browse the repository at this point in the history
itertools.batched is from Python 3.12. Not a complete dealbreaker, but
makes life simpler as developers are likely running the script from a
Euphonic dev environment which is 3.10 with toolz available.
  • Loading branch information
ajjackson committed Feb 9, 2025
1 parent 6409b37 commit 139e693
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/set_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: python -m pip install toolz packaging

- name: Validate and normalise version number
shell: python
run : |
Expand Down
17 changes: 12 additions & 5 deletions build_utils/bump_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"""
from argparse import ArgumentParser
from dataclasses import dataclass
from itertools import batched
from pathlib import Path
import re

from toolz.itertoolz import partition

REPOSITORY_ADDRESS = "https://github.com/pace-neutrons/Euphonic"

Expand All @@ -33,13 +33,14 @@ def parse_changelog(changelog_file: Path) -> list[Block]:
except for 'Unreleased' which compares with HEAD
"""

with open(changelog_file) as fd:
with open(changelog_file, "rt", encoding="utf8") as fd:
split_text = re.split(r"`(\S+) <\S+/compare/(\S+)\.\.\.\S+>`_\n-+", fd.read())

# First item is always empty?
split_text = split_text[1:]

blocks = [Block(*block_data) for block_data in batched(split_text, n=3)]
# From Python 3.12 can replace partition with itertools.batched
blocks = [Block(*block_data) for block_data in partition(3, split_text)]

for block in blocks:
block.content = block.content.strip()
Expand Down Expand Up @@ -83,6 +84,7 @@ def to_text(blocks: list[Block]) -> str:


def get_parser() -> ArgumentParser:
"""Use argparse to get user input"""
parser = ArgumentParser()
parser.add_argument("filename", type=Path, help="Input CHANGELOG.rst file")
parser.add_argument("tag", type=str, help="Tag for new/updated version")
Expand All @@ -91,15 +93,20 @@ def get_parser() -> ArgumentParser:
return parser


if __name__ == "__main__":
def main() -> None:
"""Entrypoint"""
args = get_parser().parse_args()

blocks = parse_changelog(args.filename)
bump_version(blocks, args.tag)

if args.replace:
with open(args.filename, "w") as fd:
with open(args.filename, "w", encoding="utf8") as fd:
print(to_text(blocks), file=fd)

else:
print(to_text(blocks))


if __name__ == "__main__":
main()

0 comments on commit 139e693

Please sign in to comment.