Python Necromancy
This year I had deal with reviewing two old projects.
Both projects had Python 2 support and Python 3 compatibility with six.
Both had been using setup.py for installation and can not be installed on any
of the modern & currently supported Python versions.
But I was fortunate that both projects had tests.
Here’s my action plan for Python necromancy.
-
If projects are on PyPI and test PyPI, make sure that you have maintainer/ owner access to the old project. If you don’t you will have to create separate projects on PyPI and test PyPI.
-
Convert old setup systems to
pyproject.toml. -
With the above step you will have to update the dependencies as well.
-
Drop support for any unsupported Python versions. This will make your life easier with dealing with dependencies and not having to support Python 2 or older versions.
-
When possible drop any dependencies. Less dependencies to worry about is always a plus.
-
When possible drop any features that doesn’t require. Try to get the MVP (Minimal Viable Product), you can always look to add any missing features later on.
-
When the package is installable, do some manual tests to see the intended features are working as intended.
-
Delete any special Python 2 checks and Python 2 specific logic. Lot of projects that have transitioned Python 3 will have checks for the Python version.
-
If you are lucky to have tests, use tox to run tests for all supported Python versions.
-
Work on fixing tests, you might have to make judgement calls about keeping some tests or making complex tests simpler.
-
Add tests as a CI/CD test.
-
Add PyPI Trusted Publisher to your projects.
Optional steps: