-
Notifications
You must be signed in to change notification settings - Fork 6
Remove Python 2 support
Michael Howitz edited this page Sep 29, 2020
·
10 revisions
- Remove Python 2 support
- Use f-strings (requires Python >= 3.6)
-
pyupgrade
installed (the code examples below expect it to be on the search PATH.)
The following steps are necessary to remove Python 2 support from a package:
-
setup.py
- Update version number to next major version.
- Remove Python 2 from the list of classifiers.
- Remove
six
from the list of dependencies - Update
python_requires
topython_requires='>=3.6, <4',
- Remove other things pointing to Python 2 or PyPy[2].
-
setup.cfg
- set
universal = 0
in section[bdist_wheel]
- set
-
tox.ini
- Remove
py27
andpypy
from `envlist - Remove Python 2 specific environments
- Remove
-
.travis.yml
- Remove Python 2.7 and PyPy jobs.
-
appveyor.yml
- Remove Python 2 job(s) if existing.
- CHANGES.rst
- Update the version number of the unreleased version
- Add an entry:
Drop support for Python 2.
- Remove Python 2 support code
- Run
find src -name "*.py" -exec pyupgrade --py3-plus {} \;
- Update the code to Python 3 e. g. by removing (some of)
six
usage.
- Update the code to Python 3 e. g. by removing (some of)
- Run
grep -rn six src
- Remove or change all the usages of
six
- Remove or change all the usages of
- Run the tests:
tox
+ fix problems - Commit the current status to a branch.
- Run
egrep -rn "2.7|sys.version|PY2|PY3|Py2|Py3|Python 2|Python 3|__unicode__|ImportError" src
- Fix branching depending on Python version etc.
- Run
find src -name "*.py" -exec pyupgrade --py36-plus {} \;
- Update code to more Python 3 only goodies.
- Run
- Create pull request from your changes.
- Create a new branch from
master
before your changes to be able to back port fixes later on easily to the version which still supports Python 2.
- document needed changes if a package is tests on Appveyor