API to call PEP 517 hooks for building Python packages https://pep517.readthedocs.io/
Go to file
Thomas Kluyver ce8b84964a Prototype implementation of loading a self-hosting backend 2019-02-01 21:12:01 +00:00
pep517 Prototype implementation of loading a self-hosting backend 2019-02-01 21:12:01 +00:00
tests Prototype implementation of loading a self-hosting backend 2019-02-01 21:12:01 +00:00
.bumpversion.cfg Bump version: 0.4.0 → 0.5.0 2018-12-17 12:15:11 -05:00
.gitignore Add tox for testing 2018-07-22 15:58:39 +01:00
.travis.yml Run tests on Python 3.7 also 2018-12-17 10:29:02 -05:00
LICENSE Packaging with flit 2017-11-12 18:15:50 +00:00
README.rst Update usage example in README 2019-02-01 12:29:13 +00:00
RELEASE.rst Add release instructions. Fixes #29. 2018-12-17 09:36:26 -05:00
appveyor.yml Add tox for testing 2018-07-22 15:58:39 +01:00
dev-requirements.txt Declare setuptools>=30 to avoid errors on Python 3.4+ when venv gets older setuptools versions. 2018-12-17 09:59:36 -05:00
install-pip-master.py Indentation must be spaces 2018-12-17 10:27:02 -05:00
pyproject.toml Packaging with flit 2017-11-12 18:15:50 +00:00
pytest.ini Test modules with flake8. Ref #21. 2018-12-13 19:47:53 -05:00
tox.ini Remove workaround for #33 - no longer needed. 2018-12-17 12:14:58 -05:00

README.rst

PEP 517 specifies a standard API for systems which build Python packages.

This package contains wrappers around the hooks specified by PEP 517. 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.
  • Higher-level functions which install the build dependencies into a temporary environment and build a wheel/sdist using them.

Run the tests with py.test.

High level usage, with build requirements handled:

import os
from pep517.envbuild import build_wheel, build_sdist

src = 'path/to/source'  # Folder containing 'pyproject.toml'
destination = 'also/a/folder'
whl_filename = build_wheel(src, destination)
assert os.path.isfile(os.path.join(destination, whl_filename))

targz_filename = build_sdist(src, destination)
assert os.path.isfile(os.path.join(destination, targz_filename))

Lower level usage—you are responsible for ensuring build requirements are available:

import os
import pytoml
from pep517.wrappers import Pep517HookCaller

src = 'path/to/source'  # Folder containing 'pyproject.toml'
with open(os.path.join(src, 'pyproject.toml')) as f:
    build_sys = pytoml.load(f)['build-system']

print(build_sys['requires'])  # List of static requirements

hooks = Pep517HookCaller(src, build_backend=build_sys['build_backend'])

config_options = {}   # Optional parameters for backend
# List of dynamic requirements:
print(hooks.get_requires_for_build_wheel(config_options))

destination = 'also/a/folder'
whl_filename = hooks.build_wheel(destination, config_options)
assert os.path.isfile(os.path.join(destination, whl_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

This 'build' module should be considered experimental while the PyPA decides on the best place for this functionality.