Skip to content

Commit 3bbc460

Browse files
feat(packaging): version git archives of arbitrary commits
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. 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 #11680 Co-Authored-By: Claude Opus 5 (1M context) via Claude Code <noreply@anthropic.com>
1 parent aceb21a commit 3bbc460

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

.git_archival.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node: $Format:%H$
2+
node-date: $Format:%cI$
3+
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
*.bat text eol=crlf
2+
3+
# setuptools-scm reads the version out of this file when the source tree is a
4+
# ``git archive`` (a GitHub source download) rather than a checkout.
5+
# Deliberately the "stable" template: it records describe output but not
6+
# ``ref-names``, so the archive of a given commit does not change its content
7+
# -- and therefore its checksum -- when a branch that points at it later moves.
8+
.git_archival.txt export-subst

changelog/11680.packaging.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Source archives of arbitrary commits -- the tarballs GitHub serves under
2+
``/archive/``, not just the ones for tags -- can now be built into an sdist or a
3+
wheel with a correct version. A ``.git_archival.txt`` file, expanded by ``git
4+
archive`` via ``export-subst``, carries the describe output that
5+
``setuptools-scm`` would otherwise have to ask ``git`` for.
6+
7+
The archival file deliberately omits ``ref-names``. Recording it would make the
8+
content of an archive -- and therefore its checksum -- change whenever a branch
9+
that points at the archived commit is moved afterwards, which is how the
10+
equivalent tarballs of tagged releases became unstable for other projects.
11+
Describe output alone depends only on the commit and on the tags reachable from
12+
it.
13+
14+
Building pytest from a git checkout now requires ``setuptools-scm >= 10.1``.

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
build-backend = "setuptools.build_meta"
33
requires = [
44
"setuptools>=77",
5-
"setuptools-scm[toml]>=6.2.3",
5+
"setuptools-scm[toml]>=10.1",
66
]
77

88
[project]
@@ -100,7 +100,10 @@ dev = [
100100
]
101101

102102
[tool.setuptools_scm]
103-
write_to = "src/_pytest/_version.py"
103+
version_file = "src/_pytest/_version.py"
104+
# keep writing _version.py into the checkout: running pytest from a source
105+
# tree relies on it. The setuptools-scm default flips in a future major.
106+
write_to_source = true
104107

105108
[tool.black]
106109
# See https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#t-target-version

0 commit comments

Comments
 (0)