Skip to content

build: setuptools + setup.py for vcs-versioning and setuptools-scm (#1302)#1325

Merged
RonnyPfannschmidt merged 4 commits intopypa:mainfrom
RonnyPfannschmidt:issue-1302-setuptools-build-bootstrap
Mar 27, 2026
Merged

build: setuptools + setup.py for vcs-versioning and setuptools-scm (#1302)#1325
RonnyPfannschmidt merged 4 commits intopypa:mainfrom
RonnyPfannschmidt:issue-1302-setuptools-build-bootstrap

Conversation

@RonnyPfannschmidt
Copy link
Copy Markdown
Contributor

Summary

Addresses the distribution bootstrap cycle described in #1302: vcs-versioning was built with hatchling, while hatchling → pluggy → setuptools-scm → vcs-versioning made clean bootstrapping impossible for some packagers.

Changes

  • vcs-versioning: build with setuptools.build_meta instead of hatchling; supply the dynamic version from setup.py (logic inlined, if __name__ == "__main__").
  • setuptools-scm: use standard setuptools.build_meta (drop the custom build_meta wrapper / backend-path); version from setup.py the same way.
  • Tooling: exclude both package setup.py files from mypy / the mypy pre-commit hook (duplicate module name setup; runtime sys.path hacks are not modeled).
  • Changelog: vcs-versioning/changelog.d/1302.misc.md (towncrier).

Notes

  • Plan to revisit hatchling for vcs-versioning once the pluggy/setuptools-scm edge of the graph no longer applies (see issue discussion).

Build vcs-versioning with setuptools instead of hatchling to avoid the
bootstrap cycle (hatchling → pluggy → setuptools-scm → vcs-versioning)
reported in pypa#1302.

Use setuptools.build_meta for setuptools-scm and drop the custom
build_meta wrapper; supply dynamic versions from each package setup.py
with logic inlined and guarded by if __name__ == "__main__".

Exclude package setup.py from mypy (duplicate module name) and from the
mypy pre-commit hook.

Co-authored-by: Cursor AI <ai@cursor.sh>
Co-authored-by: Composer <composer@cursor.com>
Copilot AI review requested due to automatic review settings March 27, 2026 12:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 changes both subprojects’ build backends to setuptools.build_meta and moves self-version computation into setup.py to break the downstream bootstrap cycle (hatchling → pluggy → setuptools-scm → vcs-versioning).

Changes:

  • Switch vcs-versioning from hatchling to setuptools.build_meta, with dynamic version computed by vcs-versioning/setup.py.
  • Switch setuptools-scm to standard setuptools.build_meta, dropping the custom _own_version_helper build backend and adding setuptools-scm/setup.py for dynamic versioning.
  • Adjust repo tooling (mypy/ruff/pre-commit) and add a towncrier changelog fragment.

Reviewed changes

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

Show a summary per file
File Description
vcs-versioning/setup.py New setuptools entry point that computes the package version at build time.
vcs-versioning/pyproject.toml Switch build backend to setuptools and configure setuptools package discovery.
vcs-versioning/changelog.d/1302.misc.md Towncrier fragment documenting the bootstrap-cycle fix.
setuptools-scm/setup.py New setuptools entry point that computes the package version at build time.
setuptools-scm/pyproject.toml Switch to setuptools.build_meta, remove backend-path and dynamic-version attr indirection.
setuptools-scm/_own_version_helper.py Removes the previous custom version/build helper module.
pyproject.toml Tooling adjustments (mypy/ruff) for new setup.py scripts.
.pre-commit-config.yaml Exclude setup.py scripts from the mypy pre-commit hook.
Comments suppressed due to low confidence (2)

vcs-versioning/setup.py:67

  • In this setup.py, _repo_root = _root.parent points outside an extracted sdist (where setup.py sits at the sdist root). That can cause version inference to skip PKG-INFO (because your custom _parse runs against config.absolute_root) and fall through to fallback_version, producing an incorrect version when building from an sdist. Use the project directory as root (e.g., _root) and rely on search_parent_directories=True (or equivalent) to find the VCS root when building from a monorepo checkout, so sdist builds still see PKG-INFO/fallbacks under the sdist root.
    vcs-versioning/setup.py:75
  • fallback_version here ("0.1.1+pre.tag") is inconsistent with the configured fallback in vcs-versioning/pyproject.toml ([tool.vcs-versioning].fallback_version = "0.1.0"). This can lead to different versions depending on which code path is used (e.g., building from sdist vs. calling the library). Consider sourcing the fallback version from the same configuration or making them match to avoid surprising version outputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread setuptools-scm/setup.py
Comment on lines +25 to +30
return get_version(
root=_root.parent,
version_scheme="guess-next-dev",
local_scheme=local_scheme,
tag_regex=r"^setuptools-scm-(?P<version>v?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$",
scm={"git": {"describe_command": make_describe_command("setuptools-scm-*")}},
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

root=_root.parent will resolve to the directory above an extracted sdist (since setup.py is at the sdist root), which can break SCM discovery and makes error messages/root paths misleading during sdist wheel builds. Prefer root=_root (the project root) and enable parent-directory discovery (search_parent_directories=True) so monorepo checkouts still find the repo root while sdists stay self-contained.

Copilot uses AI. Check for mistakes.
RonnyPfannschmidt and others added 2 commits March 27, 2026 13:38
Pass relative_to and fallback_root so SCM fallbacks do not resolve
against the process cwd (e.g. workspace root in CI).

Co-authored-by: Cursor AI <ai@cursor.sh>
Co-authored-by: Composer <composer@cursor.com>
Use root=".." and fallback_root="." (anchored with relative_to
pyproject.toml) for SCM vs sdist metadata. Add resolved_fallback_root()
so setuptools_scm.parse_scm_fallback finds PKG-INFO under the package
tree; vcs-versioning setup.py routes parse_pkginfo through the same path.

Co-authored-by: Cursor AI <ai@cursor.sh>
Co-authored-by: Composer <composer@cursor.sh>
Include vcs_versioning._cli git archival templates and setuptools_scm
.git_archival.txt in wheels via tool.setuptools.package-data.

Co-authored-by: Cursor AI <ai@cursor.sh>
Co-authored-by: Composer <composer@cursor.sh>
@RonnyPfannschmidt RonnyPfannschmidt merged commit 59275f7 into pypa:main Mar 27, 2026
27 checks passed
LalatenduMohanty added a commit to LalatenduMohanty/fromager that referenced this pull request Mar 27, 2026
The circular build dependency (setuptools-scm → vcs-versioning →
hatchling → pluggy → setuptools-scm) has been fixed upstream.
vcs-versioning 1.1.0 switched its build backend from hatchling to
setuptools, breaking the cycle.

See: pypa/setuptools-scm#1325

Reverts: python-wheel-build#983
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Lalatendu Mohanty <lmohanty@redhat.com>
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.

2 participants