Skip to content

Commit 9cadc66

Browse files
tonybaloneyncoghlan
authored andcommitted
Guide for phasing out Python versions (#459)
Instructions for setuptools/distutils users looking to gracefully drop support for older Python versions, by keeping users of those versions on the last release stream that supported it.
1 parent 1252354 commit 9cadc66

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
.. _`Dropping Support for Older Python Versions`:
2+
3+
==========================================
4+
Dropping Support for Older Python Versions
5+
==========================================
6+
7+
Dropping support for older Python versions is supported by the standard :ref:`core-metadata` 1.2 specification via a "Requires-Python" attribute.
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
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+
12+
This mechanism can be used to drop support for older Python versions, by amending the "Requires-Python" attribute in the package metadata.
13+
14+
This guide is specifically for users of :ref:`setuptools`, other packaging tools such as ``flit`` may offer similar functionality but users will need to consult relevant documentation.
15+
16+
Requirements
17+
------------
18+
19+
This workflow requires that:
20+
21+
1. The publisher is using the latest version of :ref:`setuptools`,
22+
2. The latest version of :ref:`twine` is used to upload the package,
23+
3. The user installing the package has at least Pip 9.0, or a client that supports the Metadata 1.2 specification.
24+
25+
Defining the Python version required
26+
------------------------------------
27+
28+
1. Download the newest version of Setuptools
29+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30+
31+
Ensure that before you generate source distributions or binary distributions, you update Setuptools and twine.
32+
33+
Steps::
34+
35+
pip install --upgrade setuptools twine
36+
37+
Version should be above 24.0.0.
38+
39+
2. Specify the version ranges for supported Python distributions
40+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41+
42+
You can specify version ranges and exclusion rules, such as at least Python 3. Or, Python 2.7, 3.4 and beyond.
43+
44+
Examples::
45+
46+
Requires-Python: ">=3"
47+
Requires-Python: ">2.7,!=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
48+
49+
The way to set those values is within the call to `setup` within your setup.py script. This will insert the Requires-Python
50+
metadata values based on the argument you provide in `python_requires`.
51+
52+
..code-block:: Python
53+
54+
from setuptools import setup
55+
56+
57+
setup(
58+
# Your setup arguments
59+
python_requires='>=2.7', # Your supported Python ranges
60+
)
61+
62+
3. Validating the Metadata before publishing
63+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64+
65+
Within a Python source package (the zip or the tar-gz file you download) is a text file called PKG-INFO.
66+
67+
This file is generated by Distutils or :ref:`setuptools` when it generates the source package.
68+
The file contains a set of keys and values, the list of keys is part of the PyPa standard metadata format.
69+
70+
You can see the contents of the generated file like this:
71+
72+
tar xvfz dist/my-package-1.0.0.tar.gz -O | cat */PKG-INFO
73+
74+
Validate that the following is in place, before publishing the package:
75+
76+
- If you have upgraded correctly, the Metadata-Version value should be 1.2 or higher.
77+
- The Requires-Python field is set and matches your specification in setup.py.
78+
79+
4. Using Twine to publish
80+
~~~~~~~~~~~~~~~~~~~~~~~~~
81+
82+
Twine has a number of advantages, apart from being faster it is now the supported method for publishing packages.
83+
84+
Make sure you are using the newest version of Twine, at least 1.9.
85+
86+
Dropping a Python release
87+
-------------------------
88+
89+
Once you have published a package with the Requires-Python metadata, you can then make a further update removing that Python runtime from support.
90+
91+
It must be done in this order for the automated fail-back to work.
92+
93+
For example, you published the Requires-Python: ">=2.7" as version 1.0.0 of your package.
94+
95+
If you were then to 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
96+
have version 1.0.0 of the package installed, and any >=3.5 users will receive version 2.0.0.

‎source/guides/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ introduction to packaging, see :doc:`/tutorials/index`.
1515
multi-version-installs
1616
single-sourcing-package-version
1717
supporting-multiple-python-versions
18+
dropping-older-python-versions
1819
packaging-binary-extensions
1920
supporting-windows-using-appveyor
2021
packaging-namespace-packages

0 commit comments

Comments
 (0)