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
Copy file name to clipboardExpand all lines: source/guides/dropping-older-python-versions.rst
+28-36Lines changed: 28 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,28 +4,27 @@
4
4
Dropping support for older Python versions
5
5
==========================================
6
6
7
-
Dropping support for older Python versions is supported by the standard :ref:`core-metadata` 1.2 specification via a:ref:`"Requires-Python" <core-metadata-requires-python>` attribute.
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 9.0+, will adhere to this specification by matching the current Python runtime and comparing it with the required version
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
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 has at least Pip 9.0, or a client that supports the Metadata 1.2 specification.
17
+
This workflow requires that the user installing the package uses Pip [#]_, or another client that supports the Metadata 1.2 specification.
18
18
19
19
Dealing with the universal wheels
20
20
---------------------------------
21
21
22
-
Traditionally, projects providing Python code that is semantically
22
+
Traditionally, :ref:`setuptools` projects providing Python code that is semantically
23
23
compatible with both Python 2 and Python 3, produce :term:`wheels
24
24
<Wheel>` that have a ``py2.py3`` tag in their names. When dropping
25
25
support for Python 2, it is important not to forget to change this tag
26
26
to just ``py3``. It is often configured within :file:`setup.cfg` under
27
-
the ``[bdist_wheel]`` section by setting ``universal = 1`` if they
28
-
use setuptools.
27
+
the ``[bdist_wheel]`` section by setting ``universal = 1``.
29
28
30
29
If you use this method, either remove this option or section, or
31
30
explicitly set ``universal`` to ``0``:
@@ -37,11 +36,10 @@ explicitly set ``universal`` to ``0``:
37
36
[bdist_wheel]
38
37
universal = 0 # Make the generated wheels have "py3" tag
39
38
40
-
.. tip::
39
+
.. hint::
41
40
42
-
Since it is possible to override the :file:`setup.cfg` settings via
43
-
CLI flags, make sure that your scripts don't have ``--universal`` in
44
-
your package creation scripts.
41
+
Regarding :ref:`deprecated <setup-py-deprecated>` direct ``setup.py`` invocations,
42
+
passing the ``--universal`` flag on the command line could override this setting.
The way to set those values is within your :file:`pyproject.toml`. The :ref:`requires-python` field of the
80
-
``[project]`` table corresponds to the ``Requires-Python`` metadata field.
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.
81
79
82
80
.. code-block:: toml
83
81
@@ -89,34 +87,29 @@ The way to set those values is within your :file:`pyproject.toml`. The :ref:`req
89
87
90
88
91
89
For :ref:`setuptools` users, another way to achieve this is using the ``python_requires`` parameter
92
-
in the call to ``setup`` within your :file:`setup.py` script.
93
-
94
-
.. code-block:: python
95
-
96
-
from setuptools import setup
97
-
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`.
98
92
99
-
setup(
100
-
# Your setup arguments
101
-
python_requires='>= 3.8',
102
-
)
93
+
Consult the ``setuptools`` `dependency-management`_ documentation for information about the appropriate
94
+
way to configure each of these files.
103
95
104
-
It is warned against adding upper bounds to the version ranges, e. g. ``">= 3.8 < 3.10"``. This can cause different errors
105
-
and version conflicts. See the `discourse discussion`_ for more information.
96
+
.. caution::
97
+
It is warned against adding upper bounds to the version ranges, e. g. ``">= 3.8 < 3.10"``. This can cause different errors
98
+
and version conflicts. See the `discourse-discussion`_ for more information.
106
99
107
100
3. Validating the Metadata before publishing
108
101
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109
102
110
103
Within a Python source package (the zip or the tar-gz file you download) is a text file called PKG-INFO.
111
104
112
-
This file is generated by the build backend when it generates the source package.
105
+
This file is generated by the :term:`build backend <Build Backend>` when it generates the source package.
113
106
The file contains a set of keys and values, the list of keys is part of the PyPA standard metadata format.
114
107
115
108
You can see the contents of the generated file like this:
116
109
117
110
.. code-block:: bash
118
111
119
-
tar xf dist/my-package-1.0.0.tar.gz my-package-1.0.0/PKG-INFO -O
112
+
tar xfO dist/my-package-1.0.0.tar.gz my-package-1.0.0/PKG-INFO
120
113
121
114
Validate that the following is in place, before publishing the package:
122
115
@@ -137,15 +130,14 @@ If however supporting a specific version becomes a blocker for a new feature or
137
130
``Requires-Python`` should be amended. Of course this also depends on whether the project needs to be stable and
138
131
well-covered for a wider range of users.
139
132
140
-
Each version compatibility change should have an own release.
133
+
Each version compatibility change should have its own release.
141
134
142
-
For example, you published version 1.0.0 of your package with ``Requires-Python: ">= 2.7"`` metadata.
143
-
144
-
If you then update the version string to ``">= 3.5"``, and publish a new version 2.0.0 of your package, any users running Pip 9.0+ from version 2.7 will have version 1.0.0 of the package installed, and any ``>= 3.5`` users will receive version 2.0.0.
145
-
146
-
It may be a good idea to create a minor release, stating that it is the last one compatible with the Python version to be removed, just before dropping that version.
135
+
.. tip::
147
136
148
-
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.
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.
0 commit comments