Skip to content

Remove Python 2 support

Michael Howitz edited this page Sep 29, 2020 · 10 revisions

Goals

  • Remove Python 2 support
  • Use f-strings (requires Python >= 3.6)

Prerequisites

  • pyupgrade installed (the code examples below expect it to be on the search PATH.)

Steps

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 to python_requires='>=3.6, <4',
    • Remove other things pointing to Python 2 or PyPy[2].
  • setup.cfg
    • set universal = 0 in section [bdist_wheel]
  • tox.ini
    • Remove py27 and pypy from `envlist
    • Remove Python 2 specific environments
  • .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.
    • Run grep -rn six src
      • Remove or change all the usages of six
    • 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.
  • 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.

Open issues

  • document needed changes if a package is tests on Appveyor
Clone this wiki locally