Skip to main content

Wrappers to build Python packages using PEP 517 hooks

Project description

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

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

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.

hooks = Pep517HookCaller(
    src,
    build_backend=build_sys['build-backend'],
    backend_path=build_sys.get('backend-path'),
)

config_options = {}   # Optional parameters for backend
# List of dynamic requirements:
print(hooks.get_requires_for_build_wheel(config_options))
# Again, the caller is responsible for installing these build requirements

destination = 'also/a/folder'
whl_filename = hooks.build_wheel(destination, config_options)
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

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))

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pep517-0.12.0.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pep517-0.12.0-py2.py3-none-any.whl (19.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pep517-0.12.0.tar.gz.

File metadata

  • Download URL: pep517-0.12.0.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.26.0

File hashes

Hashes for pep517-0.12.0.tar.gz
Algorithm Hash digest
SHA256 931378d93d11b298cf511dd634cf5ea4cb249a28ef84160b3247ee9afb4e8ab0
MD5 7ed0adb5f737c316e071d48d66329a5d
BLAKE2b-256 0a656e656d49c679136edfba25f25791f45ffe1ea4ae2ec1c59fe9c35e061cd1

See more details on using hashes here.

File details

Details for the file pep517-0.12.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pep517-0.12.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.26.0

File hashes

Hashes for pep517-0.12.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dd884c326898e2c6e11f9e0b64940606a93eb10ea022a2e067959f3a110cf161
MD5 6e9c63b2635523a2f0bddcc579cbfc57
BLAKE2b-256 f467846c08e18fefb265a66e6fd5a34269d649b779718d9bf59622085dabd370

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page