Skip to content

fix(build): pick PEP 440-compatible nbgv field, avoid trailing .height#454

Merged
heyitsaamir merged 3 commits into
mainfrom
aamirj/fix-version-field-priority
Jun 8, 2026
Merged

fix(build): pick PEP 440-compatible nbgv field, avoid trailing .height#454
heyitsaamir merged 3 commits into
mainfrom
aamirj/fix-version-field-priority

Conversation

@heyitsaamir

Copy link
Copy Markdown
Collaborator

Summary

Fix the hatch build plugin so released package versions don't have a trailing .height component (we just shipped 2.0.13.4 when we meant 2.0.13).

Why

I introduced this in PR #445 when migrating off the 3.12-only nbgv-python wrapper. The plugin picked nbgv's CloudBuildNumber field, which works fine on main (2.0.13-dev.11+eaec265930) but on release it expands to 2.0.13.4 because nbgv appends git height as a 4th version component when version.json has a plain three-part version. PyPI then got microsoft-teams-apps==2.0.13.4 instead of 2.0.13.

What changed

Field priority is now SemVer2CloudBuildNumberSimpleVersion, with a PEP 440 validity check that walks past unparseable fields. End result:

  • release: SemVer2 is 2.0.13 (plain stable) — picked
  • main: SemVer2 is 2.0.13-dev.11.geaec265930 (not PEP 440 due to trailing .gHASH) — falls through to CloudBuildNumber 2.0.13-dev.11+eaec265930 (PEP 440-valid via local-version +)

Reviewer tips

Diff is small — just the field list + a try/except in _select_version. The comment block explains the rationale so future folks don't reintroduce the bug.

Testing

Verified both code paths locally:

# main
$ NBGV_REQUIRED=1 uv build --package microsoft-teams-apps --sdist
Successfully built dist/microsoft_teams_apps-2.0.13.dev11+eaec265930.tar.gz

# release (simulated by checking the field selection logic against
# nbgv output captured from the release branch)
SemVer2=2.0.13 -> picked, parses as PEP 440 2.0.13

Will be visible end-to-end on the next release (2.0.14).

Released version was `2.0.13.4` instead of `2.0.13` because the hatch
plugin preferred nbgv's CloudBuildNumber field. On release branches with
a plain three-part version, nbgv appends git height as a 4th component
(`2.0.13.4`).

Switch the field priority to SemVer2 -> CloudBuildNumber -> SimpleVersion,
and walk past any field that isn't PEP 440-parseable. End result:
- release: SemVer2 picks `2.0.13`
- main:    SemVer2 has +gHASH (not PEP 440) so falls through to
           CloudBuildNumber `2.0.13-dev.11+eaec265930` (PEP 440-valid)
Copilot AI review requested due to automatic review settings June 8, 2026 22:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts the Teams Hatch build plugin’s version selection logic so that release builds prefer an nbgv field that yields a PEP 440-compatible stable version (avoiding an unintended 4th “git height” component like 2.0.13.4 when 2.0.13 is intended).

Changes:

  • Reorders nbgv field selection priority to prefer SemVer2, then CloudBuildNumber, then SimpleVersion.
  • Adds a PEP 440 parse check to skip unparseable nbgv fields instead of blindly selecting the first populated one.
  • Improves the failure message when no usable PEP 440 version is available in expected fields.

Comment thread tools/hatch-teams-build/src/hatch_teams_build/version_source.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread tools/hatch-teams-build/src/hatch_teams_build/version_source.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@heyitsaamir heyitsaamir merged commit a7553f9 into main Jun 8, 2026
4 checks passed
@heyitsaamir heyitsaamir deleted the aamirj/fix-version-field-priority branch June 8, 2026 23:15
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