1
- .. _ declaring-project-metadata :
1
+ .. _ pyproject-toml-spec :
2
2
3
- ==========================
4
- Declaring project metadata
5
- ==========================
6
-
7
- :pep: `621 ` specifies how to write a project's
8
- :ref: `core metadata <core-metadata >` in a ``pyproject.toml `` file for
9
- packaging-related tools to consume. It defines the following
10
- specification as the canonical source for the format used.
3
+ ================================
4
+ ``pyproject.toml `` specification
5
+ ================================
11
6
12
7
.. warning ::
13
8
14
9
This is a **technical, formal specification **. For a gentle,
15
10
user-friendly guide to ``pyproject.toml ``, see
16
11
:ref: `writing-pyproject-toml `.
17
12
13
+ The ``pyproject.toml `` file acts as a configuration file for packaging-related
14
+ tools (as well as other tools).
15
+
16
+ .. note :: This specification was originally defined in :pep:`518` and :pep:`621`.
17
+
18
+ The ``pyproject.toml `` file is written in `TOML <https://toml.io >`_. Three
19
+ tables are currently specified, namely
20
+ :ref: `[build-system] <pyproject-build-system-table >`,
21
+ :ref: `[project] <pyproject-project-table >` and
22
+ :ref: `[tool] <pyproject-tool-table >`. Other tables are reserved for future
23
+ use (tool-specific configuration should use the ``[tool] `` table).
24
+
25
+ .. _pyproject-build-system-table :
26
+
27
+ Declaring build system dependencies: the ``[build-system] `` table
28
+ =================================================================
29
+
30
+ The ``[build-system] `` table declares any Python level dependencies that
31
+ must be installed in order to run the project's build system
32
+ successfully.
33
+
34
+ .. TODO: merge with PEP 517
35
+
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>`.
42
+
43
+ An example ``[build-system] `` table for a project built with
44
+ ``setuptools `` is:
45
+
46
+ .. code-block :: toml
47
+
48
+ [build-system]
49
+ # Minimum requirements for the build system to execute.
50
+ requires = ["setuptools"]
51
+
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.
54
+
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.
62
+
63
+
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:
67
+
68
+ .. code-block :: json
69
+
70
+ {
71
+ "$schema" : " http://json-schema.org/schema#" ,
18
72
19
- Specification
20
- =============
73
+ "type" : " object" ,
74
+ "additionalProperties" : false ,
75
+
76
+ "properties" : {
77
+ "build-system" : {
78
+ "type" : " object" ,
79
+ "additionalProperties" : false ,
80
+
81
+ "properties" : {
82
+ "requires" : {
83
+ "type" : " array" ,
84
+ "items" : {
85
+ "type" : " string"
86
+ }
87
+ }
88
+ },
89
+ "required" : [" requires" ]
90
+ },
91
+
92
+ "tool" : {
93
+ "type" : " object"
94
+ }
95
+ }
96
+ }
97
+
98
+
99
+ .. _pyproject-project-table :
100
+
101
+ Declaring project metadata: the ``[project] `` table
102
+ ===================================================
103
+
104
+ The ``[project] `` table specifies the project's :ref: `core metadata <core-metadata >`.
21
105
22
106
There are two kinds of metadata: *static * and *dynamic *. Static
23
107
metadata is specified in the ``pyproject.toml `` file directly and
@@ -27,12 +111,6 @@ by the metadata). Dynamic metadata is listed via the ``dynamic`` key
27
111
(defined later in this specification) and represents metadata that a
28
112
tool will later provide.
29
113
30
- The keys defined in this specification MUST be in a table named
31
- ``[project] `` in ``pyproject.toml ``. No tools may add keys to this
32
- table which are not defined by this specification. For tools wishing
33
- to store their own settings in ``pyproject.toml ``, they may use the
34
- ``[tool] `` table as defined in the
35
- :ref: `build dependency declaration specification <declaring-build-dependencies >`.
36
114
The lack of a ``[project] `` table implicitly means the :term: `build backend <Build Backend> `
37
115
will dynamically provide all keys.
38
116
@@ -340,4 +418,31 @@ provided via tooling later on.
340
418
341
419
342
420
421
+ .. _pyproject-tool-table :
422
+
423
+ Arbitrary tool configuration: the ``[tool] `` table
424
+ ==================================================
425
+
426
+ The ``[tool] `` table is where any tool related to your Python
427
+ project, not just build tools, can have users specify configuration
428
+ data as long as they use a sub-table within ``[tool] ``, e.g. the
429
+ `flit <https://pypi.python.org/pypi/flit >`_ tool would store its
430
+ configuration in ``[tool.flit] ``.
431
+
432
+ A mechanism is needed to allocate names within the ``tool.* ``
433
+ namespace, to make sure that different projects do not attempt to use
434
+ the same sub-table and collide. Our rule is that a project can use
435
+ the subtable ``tool.$NAME `` if, and only if, they own the entry for
436
+ ``$NAME `` in the Cheeseshop/PyPI.
437
+
438
+
439
+
440
+ History
441
+ =======
442
+
443
+ This specification was originally defined in :pep: `518 ` (``[build-system] ``
444
+ and ``[tool] `` tables) and :pep: `621 ` (``[project] `` table).
445
+
446
+
447
+
343
448
.. _TOML : https://toml.io
0 commit comments