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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.070s · 17.9MB
glibcpy 3.10–3.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')
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.
fixUse 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.
fixInstall 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`.
fixEnsure 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').
fixProvide 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