13
13
The ``pyproject.toml `` file acts as a configuration file for packaging-related
14
14
tools (as well as other tools).
15
15
16
- .. note :: This specification was originally defined in :pep:`518` and :pep:`621`.
16
+ .. note :: This specification was originally defined in :pep:`518`,
17
+ :pep: `517 ` and :pep: `621 `.
17
18
18
19
The ``pyproject.toml `` file is written in `TOML <https://toml.io >`_. Three
19
20
tables are currently specified, namely
@@ -29,71 +30,100 @@ Declaring build system dependencies: the ``[build-system]`` table
29
30
30
31
The ``[build-system] `` table declares any Python level dependencies that
31
32
must be installed in order to run the project's build system
32
- successfully.
33
+ successfully. The valid keys are ``requires ``, ``build-backend `` and
34
+ ``backend-path ``.
33
35
34
- .. TODO: merge with PEP 517
36
+ Tools should not require the existence of the ``[build-system] `` table.
37
+ A ``pyproject.toml `` file may be used to store configuration details
38
+ other than build-related data and thus lack a ``[build-system] `` table
39
+ legitimately.
40
+ If the table is specified but is missing required fields then the tool
41
+ should consider it an error.
42
+
43
+
44
+ ``requires ``
45
+ ------------
46
+
47
+ The ``requires `` key must have a value of a list of strings representing
48
+ dependencies required to execute the build system [#requires-json-schema ]_.
49
+ The strings in this list follow the :ref: `version specifier specification
50
+ <version-specifiers>`.
35
51
36
- The ``[build-system] `` table is used to store build-related data.
37
- Initially, only one key of the table is valid and is mandatory
38
- for the table: ``requires ``. This key must have a value of a list
39
- of strings representing dependencies required to execute the
40
- build system. The strings in this list follow the :ref: `version specifier
41
- specification <version-specifiers>`.
52
+ This key is mandatory if the ``[build-system] `` table is present. If
53
+ the ``pyproject.toml `` file is missing, or exists but is lacking the
54
+ ``[build-system] `` table, then ``requires `` defaults to ``["setuptools"] ``.
42
55
43
- An example ``[build-system] `` table for a project built with
44
- ``setuptools `` is:
56
+
57
+
58
+ ``build-backend ``
59
+ -----------------
60
+
61
+ The ``build-backend `` key is a string naming a Python object that will be
62
+ used to perform the build. This is formatted following the same
63
+ ``module:object `` syntax as an :ref: `entry point <entry-points >`.
64
+ For instance, with the configuration
45
65
46
66
.. code-block :: toml
47
67
48
68
[build-system]
49
- # Minimum requirements for the build system to execute.
50
- requires = ["setuptools"]
69
+ requires = ["backend-name"]
70
+ build-backend = "backend_name.build_system:backend"
51
71
52
- Build tools are expected to use the example configuration file above as
53
- their default semantics when a ``pyproject.toml `` file is not present.
72
+ this object would be looked up by executing the equivalent of::
54
73
55
- Tools should not require the existence of the ``[build-system] `` table.
56
- A ``pyproject.toml `` file may be used to store configuration details
57
- other than build-related data and thus lack a ``[build-system] `` table
58
- legitimately. If the file exists but is lacking the ``[build-system] ``
59
- table then the default values as specified above should be used.
60
- If the table is specified but is missing required fields then the tool
61
- should consider it an error.
74
+ import backend_name.build
75
+ backend = backend_name.build_system.backend
62
76
77
+ It is also legal to leave out the ``:object `` part, e.g.
63
78
64
- To provide a type-specific representation of the resulting data from
65
- the TOML file for illustrative purposes only, the following
66
- `JSON Schema <https://json-schema.org >`_ would match the data format:
79
+ .. code-block :: toml
67
80
68
- .. code-block :: json
81
+ build-backend = "backend_name.build_system"
69
82
70
- {
71
- "$schema" : " http://json-schema.org/schema#" ,
83
+ which acts like::
72
84
73
- "type" : " object " ,
74
- "additionalProperties" : false ,
85
+ import backend_name.build_system
86
+ backend = backend_name.build_system
75
87
76
- "properties" : {
77
- "build-system" : {
78
- "type" : " object" ,
79
- "additionalProperties" : false ,
88
+ Formally, the string should satisfy this grammar:
80
89
81
- "properties" : {
82
- "requires" : {
83
- "type" : " array" ,
84
- "items" : {
85
- "type" : " string"
86
- }
87
- }
88
- },
89
- "required" : [" requires" ]
90
- },
90
+ .. code-block :: text
91
+
92
+ identifier = (letter | '_') (letter | '_' | digit)*
93
+ module_path = identifier ('.' identifier)*
94
+ object_path = identifier ('.' identifier)*
95
+ entry_point = module_path (':' object_path)?
96
+
97
+ The module specified by ``module_path `` is imported and the build
98
+ backend object is looked up using ``module_path.object_path `` (or
99
+ ``module_path `` is directly used if ``object_path `` is missing).
100
+ See :ref: `build-system-interface ` for how the build backend object
101
+ is used to perform the build.
102
+
103
+ When importing the module path, we do *not * look in the directory
104
+ containing the source tree, unless that would be on ``sys.path `` anyway
105
+ (e.g. because it is specified in PYTHONPATH). Although Python
106
+ automatically adds the working directory to ``sys.path `` in some
107
+ situations, code to resolve the backend should not be affected by this.
108
+
109
+ Unlike the ``requires `` key, the ``build-backend `` key is optional
110
+ [#build-backend-optional ]_. If ``pyproject.toml `` is absent, or
111
+ the ``[build-system] `` table is missing, or it does not contain
112
+ the ``build-backend `` key, build frontends should revert to the legacy
113
+ behavior of running ``setup.py `` (either directly, or implicitly by
114
+ invoking the ``setuptools.build_meta:__legacy__ `` backend).
115
+
116
+
117
+ ``backend-path ``
118
+ ----------------
119
+
120
+ This key is for use by projects wishing to include their build backend
121
+ directly in their source tree, such as build backends themselves. If
122
+ provided, it must be a list of directories, which are prepended to
123
+ ``sys.path `` during the build. For details, see
124
+ :ref: `in-tree-build-backends ` in the build system interface
125
+ specification.
91
126
92
- "tool" : {
93
- "type" : " object"
94
- }
95
- }
96
- }
97
127
98
128
99
129
.. _pyproject-project-table :
@@ -441,8 +471,51 @@ History
441
471
=======
442
472
443
473
This specification was originally defined in :pep: `518 ` (``[build-system] ``
444
- and ``[tool] `` tables) and :pep: `621 ` (``[project] `` table).
474
+ and ``[tool] `` tables), :pep: `517 ` (``build-backend `` and ``backend-path ``
475
+ in the ``[build-system] `` table), and :pep: `621 ` (``[project] `` table).
476
+
477
+
478
+ --------------------------------------------------------------------------
479
+
480
+ .. [#requires-json-schema ] The following `JSON Schema <json-schema _>`_ was
481
+ originally provided, for illustrative purposes only, and has not been
482
+ updated:
483
+
484
+ .. code-block :: json
485
+
486
+ {
487
+ "$schema" : " http://json-schema.org/schema#" ,
488
+
489
+ "type" : " object" ,
490
+ "additionalProperties" : false ,
491
+
492
+ "properties" : {
493
+ "build-system" : {
494
+ "type" : " object" ,
495
+ "additionalProperties" : false ,
496
+
497
+ "properties" : {
498
+ "requires" : {
499
+ "type" : " array" ,
500
+ "items" : {
501
+ "type" : " string"
502
+ }
503
+ }
504
+ },
505
+ "required" : [" requires" ]
506
+ },
507
+
508
+ "tool" : {
509
+ "type" : " object"
510
+ }
511
+ }
512
+ }
513
+
445
514
515
+ .. [#build-backend-optional ] Historically, ``build-backend `` was defined
516
+ later than ``requires ``, thus making ``build-backend `` optional is to
517
+ preserve backwards compatibility.
446
518
447
519
448
520
.. _TOML : https://toml.io
521
+ .. _json-schema : https://json-schema.org
0 commit comments