Skip to content

Commit c5723df

Browse files
chryslejaraco
andcommitted
Use pyproject.toml instead of core metadata syntax
Better version range examples, tweak grammar, mention `ruff` as helper tool for Python version upgrade Co-authored-by: Jason R. Coombs <[email protected]>
1 parent a02e069 commit c5723df

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

source/guides/dropping-older-python-versions.rst

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ Dropping support for older Python versions
66

77
The ability to drop support for older Python versions is enabled by the standard :ref:`core-metadata` 1.2 specification via the :ref:`"Requires-Python" <core-metadata-requires-python>` attribute.
88

9-
Metadata 1.2+ clients, such as Pip, will adhere to this specification by matching the current Python runtime and comparing it with the required version
9+
Metadata 1.2+ installers, such as Pip, will adhere to this specification by matching the current Python runtime and comparing it with the required version
1010
in the package metadata. If they do not match, it will attempt to install the last package distribution that supported that Python runtime.
1111

1212
This mechanism can be used to drop support for older Python versions, by amending the ``Requires-Python`` attribute in the package metadata.
1313

1414
Requirements
1515
------------
1616

17-
This workflow requires that the user installing the package uses Pip [#]_, or another client that supports the Metadata 1.2 specification.
17+
This workflow requires that the user installing the package uses Pip [#]_, or another installer that supports the Metadata 1.2 specification.
1818

1919
Dealing with the universal wheels
2020
---------------------------------
@@ -65,17 +65,9 @@ Steps:
6565
2. Specify the version ranges for supported Python distributions
6666
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6767

68-
You can specify version ranges and exclusion rules (complying with the :ref:`version-specifiers` specification),
69-
such as at least Python 3. Or, Python 3.7, 3.8, 3.13 and beyond:
70-
71-
.. code-block:: text
72-
73-
Requires-Python: ">= 3"
74-
Requires-Python: ">= 3.7, != 3.9.*, != 3.10.*, != 3.11.*, != 3.12.*"
75-
76-
77-
Those values can be set within your :file:`pyproject.toml`. The :ref:`requires-python` configuration field
78-
corresponds to the ``Requires-Python`` metadata field.
68+
Set the version ranges declaring which Python distributions are supported
69+
within your project's :file:`pyproject.toml`. The :ref:`requires-python` configuration field
70+
corresponds to the :ref:`Requires-Python <core-metadata-requires-python>` core metadata field:
7971

8072
.. code-block:: toml
8173
@@ -85,16 +77,19 @@ corresponds to the ``Requires-Python`` metadata field.
8577
[project]
8678
requires-python = ">= 3.8" # At least Python 3.8
8779
80+
You can specify version ranges and exclusion rules (complying with the :ref:`version-specifiers` specification),
81+
such as at least Python 3.9. Or, at least Python 3.7 and beyond, skipping the 3.7.0 and 3.7.1 point releases:
82+
83+
.. code-block:: toml
84+
85+
requires-python = ">= 3.9"
86+
requires-python = ">= 3.7, != 3.7.0, != 3.7.1"
8887
89-
For :ref:`setuptools` users, another way to achieve this is using the ``python_requires`` parameter
90-
in your :file:`setup.cfg` config or the :file:`setup.py` script. ``setuptools < 61`` does not support
91-
declaring the package metadata in :file:`pyproject.toml`.
9288
93-
Consult the ``setuptools`` `dependency-management`_ documentation for information about the appropriate
94-
way to configure each of these files.
89+
If using the :ref:`setuptools` build backend, consult the `dependency-management`_ documentation for more options.
9590

9691
.. caution::
97-
It is warned against adding upper bounds to the version ranges, e. g. ``">= 3.8 < 3.10"``. This can cause different errors
92+
Avoid adding upper bounds to the version ranges, e. g. ``">= 3.8, < 3.10"``. Doing so can cause different errors
9893
and version conflicts. See the `discourse-discussion`_ for more information.
9994

10095
3. Validating the Metadata before publishing
@@ -113,7 +108,7 @@ You can see the contents of the generated file like this:
113108
114109
Validate that the following is in place, before publishing the package:
115110

116-
- If you have upgraded correctly, the Metadata-Version value should be 1.2 or higher.
111+
- If you have upgraded correctly, the ``Metadata-Version`` value should be 1.2 or higher.
117112
- The ``Requires-Python`` field is set and matches your specification in the configuration file.
118113

119114
4. Publishing the package
@@ -134,7 +129,7 @@ Each version compatibility change should have its own release.
134129

135130
.. tip::
136131

137-
When dropping a Python version, it might also be rewarding to upgrade the project's code syntax generally, apart from updating the versions used in visible places (like the testing environment). Tools like pyupgrade_ can simplify this task.
132+
When dropping a Python version, it might also be rewarding to upgrade the project's code syntax generally, apart from updating the versions used in visible places (like the testing environment). Tools like pyupgrade_ or `ruff <https://docs.astral.sh/ruff/linter/>`_ can automate some of this work.
138133

139134
.. _discourse-discussion: https://discuss.python.org/t/requires-python-upper-limits/12663
140135
.. _pyupgrade: https://pypi.org/project/pyupgrade/

0 commit comments

Comments
 (0)