Skip to content

Commit af82fef

Browse files
authored
Merge pull request #1396 from jeanas/unified-pyroject-spec
A unified pyproject.toml specification
2 parents a2cad18 + 99d6c23 commit af82fef

5 files changed

+130
-129
lines changed

source/flow.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@ required in the :file:`pyproject.toml` file. For example, you might specify:
9696

9797
* a ``[project]`` table containing project
9898
:doc:`Core Metadata </specifications/core-metadata/>`
99-
(name, version, author and so forth); see
100-
:doc:`Declaring project metadata </specifications/declaring-project-metadata/>`
101-
for more detail
99+
(name, version, author and so forth),
100+
101+
* a ``[tool]`` table containing tool-specific configuration options.
102+
103+
Refer to the :ref:`pyproject.toml guide <writing-pyproject-toml>` for a
104+
complete guide to ``pyproject.toml`` configuration.
102105

103-
* a ``[tool]`` table containing tool-specific configuration options
104106

105107
Build artifacts
106108
===============

source/specifications/declaring-build-dependencies.rst

Lines changed: 0 additions & 105 deletions
This file was deleted.

source/specifications/declaring-project-metadata.rst renamed to source/specifications/pyproject-toml.rst

Lines changed: 122 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,107 @@
1-
.. _declaring-project-metadata:
1+
.. _pyproject-toml-spec:
22

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+
================================
116

127
.. warning::
138

149
This is a **technical, formal specification**. For a gentle,
1510
user-friendly guide to ``pyproject.toml``, see
1611
:ref:`writing-pyproject-toml`.
1712

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#",
1872
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>`.
21105

22106
There are two kinds of metadata: *static* and *dynamic*. Static
23107
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
27111
(defined later in this specification) and represents metadata that a
28112
tool will later provide.
29113

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>`.
36114
The lack of a ``[project]`` table implicitly means the :term:`build backend <Build Backend>`
37115
will dynamically provide all keys.
38116

@@ -340,4 +418,31 @@ provided via tooling later on.
340418

341419

342420

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+
343448
.. _TOML: https://toml.io

source/specifications/section-distribution-metadata.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Package Distribution Metadata
99
core-metadata
1010
version-specifiers
1111
dependency-specifiers
12-
declaring-build-dependencies
13-
declaring-project-metadata
12+
pyproject-toml
1413
inline-script-metadata
1514
platform-compatibility-tags

source/specifications/source-distribution-format.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ A ``.tar.gz`` source distribution (sdist) contains a single top-level directory
5858
called ``{name}-{version}`` (e.g. ``foo-1.0``), containing the source files of
5959
the package. The name and version MUST match the metadata stored in the file.
6060
This directory must also contain a :file:`pyproject.toml` in the format defined in
61-
:ref:`declaring-build-dependencies`, and a ``PKG-INFO`` file containing
61+
:ref:`pyproject-toml-spec`, and a ``PKG-INFO`` file containing
6262
metadata in the format described in the :ref:`core-metadata` specification. The
6363
metadata MUST conform to at least version 2.2 of the metadata specification.
6464

0 commit comments

Comments
 (0)