Skip to content

Commit 5dcb943

Browse files
committed
Add examples to each field in the pyproject.toml project table spec
This makes it an easier reference section for readers, since this serves as the primary user-facing documentation around the `project` table today.
1 parent d0509af commit 5dcb943

1 file changed

Lines changed: 95 additions & 8 deletions

File tree

source/specifications/declaring-project-metadata.rst

Lines changed: 95 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ The name of the project.
7373
Tools SHOULD normalize this name, as specified by :pep:`503`, as soon
7474
as it is read for internal consistency.
7575

76+
.. code-block:: toml
77+
78+
[project]
79+
name = "spam"
7680
7781
``version``
7882
-----------
@@ -85,6 +89,10 @@ The version of the project as supported by :pep:`440`.
8589

8690
Users SHOULD prefer to specify already-normalized versions.
8791

92+
.. code-block:: toml
93+
94+
[project]
95+
version = "2020.0.0"
8896
8997
``description``
9098
---------------
@@ -95,6 +103,10 @@ Users SHOULD prefer to specify already-normalized versions.
95103

96104
The summary description of the project.
97105

106+
.. code-block:: toml
107+
108+
[project]
109+
description = "Lovely Spam! Wonderful Spam!"
98110
99111
``readme``
100112
----------
@@ -134,6 +146,13 @@ alternative content-types which they can transform to a content-type
134146
as supported by the :ref:`core metadata <core-metadata>`. Otherwise
135147
tools MUST raise an error for unsupported content-types.
136148

149+
.. code-block:: toml
150+
151+
[project]
152+
# A single pyproject.toml file can only have one of the following.
153+
readme = "README.md"
154+
readme = "README.rst"
155+
readme = {file = "README.txt", content-type = "text/markdown"}
137156
138157
``requires-python``
139158
-------------------
@@ -144,6 +163,10 @@ tools MUST raise an error for unsupported content-types.
144163

145164
The Python version requirements of the project.
146165

166+
.. code-block:: toml
167+
168+
[project]
169+
requires-python = ">=3.8"
147170
148171
``license``
149172
-----------
@@ -159,6 +182,12 @@ file's encoding is UTF-8. The ``text`` key has a string value which is
159182
the license of the project. These keys are mutually exclusive, so a
160183
tool MUST raise an error if the metadata specifies both keys.
161184

185+
.. code-block:: toml
186+
187+
[project]
188+
# A single pyproject.toml file can only have one of the following.
189+
license = {file = "LICENSE"}
190+
license = {text = "MIT License"}
162191
163192
``authors``/``maintainers``
164193
---------------------------
@@ -201,6 +230,19 @@ follows:
201230
as appropriate, with the format ``{name} <{email}>``.
202231
4. Multiple values should be separated by commas.
203232

233+
.. code-block:: toml
234+
235+
[project]
236+
authors = [
237+
{name = "Pradyun Gedam", email = "pradyun@example.com"},
238+
{name = "Tzu-Ping Chung", email = "tzu-ping@example.com"},
239+
{name = "Another person"},
240+
{email = "different.person@example.com"},
241+
]
242+
maintainers = [
243+
{name = "Brett Cannon", email = "brett@python.org"}
244+
]
245+
204246
205247
``keywords``
206248
------------
@@ -211,6 +253,10 @@ follows:
211253

212254
The keywords for the project.
213255

256+
.. code-block:: toml
257+
258+
[project]
259+
keywords = ["egg", "bacon", "sausage", "tomatoes", "Lobster Thermidor"]
214260
215261
``classifiers``
216262
---------------
@@ -221,6 +267,12 @@ The keywords for the project.
221267

222268
Trove classifiers which apply to the project.
223269

270+
.. code-block:: toml
271+
272+
classifiers = [
273+
"Development Status :: 4 - Beta",
274+
"Programming Language :: Python"
275+
]
224276
225277
``urls``
226278
--------
@@ -232,6 +284,13 @@ Trove classifiers which apply to the project.
232284
A table of URLs where the key is the URL label and the value is the
233285
URL itself.
234286

287+
.. code-block:: toml
288+
289+
[project.urls]
290+
homepage = "https://example.com"
291+
documentation = "https://readthedocs.org"
292+
repository = "https://github.com/me/spam.git"
293+
changelog = "https://github.com/me/spam/blob/master/CHANGELOG.md"
235294
236295
Entry points
237296
------------
@@ -262,6 +321,17 @@ Build back-ends MUST raise an error if the metadata defines a
262321
be ambiguous in the face of ``[project.scripts]`` and
263322
``[project.gui-scripts]``, respectively.
264323

324+
.. code-block:: toml
325+
326+
[project.scripts]
327+
spam-cli = "spam:main_cli"
328+
329+
[project.gui-scripts]
330+
spam-gui = "spam:main_gui"
331+
332+
[project.entry-points."spam.magical"]
333+
tomatoes = "spam:main_tomatoes"
334+
265335
266336
``dependencies``/``optional-dependencies``
267337
------------------------------------------
@@ -289,6 +359,22 @@ in the array thus becomes a corresponding
289359
matching :ref:`Provides-Extra <core-metadata-provides-extra>`
290360
metadata.
291361

362+
.. code-block:: toml
363+
364+
[project]
365+
dependencies = [
366+
"httpx",
367+
"gidgethub[httpx]>4.0.0",
368+
"django>2.1; os_name != 'nt'",
369+
"django>2.0; os_name == 'nt'",
370+
]
371+
372+
[project.optional-dependencies]
373+
gui = ["PyQt5"]
374+
cli = [
375+
"rich",
376+
"click",
377+
]
292378
293379
``dynamic``
294380
-----------
@@ -327,6 +413,10 @@ provided via tooling later on.
327413
the data for it (omitting the data, if determined to be the accurate
328414
value, is acceptable).
329415

416+
.. code-block:: toml
417+
418+
dynamic = ["version", "description", "optional-dependencies"]
419+
330420
331421
Example
332422
=======
@@ -359,19 +449,16 @@ Example
359449
"httpx",
360450
"gidgethub[httpx]>4.0.0",
361451
"django>2.1; os_name != 'nt'",
362-
"django>2.0; os_name == 'nt'"
452+
"django>2.0; os_name == 'nt'",
363453
]
364454
365455
# dynamic = ["version", "description"]
366456
367457
[project.optional-dependencies]
368-
test = [
369-
"pytest > 5.0.0",
370-
"pytest-cov[all]"
371-
]
372-
doc = [
373-
"sphinx",
374-
"furo"
458+
gui = ["PyQt5"]
459+
cli = [
460+
"rich",
461+
"click",
375462
]
376463
377464
[project.urls]

0 commit comments

Comments
 (0)