diff --git a/templates/github/.ci/scripts/collect_changes.py.j2 b/templates/github/.ci/scripts/collect_changes.py.j2 index b90ceedc..a759542e 100755 --- a/templates/github/.ci/scripts/collect_changes.py.j2 +++ b/templates/github/.ci/scripts/collect_changes.py.j2 @@ -6,7 +6,7 @@ import re import toml from git import GitCommandError, Repo -from pkg_resources import parse_version +from packaging.version import parse as parse_version # Read Towncrier settings tc_settings = toml.load("pyproject.toml")["tool"]["towncrier"] @@ -23,8 +23,12 @@ START_STRING = tc_settings.get( TITLE_FORMAT = tc_settings.get("title_format", "{name} {version} ({project_date})") +# Build a regex to find the header of a changelog section. +# It must have a single capture group to single out the version. +# see help(re.split) for more info. NAME_REGEX = r".*" -VERSION_REGEX = r"([0-9]+\.[0-9]+\.[0-9][0-9ab]*)" +VERSION_REGEX = r"[0-9]+\.[0-9]+\.[0-9][0-9ab]*" +VERSION_CAPTURE_REGEX = rf"({VERSION_REGEX})" DATE_REGEX = r"[0-9]{4}-[0-9]{2}-[0-9]{2}" TITLE_REGEX = ( "(" @@ -32,6 +36,7 @@ TITLE_REGEX = ( TITLE_FORMAT.format(name="NAME_REGEX", version="VERSION_REGEX", project_date="DATE_REGEX") ) .replace("NAME_REGEX", NAME_REGEX) + .replace("VERSION_REGEX", VERSION_CAPTURE_REGEX, 1) .replace("VERSION_REGEX", VERSION_REGEX) .replace("DATE_REGEX", DATE_REGEX) + ")" diff --git a/templates/github/.github/workflows/nightly.yml.j2 b/templates/github/.github/workflows/nightly.yml.j2 index 07711b3e..8a268f79 100644 --- a/templates/github/.github/workflows/nightly.yml.j2 +++ b/templates/github/.github/workflows/nightly.yml.j2 @@ -42,7 +42,7 @@ jobs: {{ setup_python(pyversion="3.11") | indent(6) }} - {{ install_python_deps(["gitpython", "toml"]) | indent(6) }} + {{ install_python_deps(["gitpython", "packaging", "toml"]) | indent(6) }} {{ configure_git() | indent(6) }}