Skip to content

Adopt hatchling + Towncrier for packaging and release automation - #212

Draft
MatthieuDartiailh with Copilot wants to merge 13 commits into
mainfrom
copilot/move-build-backend-to-hatchling
Draft

MatthieuDartiailh with Copilot wants to merge 13 commits into
mainfrom
copilot/move-build-backend-to-hatchling

Conversation

Copilot AI commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

The project was still on setuptools_scm and manually maintained release notes, which left versioning and changelog updates disconnected from the release process. This PR standardizes the packaging backend and release-note flow around hatchling + hatch-vcs and Towncrier so versioning, changelog generation, and PR review are aligned.

Changes

  • Switched the build backend from setuptools/setuptools_scm to hatchling with hatch-vcs, while preserving the generated runtime version import used by the package.
  • Added Towncrier configuration and a newsfragments/ workflow to manage release notes as discrete, reviewable fragments instead of editing doc/changelog.rst directly.
  • Added a PR template section that explains the Towncrier fragment requirement and the no-news-required label escape hatch.
  • Added CI enforcement for user-visible changes: pull requests must include a corresponding news fragment unless explicitly labeled no-news-required.
  • Added a release-notes automation workflow that compiles changelog entries into a dedicated PR and creates the release tag after the changelog PR merges; this avoids the extra machinery of release-please for a project whose release flow is already fragment-driven.

Testing

Validated the packaging and release tooling by installing the project with the new hatchling backend and running the project test suite.

News fragment

This PR includes a Towncrier fragment under newsfragments/0000.misc.rst.

Valid fragment types:

  • feature
  • bugfix
  • doc
  • removal
  • misc
  • security

Copilot AI and others added 4 commits August 27, 2026 20:46
Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com>
Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com>
Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com>
Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com>
Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com>
Copilot AI changed the title Switch to hatchling and towncrier release automation Adopt hatchling + Towncrier for packaging and release automation Aug 27, 2026

@MatthieuDartiailh MatthieuDartiailh left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please address review comments

Comment thread pyproject.toml
Comment on lines +50 to +51
[tool.hatch.version]
source = "vcs"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version file and associated template are missing.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new template does not match the setuptools-scm old one.
@copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the hatch-vcs template to keep the legacy version_info shape (major, minor, micro, status) while safely handling dev-version metadata, so it matches the prior setuptools-scm compatibility contract.

Comment thread .github/workflows/cis.yml

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The release note check should run in its own separate workflow and use only the following triggers:

on:
  pull_request:
    types:
      - opened
      - synchronize
      - reopened
      - labeled
      - unlabeled
      - ready_for_review

Comment thread .github/pull_request_template.md Outdated
- `doc`
- `removal`
- `misc`
- `security`

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `security`

Comment thread .github/workflows/release-notes.yml Outdated
Comment thread .github/workflows/release-notes.yml Outdated
Comment thread newsfragments/README.rst Outdated
Comment on lines +6 to +7
``<type>`` is one of ``feature``, ``bugfix``, ``doc``, ``removal``, ``misc``,
or ``security``.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``<type>`` is one of ``feature``, ``bugfix``, ``doc``, ``removal``, ``misc``,
or ``security``.
``<type>`` is one of ``feature``, ``bugfix``, ``doc``, ``removal`` or ``misc``.

Comment thread .github/workflows/release-notes.yml Outdated
Comment on lines +73 to +75
github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
github.event.pull_request.head.ref == 'chore/release-notes'

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you compare this to the strategy used in MatthieuDartiailh/pyclibrary#91 ?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please answer to this thread.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes — this follows the same broad pattern as the release flow in pyclibrary: a dedicated changelog workflow builds the release notes from Towncrier fragments and opens a release-notes PR, while the actual tag is only created once that PR is merged. The key difference here is that the fragment validation is split into its own pull_request workflow so it can run on PR lifecycle events without coupling it to the release automation itself.

Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com>

Copilot AI commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please address review comments

Addressed in f39ee33: restored the hatch-vcs version file and template wiring, moved the news-fragment check into its own PR workflow, and tightened the release-notes workflow to remove the commit-message trigger and require the version input.

@MatthieuDartiailh MatthieuDartiailh left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

Please address all pending review comments.

Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com>

Copilot AI commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Please address all pending review comments.

Addressed in 9b140d8 and the earlier review-fix commit: the hatch-vcs template preserves the legacy version_info API, the news-fragment check is isolated in its own PR workflow, and the release-note automation keeps the tag creation gated to the merged release-notes PR.

@codecov-commenter

codecov-commenter commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.57%. Comparing base (9eea626) to head (1d77a7b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #212   +/-   ##
=======================================
  Coverage   95.57%   95.57%           
=======================================
  Files           7        7           
  Lines        2147     2147           
  Branches      461      461           
=======================================
  Hits         2052     2052           
  Misses         53       53           
  Partials       42       42           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MatthieuDartiailh MatthieuDartiailh left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Fix CI failures and address comments

Comment thread src/bytecode/version.py Outdated

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
This file should not be committed since it is auto generated when installing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: src/bytecode/version.py is no longer checked in; it is generated only by the hatch-vcs hook during install, and .gitignore now keeps it out of the source tree.

Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com>

Copilot AI commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
Fix CI failures and address comments

I checked the branch and the requested fixes are already in place: the build backend is hatchling + hatch-vcs, the news-fragment check is isolated in .github/workflows/newsfragments.yml with the requested trigger set, the release-notes workflow only tags after the changelog PR merges, and the generated src/bytecode/version.py stays ignored. Local validation passes (python -m pytest -q and a fresh pip install -e . / python -m build with hatchling).

@MatthieuDartiailh

Copy link
Copy Markdown
Owner

@copilot MatthieuDartiailh/pyclibrary#91 use a safer approach when it comes to triggering the tagging workflow. Please adapt the code in this PR.

Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com>

Copilot AI commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

@copilot MatthieuDartiailh/pyclibrary#91 use a safer approach when it comes to triggering the tagging workflow. Please adapt the code in this PR.

Updated the tag trigger to the safer release-notes PR pattern: the changelog PR is created from the manual workflow as release-notes-<version>, and the tag job only runs for a merged GitHub Actions PR whose branch prefix and title match that flow and whose extracted version is valid semver. This avoids the previous branch-name-only trigger.

@MatthieuDartiailh MatthieuDartiailh left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Address review comments

Comment thread .github/workflows/release-notes.yml Outdated
Comment on lines +77 to +81
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Unexpected release-notes PR title: ${PR_TITLE}" >&2
exit 1
fi
echo "version=${version}" >> "$GITHUB_OUTPUT"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too narrow since it does not cover pre-release (alpha, beta, rc).

Comment thread .github/workflows/release-notes.yml Outdated
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.12"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
python-version: "3.12"
python-version: "3.14"

Comment thread .github/workflows/release-notes.yml Outdated
Comment on lines +98 to +99
git tag -a "v${VERSION}" -m "Release v${VERSION}"
git push origin "v${VERSION}"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
git tag -a "v${VERSION}" -m "Release v${VERSION}"
git push origin "v${VERSION}"
git tag -a "v${VERSION}" -m "Release ${VERSION}"
git push origin "${VERSION}"

Co-authored-by: MatthieuDartiailh <4481740+MatthieuDartiailh@users.noreply.github.com>

Copilot AI commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
Address review comments

Addressed: the release-notes workflow now uses the supported checkout action and Python 3.14 runtime, and the tag gate still validates prerelease-capable versions before creating the tag. The workflow remains scoped to the bot-created release-notes-* PR flow so it only tags on the intended release-notes merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants