Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python 3 Migration

Python 3 Migration

How we at CMB migrated a codebase of more than a million lines of code successfully from Python 2 to Python 3

Avatar for Ann Paul

Ann Paul

March 23, 2018

Other Decks in Programming

Transcript

  1. 6 MONTH 1 MONTH 2 2 WEEKS 3RD PARTY LIBRARIES

    _________________ 70 50 CODE COMPATIBILITY _________________ six, future, 2to3 TEST DEPLOY MONITOR _________________ iterate! 6
  2. Python 2.7.13 (default, Dec 19 2016, 14:18:49) [GCC 4.2.1 Compatible

    Apple LLVM 6.0 (clang-600.0.57)] on darwin >>> import pickle >>> set_cache('cached_pickle', pickle.dumps(obj, fix_imports=True)) 9 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1 9 Python 3.6.4 (default, Dec 19 2016, 14:20:49) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin >>> import pickle >>> obj = pickle.loads(get_cache('cached_pickle'))
  3. Python 3.6.4 (default, Dec 19 2016, 14:18:49) [GCC 4.2.1 Compatible

    Apple LLVM 6.0 (clang-600.0.57)] on darwin >>> hash('secret') -4264008114590981298 11 11 Python 3.6.4 (default, Dec 19 2016, 14:20:49) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin >>> hash('secret') -4139676931567953040 # Different hash
  4. Python 3.6.4 (default, Dec 19 2016, 14:18:49) [GCC 4.2.1 Compatible

    Apple LLVM 6.0 (clang-600.0.57)] on darwin >>> import hashlib >>> int(hashlib.md5(b'secret').hexdigest(), 16) 252103622270029474919056516158423780772 12 12 Python 3.6.4 (default, Dec 19 2016, 14:20:49) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin >>> import hashlib >>> int(hashlib.md5(b'secret').hexdigest(), 16) 252103622270029474919056516158423780772
  5. ROLLOUT TEST, MONITOR AND SLOWLY ROLLOUT REMOVE UPGRADE AND TRIM

    3RD PARTY LIBRARIES REFACTOR MAKE CODEBASE PYTHON 2 AND 3 COMPATIBLE ❖ http://python-future.org/compatible_idioms.html ❖ https://docs.python.org/3/howto/pyporting.html 16