feat(packaging): version git archives of arbitrary commits - #15023
Merged
RonnyPfannschmidt merged 1 commit intoSep 14, 2026
Merged
Conversation
GitHub serves a source tarball for every commit, not only for tags, but so far only a tag's tarball could be built: without a .git directory setuptools-scm had nothing to read the version from. A .git_archival.txt expanded by ``git archive`` via ``export-subst`` gives it one. The stable template is deliberate -- recording ``ref-names`` as well would tie an archive's content, and so its checksum, to whichever branches happen to point at the commit, so moving a branch afterwards would silently change the download. The file is excluded from the sdist. It only ever carries a version once ``git archive`` has expanded it, and an sdist states its version in its metadata anyway; shipping the bare template would leave a stray ``$Format:...$`` for setuptools-scm to consider on every build from an unpacked sdist. While here, move off the deprecated ``write_to`` and state the ``write_to_source`` behaviour that setuptools-scm is about to flip rather than inherit the change silently. Closes pytest-dev#11680 Co-Authored-By: Claude Opus 5 (1M context) via Claude Code <noreply@anthropic.com>
RonnyPfannschmidt
force-pushed
the
packaging/git-archival
branch
from
September 14, 2026 10:29
3bbc460 to
6062aca
Compare
nicoddemus
approved these changes
Sep 14, 2026
Backport to 9.1.x: 💚 backport PR created✅ Backport PR branch: Backported as #15025 🤖 @patchback |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11680.
GitHub serves a source tarball for every commit, not only for tags, but so far only a tag's tarball could be built — without a
.gitdirectorysetuptools-scmhad nothing to read a version from.This adds a
.git_archival.txtexpanded bygit archiveviaexport-subst.It uses the stable template —
node,node-date,describe-name, deliberately noref-names. Recordingref-nameswould tie an archive's content, and so its checksum, to whichever branches happen to point at the commit, so moving a branch afterwards would silently change an already-published download. That instability is why this was declined in 2023; the stable template did not exist yet. Describe output depends only on the commit and the tags reachable from it, so a branch moving cannot change it. Adding or moving a tag in the commit's ancestry still can.A
MANIFEST.inkeeps the file out of the sdist. It only carries a version oncegit archivehas expanded it, and an sdist states its version in its metadata anyway; shipping the bare template would leave a stray$Format:...$forsetuptools-scmto consider on every build from an unpacked sdist. Verified that the exclusion drops exactly that one file and nothing else.While here: off the deprecated
write_toontoversion_file, andwrite_to_source = truestated explicitly —setuptools-scmis about to flip that default, andsrc/_pytest/_version.pyshould keep being written into checkouts. That option is what sets the newsetuptools-scm>=10.1floor; it can go back to>=8if the floor is unwelcome, at the cost of a deprecation warning now and a silent behaviour change later.Releases are unaffected —
deploy.ymlsuppliesSETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYTEST.Verified
git archiveexpansiondescribe-namematchesgit describeexactly.git)MANIFEST.in.git_archival.txtalonesetuptools-scmwarningspre-commit run -a🤖 Generated with Claude Code