Skip to content

Commit 3d95d2b

Browse files
authored
Merge pull request #2146 from harshitethic/docs-readme-pyproject-971
Use pyproject.toml for PyPI README metadata
2 parents f8b19fb + 710e30f commit 3d95d2b

1 file changed

Lines changed: 20 additions & 54 deletions

File tree

‎source/guides/making-a-pypi-friendly-readme.rst‎

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,77 +18,43 @@ Formats supported by `PyPI's README renderer <https://github.com/pypa/readme_ren
1818
* Markdown (`GitHub Flavored Markdown <https://github.github.com/gfm/>`_ by default,
1919
or `CommonMark <https://commonmark.org/>`_)
2020

21-
It's customary to save your README file in the root of your project, in the same directory as your :file:`setup.py` file.
21+
It's customary to save your README file in the root of your project, in the same directory as your :file:`pyproject.toml` file.
2222

2323

2424
Including your README in your package's metadata
2525
------------------------------------------------
2626

27-
To include your README's contents as your package description,
28-
set your project's ``Description`` and ``Description-Content-Type`` metadata,
29-
typically in your project's :file:`setup.py` file.
27+
To include your README as your project's long description on PyPI, declare
28+
the ``readme`` key in the ``[project]`` table of :file:`pyproject.toml`.
29+
Build backends use this value to populate the distribution's ``Description``
30+
and ``Description-Content-Type`` core metadata fields.
3031

3132
.. seealso::
3233

34+
* :ref:`declaring-project-metadata`
3335
* :ref:`description-optional`
3436
* :ref:`description-content-type-optional`
3537

36-
For example, to set these values in a package's :file:`setup.py` file,
37-
use ``setup()``'s ``long_description`` and ``long_description_content_type``.
38+
For Markdown or reStructuredText files, the simplest form is the README path:
3839

39-
Set the value of ``long_description`` to the contents (not the path) of the README file itself.
40-
Set the ``long_description_content_type`` to an accepted ``Content-Type``-style value for your README file's markup,
41-
such as ``text/plain``, ``text/x-rst`` (for reStructuredText), or ``text/markdown``.
40+
.. code-block:: toml
4241
43-
.. note::
42+
[project]
43+
name = "an-example-package"
44+
# other project metadata omitted
45+
readme = "README.md"
4446
45-
If you're using GitHub-flavored Markdown to write a project's description, ensure you upgrade
46-
the following tools:
47+
When the file name has a recognized ``.md`` or ``.rst`` extension, the
48+
content type is inferred automatically. For another file name or format,
49+
provide both the file path and content type explicitly:
4750

48-
.. tab:: Unix/macOS
49-
50-
.. code-block:: bash
51-
52-
python3 -m pip install --user --upgrade setuptools wheel twine
53-
54-
.. tab:: Windows
55-
56-
.. code-block:: bat
57-
58-
py -m pip install --user --upgrade setuptools wheel twine
59-
60-
The minimum required versions of the respective tools are:
61-
62-
- ``setuptools >= 38.6.0``
63-
- ``wheel >= 0.31.0``
64-
- ``twine >= 1.11.0``
65-
66-
It's recommended that you use ``twine`` to upload the project's distribution packages:
67-
68-
.. code-block:: bash
69-
70-
twine upload dist/*
71-
72-
For example, see this :file:`setup.py` file,
73-
which reads the contents of :file:`README.md` as ``long_description``
74-
and identifies the markup as GitHub-flavored Markdown:
75-
76-
.. code-block:: python
77-
78-
from setuptools import setup
79-
80-
# read the contents of your README file
81-
from pathlib import Path
82-
this_directory = Path(__file__).parent
83-
long_description = (this_directory / "README.md").read_text()
51+
.. code-block:: toml
8452
85-
setup(
86-
name='an_example_package',
87-
# other arguments omitted
88-
long_description=long_description,
89-
long_description_content_type='text/markdown'
90-
)
53+
[project]
54+
readme = { file = "README", content-type = "text/plain" }
9155
56+
The referenced README should remain in the project source tree so the build
57+
backend can read it when producing package metadata.
9258

9359
Validating reStructuredText markup
9460
----------------------------------

0 commit comments

Comments
 (0)