Skip to content

Commit 607994d

Browse files
authored
fix: the generated sdist file should contain everything needed to check and test the code, and to build the documentation as well (#967)
1 parent 0538443 commit 607994d

4 files changed

Lines changed: 27 additions & 11 deletions

File tree

.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: 23 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)
@@ -268,7 +269,7 @@ In order to build a distribution of your package locally instead of publishing i
268269
make dist
269270
```
270271

271-
This builds a source package and a binary distribution, and stores the files in your local `dist/` folder.
272+
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.
272273

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

@@ -277,6 +278,27 @@ cz changelog
277278
cz bump
278279
```
279280

281+
## Building from a source distribution package
282+
283+
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.
284+
285+
To build from a source distribution package, simply follow these steps:
286+
287+
```bash
288+
tar zxvf package.tar.gz # Unpack the sdist tar file.
289+
cd package/
290+
git init # We need this to be a Git repository to run checks.
291+
git add . # Add all files so tools find them via the VCS.
292+
```
293+
294+
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:
295+
296+
```bash
297+
SKIP=check-hooks-apply,check-useless-excludes,actionlint make dist
298+
```
299+
300+
Note that we skip Git hooks that are unnecessary when building from the source distribution. As above, this builds the source package and a binary distribution, and stores both in the `dist/` folder. And, 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!
301+
280302
## Build integrity using SLSA framework
281303

282304
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: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,16 @@ omit = [
121121
]
122122

123123

124-
# https://flit.pypa.io/en/latest/pyproject_toml.html#sdist-section
124+
# https://flit.pypa.io/en/stable/pyproject_toml.html#sdist-section
125125
# See also: https://github.com/pypa/flit/issues/565
126+
# See also: https://github.com/pypa/flit/discussions/745
126127
[tool.flit.sdist]
127128
include = []
128129
exclude = [
129130
".github/",
130131
".vscode/",
131-
"docs/",
132-
"tests/",
133-
".flake8",
134132
".gitattributes",
135-
".gitignore",
136-
".pre-commit-config.yaml",
137-
"CHANGELOG.md",
138133
"CODEOWNERS",
139-
"Makefile",
140-
"SECURITY.md",
141134
]
142135

143136

0 commit comments

Comments
 (0)