11.. _build-system-interface :
22
3- ######################
3+ ======================
44Build 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
1118A *source tree * is something like a VCS checkout. We need a standard
1219interface for installing from this format, to support usages like
@@ -43,9 +50,10 @@ combination of wheels and sdists. In a command like ``pip install
4350lxml==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
5058There 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
110118conventions of the specified backend (as such no ``setup.py `` is needed unless the backend requires it).
111119Projects 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
114122the "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+
124134Build 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"
128138section of ``pyproject.toml ``. These are intended to ensure that projects do
129139not 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
147157avoiding 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
154165The build backend object is expected to have attributes which provide
155166some or all of the following hooks. The common ``config_settings ``
156167argument is described after the individual hooks.
157168
158169Mandatory hooks
159- ===============
170+ ---------------
171+
172+ .. _build-system-interface-build-wheel :
160173
161174build_wheel
162- -----------
175+ ~~~~~~~~~~~
163176
164177::
165178
@@ -199,8 +212,10 @@ The backend may store intermediate artifacts in cache locations or
199212temporary directories. The presence or absence of any caches should not
200213make a material difference to the final result of the build.
201214
215+ .. _build-system-interface-build-sdist :
216+
202217build_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
238253it.
239254
240255Optional hooks
241- ==============
256+ --------------
257+
258+ .. _build-system-interface-get-requires-for-build-wheel :
242259
243260get_requires_for_build_wheel
244- ----------------------------
261+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
245262
246263::
247264
@@ -260,8 +277,10 @@ Example::
260277
261278If not defined, the default implementation is equivalent to ``return [] ``.
262279
280+ .. _build-system-interface-prepare-metadata-for-build-wheel :
281+
263282prepare_metadata_for_build_wheel
264- --------------------------------
283+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
265284
266285::
267286
@@ -287,8 +306,10 @@ If a build frontend needs this information and the method is
287306not defined, it should call ``build_wheel `` and look at the resulting
288307metadata directly.
289308
309+ .. _build-system-interface-get-requires-for-build-sdist :
310+
290311get_requires_for_build_sdist
291- ----------------------------
312+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
292313
293314::
294315
@@ -303,19 +324,15 @@ dependency specifications, above and beyond those specified in the
303324If 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
317334Config settings
318- ===============
335+ ---------------
319336
320337::
321338
@@ -375,8 +392,10 @@ If a hook raises an exception, or causes the process to terminate,
375392then this indicates an error.
376393
377394
395+ .. _build-system-interface-build-environment :
396+
378397Build environment
379- =================
398+ -----------------
380399
381400One of the responsibilities of a build frontend is to set up the
382401Python environment in which the build backend will run.
@@ -429,11 +448,10 @@ stdlib, or that are explicitly declared as build-requirements.
429448
430449Frontends should call each hook in a fresh subprocess, so that backends are
431450free 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
435453Recommendations for build frontends (non-normative)
436- ---------------------------------------------------
454+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
437455
438456A build frontend MAY use any mechanism for setting up a build
439457environment that meets the above criteria. For example, simply
@@ -487,8 +505,10 @@ package *authors*, while still allowing *end-users* to open up the
487505hood and apply duct tape when necessary.
488506
489507
508+ .. _build-system-interface-in-tree-build-backends :
509+
490510In-tree build backends
491- ======================
511+ ----------------------
492512
493513In certain circumstances, projects may wish to include the source code for the
494514build 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
529549the locations in ``backend-path ``.
530550
531551
532- ======================
533- Source distributions
534- ======================
552+ .. _build-system-interface-source-distributions :
553+
554+ Source distributions
555+ ====================
535556
536557We continue with the legacy sdist format, adding some new restrictions.
537558This 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