Utilities to work with PEP 725 `[external]` metadata
Project description
pyproject-external
This is a proof of concept CLI (plus a Python API) to interact with
PEP 725 [external] metadata.
Note: all of this is currently experimental, and under the hood doesn't look anything like a production-ready version would. Please don't use this for anything beyond experimenting.
CLI usage
The CLI interface available as python -m pyproject_external provides several subcommands:
show: Query[external]metadata from pyproject.toml or source distributions. It can render it as is, normalized, mapped to your package manager names, or as a ready-to-run install command.prepare: Prepare a package for building with user-provided[external]metadata by downloading and patching its most recent sdist.build: Build a wheel for the given sdist or project. External dependencies are installed before the build starts.install: Install a project in the given location. Wheels will be built as needed. External dependencies are installed before the build starts too.
Example
Let's build cryptography from source! You'll need git and pixi.
Install
First, let's install pyproject-external:
# Clone the repository
git clone https://github.com/jaimergp/pyproject-external.git
cd pyproject-external/
# Enter a new pixi shell, this shall stay open in the rest of the example
pixi shell
You can also use
pixi rundirectly instead ofpixi shell, likepixi run python -m pyproject_external, but in this example we'll assume you are inside apixi shell.
In this shell, pyproject_external is installed and available as:
# Run the CLI help
python -m pyproject_external
If you don't want to use pixi at all, you can also use uv run -m pyproject_external directly. Note that in this case the package manager auto-detection will fallback to a system package manager (and not Pixi), so it will likely make changes to your system installation.
Prepare sdist
Now, let's prepare the cryptography sdist for building. Checking their install instructions,
it would require this [external] table:
[external]
build-requires = [
"dep:virtual/compiler/c",
"dep:virtual/compiler/rust",
"dep:generic/pkg-config",
]
host-requires = [
"dep:generic/openssl",
"dep:generic/libffi",
]
Save it as cryptography.toml in a external-metadata directory and then run this command:
python -m pyproject_external prepare cryptography --external-metadata-dir=external-metadata/
You'll find a patched cryptography-*.tar.gz file under the sdist/ directory.
Inspect patched sdist
What happened during prepare? We simply amended the sdist pyproject.toml to include the [external] table and put it back in the tarball. We can now inspect it with the show subcommand:
Show the [external] table as is:
$ python -m pyproject_external show sdist/cryptography-*.tar.gz
[external]
build-requires = [
"dep:virtual/compiler/c",
"dep:virtual/compiler/rust",
"dep:generic/pkg-config",
]
host-requires = [
"dep:generic/openssl",
"dep:generic/libffi",
]
Map the dep: URLs to conda-forge packages (auto-detected because we are in a Pixi shell):
$ python -m pyproject_external show sdist/cryptography-*.tar.gz --output=mapped
[external]
build_requires = [
"c-compiler",
"rust",
"pkg-config",
"python",
]
host_requires = [
"openssl",
"libffi",
]
Write the command needed to install these dependencies (again, Pixi auto-detected because of pixi shell):
$ python -m pyproject_external show sdist/cryptography-*.tar.gz --output=command
pixi add c-compiler rust pkg-config openssl libffi python
If you want a different package manager, use --package-manager. Notice how the package names are also different, since they are mapped to the correct ecosystem (Debian), instead of the auto-detected conda-forge.
$ python -m pyproject_external show sdist/cryptography-*.tar.gz --output=command --package-manager=apt
sudo apt install --yes gcc rustc pkgconf openssl libffi8 libffi-dev python3
Build wheel
Now you can take the patched sdist and turn it into a wheel with:
python -m pyproject_external build sdist/cryptography-*.tar.gz
This will fail if you run it locally! That's intentional. We need to install external dependencies with your system package manager, which might be a surprising side effect, specially if there are tons of dependencies to install (e.g. compilers, heavy librariers, etc). By default, it will auto-detect the system package manager for your distribution (e.g. apt for Ubuntu), but here you can also provide a different one with --package-manager.
If you understand the risks, proceed with:
CI=1 python -m pyproject_external build sdist/cryptography-*.tar.gz
A cryptography-*.whl file will show up in your working directory. You can install it with pip install or distribute it in your preferred way.
Install wheel directly
If you don't want to keep the wheel file around, you can build it and install it in a single step with:
CI=1 python -m pyproject_external install sdist/cryptography-*.tar.gz
Same warnings apply about the CI=1 guards!
Python API
The library offers several classes importable from pyproject_external.
The high-level API is provided by the External class. All the other
objects are considered low-level API to interact with the data
provided by external-metadata-mappings.
Related projects
external-deps-build: CI workflows to build popular PyPI packages patched with the necessary[external]metadata.external-metadata-mappings: Schemas, registries and mappings to support[external]metadata for different ecosystems and package managers.
Contributing
Refer to CONTRIBUTING.
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 pyproject_external-0.1.7.tar.gz.
File metadata
- Download URL: pyproject_external-0.1.7.tar.gz
- Upload date:
- Size: 88.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b83f4e766129fc8b9dfe26c5c97d64f804161b8954fc8a4a22bb8921f2636aad
|
|
| MD5 |
c1a012034fa20461a4b0d26169db8ff9
|
|
| BLAKE2b-256 |
d6ace4e32b470556e3b6cb917e8b0415771ffe7cd5c531f70a2b110b97215068
|
Provenance
The following attestation bundles were made for pyproject_external-0.1.7.tar.gz:
Publisher:
pypi.yml on jaimergp/pyproject-external
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyproject_external-0.1.7.tar.gz -
Subject digest:
b83f4e766129fc8b9dfe26c5c97d64f804161b8954fc8a4a22bb8921f2636aad - Sigstore transparency entry: 474003376
- Sigstore integration time:
-
Permalink:
jaimergp/pyproject-external@dc1bc69643ce931d44ed4c6401bed81c8c115774 -
Branch / Tag:
refs/tags/0.1.7 - Owner: https://github.com/jaimergp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@dc1bc69643ce931d44ed4c6401bed81c8c115774 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyproject_external-0.1.7-py3-none-any.whl.
File metadata
- Download URL: pyproject_external-0.1.7-py3-none-any.whl
- Upload date:
- Size: 35.2 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 |
aba7755e3d2348a7988cfcf5e48b43ca68b224e1bb1a9d9a6be6824db47449b6
|
|
| MD5 |
3f91282d94b1f78b6dfd3ffbcef0148c
|
|
| BLAKE2b-256 |
51fbeae26ffc6781972d5705eac3e32af4b3b54377445a9df5c9f90124fc924b
|
Provenance
The following attestation bundles were made for pyproject_external-0.1.7-py3-none-any.whl:
Publisher:
pypi.yml on jaimergp/pyproject-external
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyproject_external-0.1.7-py3-none-any.whl -
Subject digest:
aba7755e3d2348a7988cfcf5e48b43ca68b224e1bb1a9d9a6be6824db47449b6 - Sigstore transparency entry: 474003387
- Sigstore integration time:
-
Permalink:
jaimergp/pyproject-external@dc1bc69643ce931d44ed4c6401bed81c8c115774 -
Branch / Tag:
refs/tags/0.1.7 - Owner: https://github.com/jaimergp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@dc1bc69643ce931d44ed4c6401bed81c8c115774 -
Trigger Event:
release
-
Statement type: