Skip to content

Commit 2a8412b

Browse files
authored
feat: add a Makefile goal simple-index that generates a PEP-503 compatible Simple Index directory inside the dist (#947)
1 parent 57cce09 commit 2a8412b

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-docs-md.zip: docs-md
197197
dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-build-epoch.txt:
198198
echo $(SOURCE_DATE_EPOCH) > dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-build-epoch.txt
199199

200+
# Build a PEP-503 compatible Simple Repository directory inside of dist/. For details on
201+
# the layout of that directory and the normalized project name, see: https://peps.python.org/pep-0503/
202+
# The directory can then be used to install (hashed) artifacts by using `pip` and
203+
# its `--extra-index-url` argument: https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-extra-index-url
204+
PROJECT_NAME := $(shell python -c $$'import re; print(re.sub(r"[-_.]+", "-", "$(PACKAGE_NAME)").lower());')
205+
.PHONY: simple-index
206+
simple-index: dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-none-any.whl dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz
207+
mkdir -p dist/simple-index/$(PROJECT_NAME)
208+
echo -e "<!-- https://peps.python.org/pep-0503/ -->\n<!DOCTYPE html><html lang='en'><head><meta name='pypi:repository-version' content='1.3'><title>Simple Index</title></head><body><a href='/$(PACKAGE_NAME)/'>$(PACKAGE_NAME)</a></body></html>" > dist/simple-index/index.html
209+
echo -e "<!-- https://peps.python.org/pep-0503/ -->\n<!DOCTYPE html><html lang='en'><head><meta name='pypi:repository-version' content='1.3'><title>Simple Index: $(PROJECT_NAME)</title></head><body><a href='$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-none-any.whl#sha256="$$(python -c "with open('dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-none-any.whl', 'rb') as f: import hashlib; print(hashlib.sha256(f.read()).hexdigest());")"'>$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-none-any.whl</a><a href='$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz#sha256="$$(python -c "with open('dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz', 'rb') as f: import hashlib; print(hashlib.sha256(f.read()).hexdigest());")"'>$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz</a></body></html>" > dist/simple-index/$(PROJECT_NAME)/index.html
210+
cp -f dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-none-any.whl dist/simple-index/$(PROJECT_NAME)/
211+
cp -f dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz dist/simple-index/$(PROJECT_NAME)/
212+
200213
# Build the HTML and Markdown documentation from the package's source.
201214
DOCS_SOURCE := $(shell git ls-files docs/source)
202215
.PHONY: docs docs-html docs-md

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ This repository is intended to be a base template, a cookiecutter for a new Pyth
2121
[Testing](#testing)
2222
[Generating documentation](#generating-documentation)
2323
[Synchronizing with this template repo](#synchronizing-with-this-template-repo)
24-
[Versioning, publishing and changelog](#versioning-publishing-and-changelog)
24+
[Versioning, publishing and distributions](#versioning-publishing-and-distributions)
2525
&emsp;[Building from a source distribution package](#building-from-a-source-distribution-package)
26+
&emsp;[Using the Simple Index](#using-the-simple-index)
2627
[Build integrity using SLSA framework](#build-integrity-using-slsa-framework)
2728
[Cleaning up](#cleaning-up)
2829
[Frequently asked questions](#frequently-asked-questions)
@@ -255,7 +256,7 @@ In addition to the default HTML, Sphinx also generates Markdown documentation co
255256

256257
The [sync-with-upstream.yaml](https://github.com/jenstroeger/python-package-template/blob/main/.github/workflows/sync-with-upstream.yaml) GitHub Acions workflow checks this template repo daily and automatically creates a pull request in the downstream repo if there is a new release. Make sure to set up the GitHub username and email address in this workflow accordingly.
257258

258-
## Versioning, publishing and changelog
259+
## Versioning, publishing and distributions
259260

260261
To enable automation for [semantic versioning](https://semver.org/), package publishing, and changelog generation it is important to use meaningful [conventional commit messages](https://www.conventionalcommits.org/)! This package template already has a built-in semantic release support enabled which is set up to take care of all three of these aspects — every time changes are pushed to the `release` branch.
261262

@@ -299,6 +300,16 @@ SKIP=check-hooks-apply,check-useless-excludes,actionlint make dist
299300

300301
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!
301302

303+
## Using the Simple Index
304+
305+
Once source and/or binary distribution packages have been built, they can be served using a [PEP 503](https://peps.python.org/pep-0503/) compatible package repository. Simply call
306+
307+
```bash
308+
make simple-index
309+
```
310+
311+
to create the package repository in the `dist/` folder, and then use it e.g. with [pip](https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-extra-index-url) and its `--extra-index-url` parameter.
312+
302313
## Build integrity using SLSA framework
303314

304315
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:

0 commit comments

Comments
 (0)