No project description provided
Project description
Wheel Metadata Injector
A tool that injects build metadata into Python wheel packages according to PEP 658.
This allows metadata that the builder would like to get included from the build to be inspected in the final wheel without downloading and installing the entire wheel. A good example and motivation for this is TORCH_CUDA_ARCH_LIST, which controls how code is compiled for packages that link to torch. This makes it much easier post-facto to figure out what a wheel was built against, and can potentially serve as inputs for advanced resolvers.
Installation
pip install wheel-metadata-injector
Usage
Command Line Interface
# Process a wheel file (overwrites the original file)
wheel-metadata-injector path/to/your-package-1.0.0-py3-none-any.whl
# Process a wheel file and save to a new location
wheel-metadata-injector path/to/your-package-1.0.0-py3-none-any.whl -o path/to/output.whl
# Process a wheel file using environment variables from a file
wheel-metadata-injector path/to/your-package-1.0.0-py3-none-any.whl -e path/to/env_vars.txt
# Process a wheel file using inline list of environment variables
wheel-metadata-injector path/to/your-package-1.0.0-py3-none-any.whl -v "PATH,PYTHONPATH,CUDA_VERSION"
Environment Variables Configuration
By default, the tool captures a predefined list of environment variables (see Whitelisted Environment Variables section).
Alternatively, you can provide a file containing a custom list of environment variable names to collect. Example file content:
# This is a comment
TORCH_CUDA_ARCH_LIST
CUDA_VERSION
BUILD_TYPE
PATH
PYTHONPATH
# Each line should contain just one variable name
Python API
from wheel_metadata_injector import (
process_wheel,
process_wheel_with_env_file,
get_whitelisted_env_vars,
get_whitelisted_env_vars_with_file
)
# Get environment variables using default whitelist
env_vars = get_whitelisted_env_vars()
print(f"Will inject {len(env_vars)} environment variables")
# Get environment variables using custom list from file
env_vars = get_whitelisted_env_vars_with_file("path/to/env_vars.txt")
print(f"Will inject {len(env_vars)} environment variables from custom list")
# Process a wheel file using system environment variables
output_path = process_wheel("path/to/your-package-1.0.0-py3-none-any.whl")
# or specify output path
output_path = process_wheel("path/to/your-package-1.0.0-py3-none-any.whl", "path/to/output.whl")
# Process a wheel file using custom environment variable list from file
output_path = process_wheel_with_env_file(
"path/to/your-package-1.0.0-py3-none-any.whl",
"path/to/env_vars.txt",
"path/to/output.whl" # output path is optional
)
# Process a wheel file using inline list of environment variables
output_path = process_wheel_with_env_vars(
"path/to/your-package-1.0.0-py3-none-any.whl",
"PATH,PYTHONPATH,CUDA_VERSION",
"path/to/output.whl" # output path is optional
)
Setuptools Plugin
The package can be used as a setuptools plugin to automatically inject environment metadata when building wheels.
Method 1: Import to automatically register the command
# Import the custom wheel command to register it automatically
from wheel_metadata_injector import InjectMetadataBdistWheel
from setuptools import setup, find_packages
setup(
name="your-package",
version="0.1.0",
packages=find_packages(),
# ... other args
)
Method 2: Explicitly set the command class
from wheel_metadata_injector import InjectMetadataBdistWheel
from setuptools import setup, find_packages
setup(
name="your-package",
version="0.1.0",
packages=find_packages(),
cmdclass={
'bdist_wheel': InjectMetadataBdistWheel,
},
# ... other args
)
Then build your wheel as usual:
python setup.py bdist_wheel
You can skip the metadata injection by passing the --skip-metadata-injection flag:
python setup.py bdist_wheel --skip-metadata-injection
To use environment variables from a file:
python setup.py bdist_wheel --env-file path/to/env_vars.txt
To specify environment variables inline:
python setup.py bdist_wheel --env-vars "PATH,PYTHONPATH,CUDA_VERSION"
See the examples directory for more detailed usage.
Whitelisted Environment Variables
This tool captures the following environment variables:
TORCH_CUDA_ARCH_LISTCUDA_VERSIONCUDA_HOMECUDNN_VERSIONBUILD_TYPEPYTORCH_BUILD_VERSIONPYTORCH_BUILD_NUMBERCMAKE_ARGSEXTRA_CAFFE2_CMAKE_FLAGS
Development
Build from source
# Clone the repository
git clone https://github.com/yourusername/wheel-metadata-injector.git
cd wheel-metadata-injector
# Install development dependencies
pip install maturin
# Build and install in development mode
maturin develop
# Build a wheel
maturin build --release
Running Tests
The project uses pytest for testing and just as a command runner.
First, install just and the test dependencies:
# Install just (on macOS)
brew install just
# On other platforms, see: https://github.com/casey/just#installation
# Install test dependencies
pip install pytest pytest-cov
To run the tests using just:
# Run all tests
just test
# Run tests with coverage report
just coverage
# Run only end-to-end tests
just test-e2e
# See all available commands
just
You can also run pytest directly:
# Build the package first
maturin develop
# Run all tests
pytest
See the tests directory for more details on testing.
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 Distributions
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 wheel_metadata_injector-0.0.1rc2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: wheel_metadata_injector-0.0.1rc2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 968.5 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2217ff256c85f2e9aaad292d1990b48e31177c59754c437afc0639056e18d951
|
|
| MD5 |
91cf5ac2faed3da51c77e775bee82e0c
|
|
| BLAKE2b-256 |
f55087e3e3190bcb4d13e8dc93efd869eb33bfb8b233c801862a00c96017ae38
|
Provenance
The following attestation bundles were made for wheel_metadata_injector-0.0.1rc2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release_python.yml on wseaton/wheel-metadata-injector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wheel_metadata_injector-0.0.1rc2-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl -
Subject digest:
2217ff256c85f2e9aaad292d1990b48e31177c59754c437afc0639056e18d951 - Sigstore transparency entry: 204778909
- Sigstore integration time:
-
Permalink:
wseaton/wheel-metadata-injector@5b7bf84afb05cbe02dbb82aa02af673abd4e1235 -
Branch / Tag:
refs/tags/v0.0.1rc2 - Owner: https://github.com/wseaton
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release_python.yml@5b7bf84afb05cbe02dbb82aa02af673abd4e1235 -
Trigger Event:
push
-
Statement type: