![]() |
5 days ago | |
---|---|---|
.github/workflows | 7 months ago | |
doc | 7 months ago | |
pep517 | 3 weeks ago | |
tests | 7 months ago | |
.bumpversion.cfg | 9 months ago | |
.gitignore | 12 months ago | |
LICENSE | 5 years ago | |
README.rst | 2 months ago | |
RELEASE.rst | 4 years ago | |
dev-requirements.txt | 2 months ago | |
issue_template.md | 1 year ago | |
pyproject.toml | 2 months ago | |
pytest.ini | 11 months ago | |
tox.ini | 7 months ago |
README.rst
API to call PEP 517 hooks
PEP 517 specifies a standard API for systems which build Python packages.
PEP 660 extends it with a build mode that leads to editable installs.
This package contains wrappers around the hooks specified by PEP 517 and PEP 660. It provides:
- A mechanism to call the hooks in a subprocess, so they are isolated from the current process.
- Fallbacks for the optional hooks, so that frontends can call the hooks without checking which are defined.
Run the tests with pytest
or tox.
Usage—you are responsible for ensuring build requirements are available:
import os
import tomli
from pep517.wrappers import Pep517HookCaller
= 'path/to/source' # Folder containing 'pyproject.toml'
src with open(os.path.join(src, 'pyproject.toml'), 'rb') as f:
= tomli.load(f)['build-system']
build_sys
print(build_sys['requires']) # List of static requirements
# The caller is responsible for installing these and running the hooks in
# an environment where they are available.
= Pep517HookCaller(
hooks
src, =build_sys['build-backend'],
build_backend=build_sys.get('backend-path'),
backend_path
)
= {} # Optional parameters for backend
config_options # List of dynamic requirements:
print(hooks.get_requires_for_build_wheel(config_options))
# Again, the caller is responsible for installing these build requirements
= 'also/a/folder'
destination = hooks.build_wheel(destination, config_options)
whl_filename assert os.path.isfile(os.path.join(destination, whl_filename))
Deprecated high-level
For now, pep517
also contains higher-level functions which install the build dependencies into a temporary environment and build a wheel/sdist using them. This is a rough implementation, e.g. it does not do proper build isolation. The PyPA build project is recommended as an alternative, although it's still quite young in October 2020. This layer of functionality in pep517
is now deprecated, but won't be removed for some time, as there is code relying on it.
High level usage, with build requirements handled:
import os
from pep517.envbuild import build_wheel, build_sdist
= 'path/to/source' # Folder containing 'pyproject.toml'
src = 'also/a/folder'
destination = build_wheel(src, destination)
whl_filename assert os.path.isfile(os.path.join(destination, whl_filename))
= build_sdist(src, destination)
targz_filename assert os.path.isfile(os.path.join(destination, targz_filename))
To test the build backend for a project, run in a system shell:
python3 -m pep517.check path/to/source # source dir containing pyproject.toml
To build a backend into source and/or binary distributions, run in a shell:
python -m pep517.build path/to/source # source dir containing pyproject.toml
All of this high-level functionality is deprecated.