You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
Copy file name to clipboardExpand all lines: source/guides/dropping-older-python-versions.rst
+16-21Lines changed: 16 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,15 +6,15 @@ Dropping support for older Python versions
6
6
7
7
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.
8
8
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
10
10
in the package metadata. If they do not match, it will attempt to install the last package distribution that supported that Python runtime.
11
11
12
12
This mechanism can be used to drop support for older Python versions, by amending the ``Requires-Python`` attribute in the package metadata.
13
13
14
14
Requirements
15
15
------------
16
16
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.
18
18
19
19
Dealing with the universal wheels
20
20
---------------------------------
@@ -65,17 +65,9 @@ Steps:
65
65
2. Specify the version ranges for supported Python distributions
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:
79
71
80
72
.. code-block:: toml
81
73
@@ -85,16 +77,19 @@ corresponds to the ``Requires-Python`` metadata field.
85
77
[project]
86
78
requires-python = ">= 3.8" # At least Python 3.8
87
79
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"
88
87
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`.
92
88
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.
95
90
96
91
.. 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
98
93
and version conflicts. See the `discourse-discussion`_ for more information.
99
94
100
95
3. Validating the Metadata before publishing
@@ -113,7 +108,7 @@ You can see the contents of the generated file like this:
113
108
114
109
Validate that the following is in place, before publishing the package:
115
110
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.
117
112
- The ``Requires-Python`` field is set and matches your specification in the configuration file.
118
113
119
114
4. Publishing the package
@@ -134,7 +129,7 @@ Each version compatibility change should have its own release.
134
129
135
130
.. tip::
136
131
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.
0 commit comments