A generic PEP-517 build backend which allows additional processing to be applied to the resulting metadata, wheel and/or editable wheel.
Project description
multistage-build
A generic PEP-517 build backend which allows additional processing to be applied to the resulting metadata, wheel and/or editable wheel.
Motivating Example
Sometimes it is desirable to run a post-processing step on a built wheel. For example, we may wish to inject some additional metadata into the wheel. To do this, we should write a function which accepts the wheel path as its only argument, for example:
def my_wheel_post_processing_func(wheel_path):
print(f'The wheel to be processed is at {wheel_path}')
This function can then be declared as post-processing step of the PEP-517
build_wheel function:
[build-system]
requires = [
'multistage-build',
'setuptools',
]
build-backend = "multistage_build:backend"
[tool.multistage-build]
build-backend = "setuptools.build_meta"
post-build-wheel = [
{hook-function="my_mod:my_wheel_post_processing_func", hook-path="."},
]
[project]
name = "some-project"
version = "0.1.0"
...
We could also publish this functionality to the package repository, and consume it by declaring it as a build requirement:
[build-system]
requires = [
'multistage-build',
'my_mod',
'setuptools',
]
build-backend = "multistage_build:backend"
[tool.multistage-build]
build-backend = "setuptools.build_meta"
post-build-wheel = [
"my_mod:my_wheel_post_processing_func",
]
[project]
name = "some-project"
version = "0.1.0"
...
Plugin based hooks
For tools wishing to expose a standard behaviour, without requiring the user to declare each of the hooks manually, it is possible to declare potential hooks as entrypoints.
An example of a project which automatically registers build-time hooks using entry points:
[project.entry-points.multistage_build]
post-prepare-metadata-for-build-wheel = "my_mod:prepare_metadata_for_build_wheel_fn"
post-build-wheel = "my_mod:build_editable_fn"
post-build-editable = "my_mod:build_wheel_fn"
These hooks will get called for any user of the multistage_build backend, even if the project declaring these entrypoints doesn't itself use multistage-build. It allows one to build a library of hooks, and to have consumers add them by adding extra build dependencies (and declaring a multistage-build backend).
As is normal for entry-points, the name of the function is unimportant.
It is possible to declare multiple entry-points per hook.
A nice pattern would be to only run some behaviour if the hook is configured
in the pyproject.toml (which is in the CWD when the hook is running); though
this isn't obligatory (esp. when no configuration is needed - in that case,
the existence of the project in the build environment is enough of a signal for
the hook to be run).
Status of work
The current functionality includes:
- Hooks for build-sdist (
post-build-sdist``), build-wheel (post-build-wheel), and build-editable (post-build-editable), and prepare-metadata-for-build-wheel (post-prepare-metadata-for-build-wheel`) - Ability to have local definitions included, using the same mechanism as in-source builds from PEP-517.
There are a few known features not yet implemented:
- Hooks for sdist
- Hooks for all other PEP-517 and PEP-660 hooks
- Ability to override multiple hooks with a signle declaration (e.g. editable and build hooks). Perhaps allow entrypoint definitions so that you get it simply by having the dependency installed?
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file multistage_build-0.1.0.tar.gz.
File metadata
- Download URL: multistage_build-0.1.0.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0ad0b3bf4f56ce5b21f2935100b43cc5003af0108bad67739bc224e092085a6
|
|
| MD5 |
b2bfae70b1f1480646a1e10bf0fa85d1
|
|
| BLAKE2b-256 |
77745e5c3b0daf1093844732bb0b6c05509e7e0c73500660a239f833986b605c
|
Provenance
The following attestation bundles were made for multistage_build-0.1.0.tar.gz:
Publisher:
python-publish.yml on pelson/multistage-build
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
multistage_build-0.1.0.tar.gz -
Subject digest:
d0ad0b3bf4f56ce5b21f2935100b43cc5003af0108bad67739bc224e092085a6 - Sigstore transparency entry: 254336107
- Sigstore integration time:
-
Permalink:
pelson/multistage-build@1922e33e2644dcc9d83dfb859516de1dfe33d28e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/pelson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@1922e33e2644dcc9d83dfb859516de1dfe33d28e -
Trigger Event:
release
-
Statement type:
File details
Details for the file multistage_build-0.1.0-py3-none-any.whl.
File metadata
- Download URL: multistage_build-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e1e8780052c6ba27c1878fe47680dd98c276c2459f51321306205537c9afc46
|
|
| MD5 |
00383215200889f6bd296e149dd91af1
|
|
| BLAKE2b-256 |
a8efc359b062ca26703cdce1fff0bcaa92f17b1c7c201e47ca5995e848e7c3ed
|
Provenance
The following attestation bundles were made for multistage_build-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on pelson/multistage-build
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
multistage_build-0.1.0-py3-none-any.whl -
Subject digest:
0e1e8780052c6ba27c1878fe47680dd98c276c2459f51321306205537c9afc46 - Sigstore transparency entry: 254336109
- Sigstore integration time:
-
Permalink:
pelson/multistage-build@1922e33e2644dcc9d83dfb859516de1dfe33d28e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/pelson
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@1922e33e2644dcc9d83dfb859516de1dfe33d28e -
Trigger Event:
release
-
Statement type: