Skip to content

Commit 64be104

Browse files
committed
chore: make sdist round-trip reproducible wheels
1 parent 3c3c7db commit 64be104

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ share/python-wheels/
2727
.installed.cfg
2828
*.egg
2929
MANIFEST
30+
PKG-INFO
3031

3132
# Local venv
3233
bin/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ dist: dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-none-any.whl dist/$(PACKAGE_NA
186186
dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-none-any.whl: check test-all dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-build-epoch.txt
187187
SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) python -m flit build --setup-py --format wheel
188188
dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz: check test-all dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-build-epoch.txt
189-
SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) python -m flit build --setup-py --format sdist
189+
SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) python -m flit build --no-setup-py --format sdist
190190
dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-docs-html.zip: docs-html
191191
python -m zipfile -c dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-docs-html.zip docs/_build/html/
192192
dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-docs-md.zip: docs-md

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This repository is intended to be a base template, a cookiecutter for a new Pyth
2222
[Generating documentation](#generating-documentation)
2323
[Synchronizing with this template repo](#synchronizing-with-this-template-repo)
2424
[Versioning, publishing and changelog](#versioning-publishing-and-changelog)
25+
 [Building from a source distribution package](#building-from-a-source-distribution-package)
2526
[Build integrity using SLSA framework](#build-integrity-using-slsa-framework)
2627
[Cleaning up](#cleaning-up)
2728
[Frequently asked questions](#frequently-asked-questions)
@@ -266,7 +267,7 @@ In order to build a distribution of your package locally instead of publishing i
266267
make dist
267268
```
268269

269-
This builds a source package and a binary distribution, and stores the files in your local `dist/` folder.
270+
This builds a source package ([sdist](https://packaging.python.org/en/latest/discussions/package-formats/#what-is-a-source-distribution)) and a binary distribution ([wheel](https://packaging.python.org/en/latest/discussions/package-formats/#what-is-a-wheel)), and stores the files in your local `dist/` folder.
270271

271272
You can also generate a changelog and bump the version manually and locally using commitizen (already installed as a dev dependency), for example:
272273

@@ -275,6 +276,26 @@ cz changelog
275276
cz bump
276277
```
277278

279+
## Building from a source distribution package
280+
281+
The source distribution package ([sdist](https://packaging.python.org/en/latest/discussions/package-formats/#what-is-a-source-distribution)) contains everything needed in order to check, test, and build a binary distribution ([wheel](https://packaging.python.org/en/latest/discussions/package-formats/#what-is-a-wheel)) and its documentation; that is particulalry useful for third-party packaging services that build their own software distribution packages using custom processes.
282+
283+
To build a everything from a source distribution package, simply follow these steps:
284+
285+
```bash
286+
tar zxvf package.tar.gz # Unpack the tar file.
287+
cd package/
288+
git init # We need this to be a Git repository to run checks.
289+
```
290+
291+
We do need to initialize the package folder as a Git repository to ensure the Makefile is able to call various checkers via hooks. Once done, we can use `make` as before:
292+
293+
```bash
294+
SKIP=check-hooks-apply,check-useless-excludes,actionlint make dist
295+
```
296+
297+
Note that we skip Git hooks that are unnecessary when building from the source distribution. As above, this builds both the source package and a binary distribution, and stores them in the `dist/` folder. In addition, as expected, setting the `SOURCE_DATE_EPOCH` environment variable to the build epoch value of the original sdist and wheel build results in the bit-exact same binary distribution package!
298+
278299
## Build integrity using SLSA framework
279300

280301
The build process in this repository follows the requirements in the [SLSA framework](https://slsa.dev/) to be compliant at level 3. An important aspect of SLSA to improve the supply chain security posture is to generate a verifiable provenance for the build pipeline. Such a provenance can be used to verify the builder and let the consumers check the materials and configurations used while building an artifact. In this repository we use the [generic provenance generator reusable workflow](https://github.com/slsa-framework/slsa-github-generator) to generate a provenance that can attest to the following artifacts in every release:

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ exclude = [
130130
".github/",
131131
".vscode/",
132132
".gitattributes",
133-
".gitignore",
134133
"CHANGELOG.md",
135134
"CODEOWNERS",
136135
"SECURITY.md",

0 commit comments

Comments
 (0)