Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

make python code compatible with both python2 and python3 #3412

Merged
merged 16 commits into from
Dec 13, 2019

Conversation

nlu90
Copy link
Member

@nlu90 nlu90 commented Dec 4, 2019

Given the deadline for python3 migration is drawing near, we need to move all python related code to python3 now.

This PR uses the 2to3 tools to update all the python files.

@nlu90 nlu90 changed the title migrate to python3 using 2to3 cmd tool [WIP] migrate to python3 using 2to3 cmd tool Dec 4, 2019
@nwangtw
Copy link
Contributor

nwangtw commented Dec 4, 2019

There are a few syntax errors to fix

@nlu90
Copy link
Member Author

nlu90 commented Dec 4, 2019

There are a few syntax errors to fix

It seems some syntax error only reported undert python2's syntax checker.

$ find . -name "*.py" | xargs python -m py_compile
  File "./heron/tools/ui/src/python/main.py", line 190
    print('\n', end='')
                   ^
SyntaxError: invalid syntax

  File "./heron/tools/tracker/src/python/main.py", line 274
    print('\n', end='')
                   ^
SyntaxError: invalid syntax

  File "./heron/tools/cli/src/python/result.py", line 81
    print(msg, file=f)
                   ^
SyntaxError: invalid syntax

  File "./heron/statemgrs/src/python/statemanager.py", line 36
    class StateManager(metaclass=abc.ABCMeta):
                                ^
SyntaxError: invalid syntax

But with python3's syntax checker, those errors are gone.

# nlu @ tw-mbp-nlu in ~/workspace/heron on git:neng/py3-migration o [9:39:37] C:1
$ find . -name "*.py" | xargs python3 -m py_compile

# nlu @ tw-mbp-nlu in ~/workspace/heron on git:neng/py3-migration o [9:40:21]
$

@nwangtw
Copy link
Contributor

nwangtw commented Dec 6, 2019

Seems like cpplint is not compatible? Maybe try to upgrade it https://github.com/apache/incubator-heron/tree/master/third_party/python/cpplint

@nlu90
Copy link
Member Author

nlu90 commented Dec 6, 2019

Seems like cpplint is not compatible? Maybe try to upgrade it https://github.com/apache/incubator-heron/tree/master/third_party/python/cpplint

The original cpplint.py file is actually compatible with both 2 and 3 with a built-in rename hack. So most of the changes to it should be reverted.

@nlu90 nlu90 changed the title [WIP] migrate to python3 using 2to3 cmd tool [WIP] make python code compatible with both python2 and python3 Dec 6, 2019
import logging
import os
import signal
import urlparse
from urllib.parse import parse_qsl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is a package only valid in py3?

Copy link
Member Author

@nlu90 nlu90 Dec 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's available in python2 with the first two lines of this file

from future.standard_library import install_aliases
install_aliases()

@nlu90 nlu90 changed the title [WIP] make python code compatible with both python2 and python3 make python code compatible with both python2 and python3 Dec 13, 2019
@nlu90 nlu90 merged commit 869c82e into master Dec 13, 2019
sreev pushed a commit to sreev/incubator-heron that referenced this pull request Apr 9, 2020
nicknezis pushed a commit that referenced this pull request Sep 14, 2020
* make code compatible with both python2 and 3
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants