Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

We have nearly one million lines of Python 2 code in production — and now?

101 views

Published on

Still running Python 2 code in production is like steering a ship without radar in thick fog: You don’t know, which obstacle you will hit next. But there are ways to see the sun again even for large code bases. This presentation contains a discussion of the possible ways and for a success story.

Published in: Software
  • Be the first to comment

  • Be the first to like this

We have nearly one million lines of Python 2 code in production — and now?

  1. 1. Michael Howitz, gocept We have nearly one million lines of Python 2 code in production — and now? Image by sipa from Pixabay
  2. 2. Michael Howitz Introduction • since 2003 * at gocept gmbh & co kg. * in Halle (Saale), DE * Python developer
  3. 3. Agenda • Discussion of approaches • Introduction into union.cms • Doing the migration • Tips and tricks
  4. 4. • Sunset the application • Replace by something off the shelf • Don’t migrate • Start over / Fade out • Move to Python 3 Discussion of approaches
  5. 5. Possible approaches Sunset the application Image by Pexels from Pixabay
  6. 6. Possible approaches Replace by something off the shelf Image by Michal Jarmoluk from Pixabay
  7. 7. Possible approaches Don’t migrate Image by Lynn Greyling from Pixabay
  8. 8. Possible approaches Start over Image by Lynn Greyling from Pixabay
  9. 9. Possible approaches Move to Python 3 Image by Marcus Bouvin from Pixabay
  10. 10. union.cms ☞ Migrate to Python 3
  11. 11. Steps towards running on Python 3
  12. 12. Migration steps I. General preparation • Know your tools: Python 2 and 3 and the differences • Have a good test coverage. • Type annotations might help.
  13. 13. Migration steps II. Clean up code and tests • Make sure all tests run and pass • Find out which code parts are still used, delete the rest
  14. 14. Migration steps III.Bring dependencies to Python 3 • List all Python package dependencies • Check each dependency for Python 3 compatibility • Update to newest versions of dependencies • Replace or port not yet Python 3 compatible ones • Create a dependency tree of your packages * tl.eggdeps
  15. 15. Migration steps IV.Migrate the code • Run python-modernize (package is called modernize.) • Run pylint --py3k • Fix the tests. * pytest-quarantine * Make sure, the tests still run on Python 2. • Mark code with # PY2 resp. # PY3.
  16. 16. Migration steps V. Switch to Python 3 • Run instance against empty database. • Maybe migrate the data. • Test the application in depth from end to end. • Rollout on Python 3. • Drop Python 2 support. * pyupgrade
  17. 17. • Use metrics to compute the effort * pylint warning: 30 min * doctest: 20 min * Python module: 5 min * modernized Python module: 2 min * base effort per package: 135 min • Plan the migration • Rollout often Schedule
  18. 18. • Target to a recent Python 3 version • No long running branches • Always do small steps • Take the time it needs Tips and tricks
  19. 19. • Python 2 End Of Life Survey from ActiveState * https://www.activestate.com/resource s/white-papers/python-2-eol-survey- results/ • union.cms consumers * https://www.dgb.de * https://www.verdi.de • My employer * https://gocept.com/index_en.html • Migration helpers * https://pypi.org/project/mypy/ * https://pypi.org/project/modernize/ * https://pypi.org/project/pylint/ * https://pypi.org/project/pytest- quarantine/ * https://www.stxnext.com/blog/python- 3-migration-guide/ * https://portingguide.readthedocs.io * https://pypi.org/project/pyupgrade/ * https://pypi.org/project/tl.eggdeps/ Links

×