user:kluong:improvement_-_upgrade_gateway_code_from_python2_to_python3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
user:kluong:improvement_-_upgrade_gateway_code_from_python2_to_python3 [2021/10/07 05:23]
kluong created
user:kluong:improvement_-_upgrade_gateway_code_from_python2_to_python3 [2022/02/17 14:58] (current)
kluong
Line 1: Line 1:
 ====== Improvement - Update gateway code from python 2 to python 3 ====== ====== Improvement - Update gateway code from python 2 to python 3 ======
 +
 +===== Background =====
  
 Python 2 is no longer supported, we should migrate to python 3. Python 2 is no longer supported, we should migrate to python 3.
 +
 +Python 2 was officially sunset on Jan 1, 2020: https://​www.python.org/​doc/​sunset-python-2/​
 +
 +Prior to doing this, it would be helpful to reformat some of the code - there’s a mix of tabs and spaces (switch to only using spaces)
 +
 +There’s a python tool called 2to3 that should help with this conversion. Here's a really simple example. Consider an old python2 file below - where there is a print statement without parenthesis:​
 +
 +<​code>​
 +cat old.py
 +print "​hello,​ world"
 +</​code>​
 +
 +We can run `2to3` on the file with the `-w` flag to edit it inline:
 +
 +<​code>​
 +$ 2to3 -w old.py
 +RefactoringTool:​ Skipping optional fixer: buffer
 +RefactoringTool:​ Skipping optional fixer: idioms
 +RefactoringTool:​ Skipping optional fixer: set_literal
 +RefactoringTool:​ Skipping optional fixer: ws_comma
 +RefactoringTool:​ Refactored old.py
 +--- old.py (original)
 ++++ old.py (refactored)
 +@@ -1 +1 @@
 +-print "hello world"
 ++print("​hello world"​)
 +</​code>​
 +
 +You can see the print function was modified to convert it to something that's acceptable in python3.
 +
 +===== Tasks =====
 +
 +
 +  - Cleanup some of the indentation in the code - there mixed tabs and spaces all over the place, this should be converted to use spaces. This is used by the official python style guide.
 +  - Submit a PR for the above changes, get review/​approval
 +  - Cleanup the python3 files
 +  - Make sure that the integration test runs properly
 +  - Submit a PR for the above changes, get review/​approval
 +
 +
 +
 +
 +
 +
 +
 +
 +
  • user/kluong/improvement_-_upgrade_gateway_code_from_python2_to_python3.1633584212.txt.gz
  • Last modified: 2021/10/07 05:23
  • by kluong