Skip to content

Commit 3ef663d

Browse files
RonnyPfannschmidtpatchback[bot]
authored andcommitted
Merge pull request #15023 from RonnyPfannschmidt/packaging/git-archival
feat(packaging): version git archives of arbitrary commits (cherry picked from commit de30d84)
1 parent aef551a commit 3ef663d

5 files changed

Lines changed: 37 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

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Only meaningful inside a ``git archive``, where ``export-subst`` has filled it
2+
# in; an sdist carries its version in the metadata instead. Shipping the
3+
# unexpanded template would leave setuptools-scm a stray ``$Format:...$`` to
4+
# consider on every build from an unpacked sdist.
5+
exclude .git_archival.txt

changelog/11680.packaging.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
The archival file is not shipped in the sdist -- an sdist carries its version
15+
in its metadata, and the template is only ever expanded by ``git archive``.
16+
17+
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]
@@ -82,7 +82,10 @@ scripts.pytest = "_pytest.config:_console_main"
8282
]
8383

8484
[tool.setuptools_scm]
85-
write_to = "src/_pytest/_version.py"
85+
version_file = "src/_pytest/_version.py"
86+
# keep writing _version.py into the checkout: running pytest from a source
87+
# tree relies on it. The setuptools-scm default flips in a future major.
88+
write_to_source = true
8689

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

0 commit comments

Comments
 (0)