Registry / devops / pyproject-hooks

pyproject-hooks

JSON →
library1.2.0pypypi✓ verified 27d ago

A low-level library for calling build-backends in pyproject.toml-based Python projects. Current version: 1.2.0, released on September 29, 2024. Maintained by Thomas Kluyver, it provides basic functionality to help write tooling that generates distribution files from Python projects. If you want a tool that builds Python packages, you'll want to use https://github.com/pypa/build instead. This is an underlying piece for pip, build, and other 'build frontends' use to call 'build backends' within them. Note: The pep517 project has been replaced by this project (low level) and the build project (high level).

pip install pyproject-hooks
INSTALL
IMPORT
SIG · PYPROJECT-HOOKS
P
pyproject-hooks
devopspythonv1.2.0
Install
1.6s avg
Import
66ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.070s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.062s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BuildBackendHookCaller
from pyproject_hooks import BuildBackendHookCaller
Correct import path for BuildBackendHookCaller
BackendUnavailable
from pyproject_hooks import BackendUnavailable
Correct import path for BackendUnavailable exception
HookMissing
from pyproject_hooks import HookMissing
Correct import path for HookMissing exception
UnsupportedOperation
from pyproject_hooks import UnsupportedOperation
Correct import path for UnsupportedOperation exception
default_subprocess_runner
from pyproject_hooks import default_subprocess_runner
Correct import path for default_subprocess_runner function
quiet_subprocess_runner
from pyproject_hooks import quiet_subprocess_runner
Correct import path for quiet_subprocess_runner function

A basic example demonstrating how to use BuildBackendHookCaller to call the 'build_sdist' hook from a pyproject.toml-based project.

import os from pyproject_hooks import BuildBackendHookCaller # Set the path to your pyproject.toml file pyproject_toml_path = os.environ.get('PYPROJECT_TOML_PATH', 'pyproject.toml') # Initialize the BuildBackendHookCaller hook_caller = BuildBackendHookCaller(pyproject_toml_path) # Call the build hook hook_caller.call_hook('build_sdist')
Debug
Known issues
breakingIn version 1.0.0, the package was renamed from 'pep517' to 'pyproject_hooks'.
fix
Update import statements to use 'pyproject_hooks' instead of 'pep517'.
affects: 1.0.0
deprecatedIn version 1.0.0, deprecated modules '.build', '.check', and '.envbuild' were removed. Use the 'build' project for higher-level functionality.
fix
Replace usage of '.build', '.check', and '.envbuild' with the 'build' project.
affects: 1.0.0
gotchaIn version 1.1.0, the 'BackendInvalid' exception was renamed to 'BackendUnavailable'.
fix
Update exception handling code to use 'BackendUnavailable' instead of 'BackendInvalid'.
affects: 1.1.0
Errors
Common errors & fixes
ImportError: cannot import name 'build_wheel' from 'pyproject_hooks'
Developers often mistake `pyproject-hooks` as a high-level build tool and attempt to import functions like `build_wheel` directly, which are methods of the `BackendHookCaller` class, not top-level functions.
fix
Use a high-level build frontend like `build` (e.g., `python -m build`) for building packages. If you need to interact with build hooks at a low level, instantiate `pyproject_hooks.BackendHookCaller` and call its methods.
ModuleNotFoundError: No module named 'pyproject_hooks'
The `pyproject-hooks` package is not installed in the current Python environment. It's often an indirect dependency for build tools like `pip` or `build`, so direct installation might be overlooked if a developer tries to use its API explicitly.
fix
Install the package using pip: `pip install pyproject-hooks`
ModuleNotFoundError: No module named 'setuptools.build_meta'
When `pyproject-hooks` attempts to load the specified build backend (e.g., `setuptools.build_meta` or `flit_core.build_api`) from the `pyproject.toml` file or an explicitly passed `build_backend` argument, the module cannot be found. This usually means the build backend package itself is not installed, or its name is misspelled in `pyproject.toml`.
fix
Ensure the build backend specified in your `pyproject.toml` (e.g., `build-system.requires` and `build-system.build-backend`) is installed in your environment. For `setuptools.build_meta`, install `setuptools`: `pip install setuptools`. For `flit_core.build_api`, install `flit-core`: `pip install flit-core`.
TypeError: BackendHookCaller.__init__ missing 1 required positional argument: 'build_backend'
The `pyproject_hooks.BackendHookCaller` class requires the `build_backend` argument during instantiation, specifying the Python import path to the build backend (e.g., 'setuptools.build_meta').
fix
Provide the `build_backend` argument when creating an instance of `BackendHookCaller`, for example: `from pyproject_hooks import BackendHookCaller; caller = BackendHookCaller(source_dir='./my_project', build_backend='setuptools.build_meta')`.
Upgrade
Version history
1.2.0latest on PyPI · released Sep 29, 2024
Audit
Dependencies
importlib.metadatarequiredImproved interoperability with importlib.metadata in version 1.2.0
Agent activity
9 hits · last 30 days
node
8
Resources
pyproject-hooks — pip install pyproject-hooks · libregistry