Skip to content

Commit f82066d

Browse files
committed
Adapt the imported build interface text to the Guide
Normalize the PEP heading hierarchy and add stable cross-reference labels without changing hook signatures or requirement strength. Retain the frontend recommendations and examples, including the current amendment about duplicate config_settings keys. Replace the superseded editable-install discussion with a reference to PEP 660, remove the historical promise of a future hook-calling library, and record the specification's approval and amendments in History.
1 parent ee4cf5c commit f82066d

1 file changed

Lines changed: 75 additions & 40 deletions

File tree

‎source/specifications/build-system-interface.rst‎

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
.. _build-system-interface:
22

3-
######################
3+
======================
44
Build system interface
5-
######################
5+
======================
66

7-
=======================
8-
Terminology and goals
9-
=======================
7+
This specification defines a standard interface between build frontends and
8+
build backends to build wheels and source distributions from source trees.
9+
The project's build system is configured in the
10+
:ref:`[build-system] table <pyproject-build-system-table>` of
11+
:file:`pyproject.toml`.
12+
13+
.. _build-system-interface-terminology:
14+
15+
Terminology
16+
===========
1017

1118
A *source tree* is something like a VCS checkout. We need a standard
1219
interface for installing from this format, to support usages like
@@ -43,9 +50,10 @@ combination of wheels and sdists. In a command like ``pip install
4350
lxml==2.4.0``, pip is acting as an integration frontend.
4451

4552

46-
==============
47-
Source trees
48-
==============
53+
.. _build-system-interface-source-trees:
54+
55+
Source trees
56+
============
4957

5058
There is an existing, legacy source tree format involving
5159
``setup.py``. We don't try to specify it further; its de facto
@@ -61,7 +69,7 @@ Here we define a new style of source tree based around the
6169
[build-system]
6270
# Defined by PEP 518:
6371
requires = ["flit"]
64-
# Defined by this PEP:
72+
# Defined by this specification:
6573
build-backend = "flit.api:main"
6674

6775
``build-backend`` is a string naming a Python object that will be
@@ -110,21 +118,23 @@ Where the ``build-backend`` key exists, this takes precedence and the source tre
110118
conventions of the specified backend (as such no ``setup.py`` is needed unless the backend requires it).
111119
Projects may still wish to include a ``setup.py`` for compatibility with tools that do not use this spec.
112120

113-
This PEP also defines a ``backend-path`` key for use in ``pyproject.toml``, see
121+
This specification also defines a ``backend-path`` key for use in ``pyproject.toml``, see
114122
the "In-Tree Build Backends" section below. This key would be used as follows::
115123

116124
[build-system]
117125
# Defined by PEP 518:
118126
requires = ["flit"]
119-
# Defined by this PEP:
127+
# Defined by this specification:
120128
build-backend = "local_backend"
121129
backend-path = ["backend"]
122130

123131

132+
.. _build-system-interface-build-requirements:
133+
124134
Build requirements
125-
==================
135+
------------------
126136

127-
This PEP places a number of additional requirements on the "build requirements"
137+
This specification places a number of additional requirements on the "build requirements"
128138
section of ``pyproject.toml``. These are intended to ensure that projects do
129139
not create impossible to satisfy conditions with their build requirements.
130140

@@ -147,19 +157,22 @@ Typically this will involve specifying themselves as an in-tree backend, and
147157
avoiding external build dependencies (usually by vendoring them).
148158

149159

150-
=========================
151-
Build backend interface
152-
=========================
160+
.. _build-system-interface-backend-interface:
161+
162+
Build backend interface
163+
=======================
153164

154165
The build backend object is expected to have attributes which provide
155166
some or all of the following hooks. The common ``config_settings``
156167
argument is described after the individual hooks.
157168

158169
Mandatory hooks
159-
===============
170+
---------------
171+
172+
.. _build-system-interface-build-wheel:
160173

161174
build_wheel
162-
-----------
175+
~~~~~~~~~~~
163176

164177
::
165178

@@ -199,8 +212,10 @@ The backend may store intermediate artifacts in cache locations or
199212
temporary directories. The presence or absence of any caches should not
200213
make a material difference to the final result of the build.
201214

215+
.. _build-system-interface-build-sdist:
216+
202217
build_sdist
203-
-----------
218+
~~~~~~~~~~~
204219

205220
::
206221

@@ -238,10 +253,12 @@ The backend does not need to define this exception type if it would never raise
238253
it.
239254

240255
Optional hooks
241-
==============
256+
--------------
257+
258+
.. _build-system-interface-get-requires-for-build-wheel:
242259

243260
get_requires_for_build_wheel
244-
----------------------------
261+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
245262

246263
::
247264

@@ -260,8 +277,10 @@ Example::
260277

261278
If not defined, the default implementation is equivalent to ``return []``.
262279

280+
.. _build-system-interface-prepare-metadata-for-build-wheel:
281+
263282
prepare_metadata_for_build_wheel
264-
--------------------------------
283+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
265284

266285
::
267286

@@ -287,8 +306,10 @@ If a build frontend needs this information and the method is
287306
not defined, it should call ``build_wheel`` and look at the resulting
288307
metadata directly.
289308

309+
.. _build-system-interface-get-requires-for-build-sdist:
310+
290311
get_requires_for_build_sdist
291-
----------------------------
312+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
292313

293314
::
294315

@@ -303,19 +324,15 @@ dependency specifications, above and beyond those specified in the
303324
If not defined, the default implementation is equivalent to ``return []``.
304325

305326

306-
.. note:: Editable installs
327+
.. note::
328+
329+
Editable installs are specified separately in :pep:`660`.
307330

308-
This PEP originally specified another hook, ``install_editable``, to do an
309-
editable install (as with ``pip install -e``). It was removed due to the
310-
complexity of the topic, but may be specified in a later PEP.
311331

312-
Briefly, the questions to be answered include: what reasonable ways existing
313-
of implementing an 'editable install'? Should the backend or the frontend
314-
pick how to make an editable install? And if the frontend does, what does it
315-
need from the backend to do so.
332+
.. _build-system-interface-config-settings:
316333

317334
Config settings
318-
===============
335+
---------------
319336

320337
::
321338

@@ -375,8 +392,10 @@ If a hook raises an exception, or causes the process to terminate,
375392
then this indicates an error.
376393

377394

395+
.. _build-system-interface-build-environment:
396+
378397
Build environment
379-
=================
398+
-----------------
380399

381400
One of the responsibilities of a build frontend is to set up the
382401
Python environment in which the build backend will run.
@@ -429,11 +448,10 @@ stdlib, or that are explicitly declared as build-requirements.
429448

430449
Frontends should call each hook in a fresh subprocess, so that backends are
431450
free to change process global state (such as environment variables or the
432-
working directory). A Python library will be provided which frontends can use
433-
to easily call hooks this way.
451+
working directory).
434452

435453
Recommendations for build frontends (non-normative)
436-
---------------------------------------------------
454+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
437455

438456
A build frontend MAY use any mechanism for setting up a build
439457
environment that meets the above criteria. For example, simply
@@ -487,8 +505,10 @@ package *authors*, while still allowing *end-users* to open up the
487505
hood and apply duct tape when necessary.
488506

489507

508+
.. _build-system-interface-in-tree-build-backends:
509+
490510
In-tree build backends
491-
======================
511+
----------------------
492512

493513
In certain circumstances, projects may wish to include the source code for the
494514
build backend directly in the source tree, rather than referencing the backend
@@ -529,9 +549,10 @@ would typically involve checking the backend's ``__file__`` attribute against
529549
the locations in ``backend-path``.
530550

531551

532-
======================
533-
Source distributions
534-
======================
552+
.. _build-system-interface-source-distributions:
553+
554+
Source distributions
555+
====================
535556

536557
We continue with the legacy sdist format, adding some new restrictions.
537558
This format is mostly
@@ -554,3 +575,17 @@ The new restrictions for sdists built by :pep:`517` backends are:
554575
uses UTF-8 for file names.
555576
- The source tree contained in an sdist is expected to include the
556577
``pyproject.toml`` file.
578+
579+
580+
History
581+
========
582+
583+
- September 2017: This specification was provisionally approved through :pep:`517`.
584+
- March 2019: Cycles in build requirements were explicitly prohibited, and
585+
``backend-path`` was added to support in-tree and self-hosting backends.
586+
- May 2019: Clarified that invoking ``setuptools.build_meta:__legacy__`` is an
587+
acceptable alternative to directly invoking ``setup.py`` when ``build-backend``
588+
is not specified.
589+
- June 2021: :pep:`517` was marked Final.
590+
- February 2023: Clarified that frontends should combine values for duplicate
591+
``config_settings`` keys into a list of strings.

0 commit comments

Comments
 (0)