Skip to content

Commit 99d6c23

Browse files
committed
Merge branch 'main' into unified-pyroject-spec
2 parents 17eacba + 1142846 commit 99d6c23

9 files changed

+143
-61
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repos:
1515
rev: v2.2.6
1616
hooks:
1717
- id: codespell
18-
args: ["-L", "ned,ist,oder"]
18+
args: ["-L", "ned,ist,oder", "--skip", "*.po"]
1919

2020
- repo: local
2121
hooks:

source/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
"https://test.pypi.org/project/example-package-YOUR-USERNAME-HERE",
105105
"https://pypi.org/manage/*",
106106
"https://test.pypi.org/manage/*",
107+
# Temporarily ignored. Ref:
108+
# https://github.com/pypa/packaging.python.org/pull/1308#issuecomment-1775347690
109+
"https://www.breezy-vcs.org/*",
107110
]
108111

109112
# -- Options for extlinks ----------------------------------------------------------

source/guides/writing-pyproject-toml.rst

Lines changed: 87 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,98 @@
44
Writing your ``pyproject.toml``
55
===============================
66

7-
``pyproject.toml`` is a configuration file used by packaging tools. Most
8-
:term:`build backends <build backend>` [#poetry-special]_ allow you to specify
9-
your project's basic metadata, such as the dependencies, your name, etc.,
10-
in the ``[project]`` table of your ``pyproject.toml``.
7+
``pyproject.toml`` is a configuration file used by packaging tools, as
8+
well as other tools such as linters, type checkers, etc. There are
9+
three possible TOML tables in this file.
10+
11+
- The ``[build-system]`` table is **strongly recommended**. It allows
12+
you to declare which :term:`build backend` you use and which other
13+
dependencies are needed to build your project.
14+
15+
- The ``[project]`` table is the format that most build backends use to specify
16+
your project's basic metadata, such as the dependencies, your name, etc.
17+
18+
- The ``[tool]`` table has tool-specific subtables, e.g., ``[tool.hatch]``,
19+
``[tool.black]``, ``[tool.mypy]``. We only touch upon this table here because
20+
its contents are defined by each tool. Consult the particular tool's
21+
documentation to know what it can contain.
1122

1223
.. note::
1324

14-
You may have heard of ``setup.py`` and ``setup.cfg`` for the setuptools_
15-
build backend. For new projects, it is recommended to use ``pyproject.toml``
16-
for basic metadata, and keep ``setup.py`` only if some programmatic configuration
17-
is needed (especially building C extensions). However, putting basic project
18-
metadata in ``setup.py`` or ``setup.cfg`` is still valid. See
25+
There is a significant difference between the ``[build-system]`` and
26+
``[project]`` tables. The former should always be present, regardless of
27+
which build backend you use (since it *defines* the tool you use). The latter
28+
is understood by *most* build backends, but some build backends use a
29+
different format.
30+
31+
At the time of writing this (November 2023), Poetry_ is a notable build
32+
backend that does not use the ``[project]`` table (it uses the
33+
``[tool.poetry]`` table instead).
34+
35+
Also, the setuptools_ build backend supports both the ``[project]`` table,
36+
and the older format in ``setup.cfg`` or ``setup.py``. For new projects, it
37+
is recommended to use the ``[project]`` table, and keep ``setup.py`` only if
38+
some programmatic configuration is needed (such as building C extensions),
39+
but the ``setup.cfg`` and ``setup.py`` formats are still valid. See
1940
:ref:`setup-py-deprecated`.
2041

2142

43+
44+
Declaring the build backend
45+
===========================
46+
47+
The ``[build-system]`` table contains a ``build-backend`` key, which specifies
48+
the build backend to be used. It also contains a ``requires`` key, which is a
49+
list of dependencies needed to build the project -- this is typically just the
50+
build backend package, but it may also contain additional dependencies. You can
51+
also constrain the versions, e.g., ``requires = ["setuptools >= 61.0"]``.
52+
53+
Usually, you'll just copy what your build backend's documentation
54+
suggests (after :ref:`choosing your build backend <choosing-build-backend>`).
55+
Here are the values for some common build backends:
56+
57+
.. tab:: Hatchling
58+
59+
.. code-block:: toml
60+
61+
[build-system]
62+
requires = ["hatchling"]
63+
build-backend = "hatchling.build"
64+
65+
.. tab:: setuptools
66+
67+
.. code-block:: toml
68+
69+
[build-system]
70+
requires = ["setuptools >= 61.0"]
71+
build-backend = "setuptools.build_meta"
72+
73+
.. tab:: Flit
74+
75+
.. code-block:: toml
76+
77+
[build-system]
78+
requires = ["flit_core >= 3.4"]
79+
build-backend = "flit_core.buildapi"
80+
81+
.. tab:: PDM
82+
83+
.. code-block:: toml
84+
85+
[build-system]
86+
requires = ["pdm-backend"]
87+
build-backend = "pdm.backend"
88+
89+
90+
2291
Static vs. dynamic metadata
2392
===========================
2493

25-
Most of the time, you will directly write the value of a field in
26-
``pyproject.toml``. For example: ``requires-python = ">= 3.8"``, or
27-
``version = "1.0"``.
94+
The rest of this guide is devoted to the ``[project]`` table.
95+
96+
Most of the time, you will directly write the value of a ``[project]``
97+
field. For example: ``requires-python = ">= 3.8"``, or ``version =
98+
"1.0"``.
2899

29100
However, in some cases, it is useful to let your build backend compute
30101
the metadata for you. For example: many build backends can read the
@@ -316,6 +387,10 @@ A full example
316387

317388
.. code-block:: toml
318389
390+
[build-system]
391+
requires = ["hatchling"]
392+
build-backend = "hatchling.build"
393+
319394
[project]
320395
name = "spam-eggs"
321396
version = "2020.0.0"
@@ -370,10 +445,6 @@ A full example
370445
371446
------------------
372447

373-
.. [#poetry-special] At the time of this writing (November 2023), Poetry_
374-
is a notable exception. It uses its own format for this metadata, in
375-
the ``[tool.poetry]`` table.
376-
377448
.. [#requires-python-upper-bounds] Think twice before applying an upper bound
378449
like ``requires-python = "<= 3.10"`` here. `This blog post <requires-python-blog-post_>`_
379450
contains some information regarding possible problems.

source/specifications/index.rst

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,10 @@ by the Python Packaging Authority. The process for updating these standards,
88
and for proposing new ones, is documented on
99
`pypa.io <https://www.pypa.io/en/latest/specifications/>`__.
1010

11-
12-
Package Distribution Metadata
13-
-----------------------------
14-
15-
.. toctree::
16-
:maxdepth: 1
17-
18-
name-normalization
19-
core-metadata
20-
version-specifiers
21-
dependency-specifiers
22-
inline-script-metadata
23-
platform-compatibility-tags
24-
pyproject-toml
25-
26-
Package Installation Environment Metadata
27-
-----------------------------------------
28-
29-
.. toctree::
30-
:maxdepth: 1
31-
32-
recording-installed-packages
33-
entry-points
34-
direct-url
35-
direct-url-data-structure
36-
virtual-environments
37-
externally-managed-environments
38-
39-
Package Distribution File Formats
40-
---------------------------------
41-
42-
.. toctree::
43-
:maxdepth: 1
44-
45-
source-distribution-format
46-
binary-distribution-format
47-
48-
49-
Package Index Interfaces
50-
------------------------
51-
5211
.. toctree::
53-
:maxdepth: 1
12+
:titlesonly:
5413

55-
pypirc
56-
simple-repository-api
14+
section-distribution-metadata
15+
section-installation-metadata
16+
section-distribution-formats
17+
section-package-indices
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=================================
2+
Package Distribution File Formats
3+
=================================
4+
5+
.. toctree::
6+
:titlesonly:
7+
8+
source-distribution-format
9+
binary-distribution-format
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=============================
2+
Package Distribution Metadata
3+
=============================
4+
5+
.. toctree::
6+
:titlesonly:
7+
8+
name-normalization
9+
core-metadata
10+
version-specifiers
11+
dependency-specifiers
12+
pyproject-toml
13+
inline-script-metadata
14+
platform-compatibility-tags
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=============================
2+
Package Installation Metadata
3+
=============================
4+
5+
.. toctree::
6+
:titlesonly:
7+
8+
recording-installed-packages
9+
entry-points
10+
direct-url
11+
direct-url-data-structure
12+
virtual-environments
13+
externally-managed-environments
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
========================
2+
Package Index Interfaces
3+
========================
4+
5+
.. toctree::
6+
:titlesonly:
7+
8+
pypirc
9+
simple-repository-api

source/tutorials/packaging-projects.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ Creating a test directory
103103
:file:`tests/` is a placeholder for test files. Leave it empty for now.
104104

105105

106+
.. _choosing-build-backend:
107+
106108
Choosing a build backend
107109
------------------------
108110

0 commit comments

Comments
 (0)