Skip to content

Commit a02e069

Browse files
chryslewebknjazjeanasedgarrmondragon
committed
Apply review comments
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]> Co-authored-by: Jean Abou Samra <[email protected]> Co-authored-by: Edgar Ramírez Mondragón <[email protected]>
1 parent 4a5cbf9 commit a02e069

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

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

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,27 @@
44
Dropping support for older Python versions
55
==========================================
66

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.
88

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
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 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.
1818

1919
Dealing with the universal wheels
2020
---------------------------------
2121

22-
Traditionally, projects providing Python code that is semantically
22+
Traditionally, :ref:`setuptools` projects providing Python code that is semantically
2323
compatible with both Python 2 and Python 3, produce :term:`wheels
2424
<Wheel>` that have a ``py2.py3`` tag in their names. When dropping
2525
support for Python 2, it is important not to forget to change this tag
2626
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``.
2928

3029
If you use this method, either remove this option or section, or
3130
explicitly set ``universal`` to ``0``:
@@ -37,11 +36,10 @@ explicitly set ``universal`` to ``0``:
3736
[bdist_wheel]
3837
universal = 0 # Make the generated wheels have "py3" tag
3938
40-
.. tip::
39+
.. hint::
4140

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.
4543

4644
Defining the Python version required
4745
------------------------------------
@@ -68,16 +66,16 @@ Steps:
6866
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6967

7068
You can specify version ranges and exclusion rules (complying with the :ref:`version-specifiers` specification),
71-
such as at least Python 3. Or, Python 2.7, 3.4 and beyond:
69+
such as at least Python 3. Or, Python 3.7, 3.8, 3.13 and beyond:
7270

7371
.. code-block:: text
7472
7573
Requires-Python: ">= 3"
76-
Requires-Python: ">= 2.7, != 3.0.*, != 3.1.*, != 3.2.*, != 3.3.*"
74+
Requires-Python: ">= 3.7, != 3.9.*, != 3.10.*, != 3.11.*, != 3.12.*"
7775
7876
79-
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.
8179

8280
.. code-block:: toml
8381
@@ -89,34 +87,29 @@ The way to set those values is within your :file:`pyproject.toml`. The :ref:`req
8987
9088
9189
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`.
9892

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.
10395

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.
10699

107100
3. Validating the Metadata before publishing
108101
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109102

110103
Within a Python source package (the zip or the tar-gz file you download) is a text file called PKG-INFO.
111104

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.
113106
The file contains a set of keys and values, the list of keys is part of the PyPA standard metadata format.
114107

115108
You can see the contents of the generated file like this:
116109

117110
.. code-block:: bash
118111
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
120113
121114
Validate that the following is in place, before publishing the package:
122115

@@ -137,15 +130,14 @@ If however supporting a specific version becomes a blocker for a new feature or
137130
``Requires-Python`` should be amended. Of course this also depends on whether the project needs to be stable and
138131
well-covered for a wider range of users.
139132

140-
Each version compatibility change should have an own release.
133+
Each version compatibility change should have its own release.
141134

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::
147136

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.
149138

150-
.. _discourse discussion: https://discuss.python.org/t/requires-python-upper-limits/12663
139+
.. _discourse-discussion: https://discuss.python.org/t/requires-python-upper-limits/12663
151140
.. _pyupgrade: https://pypi.org/project/pyupgrade/
141+
.. _dependency-management: https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#python-requirement
142+
143+
.. [#] Support for the Metadata 1.2 specification has been added in Pip 9.0.

0 commit comments

Comments
 (0)