-
Notifications
You must be signed in to change notification settings - Fork 61
Python 3 Upgrade #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python 3 Upgrade #160
Conversation
I have looked through the stage 1 fixes applied by futurize and they LGTM, mostly very safe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested Tango by grading various assignments through Autolab, and it works as expected.
Overall the changes looks good, and I think this is a good patch (and improvement).
Some minor issues should be addressed before merging, but other than that it should be okay!
preallocator.py
Outdated
@@ -29,7 +31,7 @@ def __init__(self, vmms): | |||
def poolSize(self, vmName): | |||
""" poolSize - returns the size of the vmName pool, for external callers | |||
""" | |||
if vmName not in self.machines.keys(): | |||
if vmName not in list(self.machines.keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment with regards to the key situation in jobqueue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.machines here is also either a TangoNativeDictionary or TangoRemoteDictionary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refer to comment below
@victorhuangwq Thanks for your comments! I've rectified the issues you raised, do look at it again when you're available :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still some issues with regards to the usage of TangoRemoteDictionary. Other than that it looks good.
return self.dict[str(id)] | ||
else: | ||
return None | ||
|
||
def keys(self): | ||
return self.dict.keys() | ||
return list(self.dict.keys()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't it return a list here?
Wouldn't calling list again on keys() be redundant in the other lines I have highlighted above? Such as in
if vmName not in list(self.machines.keys()):
unpickled_obj = self.r.hget(self.hash_name, str(id)) | ||
obj = pickle.loads(unpickled_obj) | ||
return obj | ||
else: | ||
return None | ||
|
||
def keys(self): | ||
return self.r.hkeys(self.hash_name) | ||
keys = map(lambda key : key.decode(), self.r.hkeys(self.hash_name)) | ||
return list(keys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be returning a list when keys are called on the TangoRemoteDictionary.
preallocator.py
Outdated
@@ -29,7 +31,7 @@ def __init__(self, vmms): | |||
def poolSize(self, vmName): | |||
""" poolSize - returns the size of the vmName pool, for external callers | |||
""" | |||
if vmName not in self.machines.keys(): | |||
if vmName not in list(self.machines.keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refer to comment below
This should not block the upgrade, since I believe the current code to be correct, but most if not all of the keys() calls in the code do not require the list form of the keys (you only need to listify the keys if you either want to use [] to access elements of the key list, or if you will alter the dict while iterating over the keys). Furthermore, a more readable way to do would be to implement
instead. TangoRemoteDictionary could use HEXISTS to implement |
jobManager.py
Outdated
@@ -117,7 +129,7 @@ def __manage(self): | |||
tango = TangoServer() | |||
tango.log.debug("Resetting Tango VMs") | |||
tango.resetTango(tango.preallocator.vmms) | |||
for key in tango.preallocator.machines.keys(): | |||
for key in list(tango.preallocator.machines.keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another unnecessary list()
preallocator.py
Outdated
@@ -44,7 +46,7 @@ def update(self, vm, num): | |||
of machines as necessary. | |||
""" | |||
self.lock.acquire() | |||
if vm.name not in self.machines.keys(): | |||
if vm.name not in list(self.machines.keys()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another unnecessary list()
@cg2v This is a great suggestion, I will add it as a future enhancement instead of adding that to this PR to avoid making this PR bigger than it already is. Thank you and really appreciate the spotting of other redundant wrappers of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing: Tested Tango3 branch by grading various assignments through Autolab, and it works as expected.
I have verified that:
- Patch from Autograding. Error message: 795: unexpected token at '---' #153 has been applied
- Unnecessary lists, as mentioned by both @cg2v and I, has been removed
- Dockerfile is now back on 18.04 (change removed)
This pull request LGTM :)
@fanpu Before you merge in however, please create an alternate Python 2 branch, preferably called At the same time, here are the list of things we should also do alongside this PR. I can help with it as well.
|
I will draft a new release after I merge this to master. I think other TODO items would include update installation instructions on our docs too. |
Plan:
Unfortunately, we have almost no test coverage so regressions must be detected by hand. Our goal is to port Tango to Python 3 while still maintaining Python 2 compatibility.
Tested with all CLI commands given in https://autolab.github.io/docs/tango-cli/
This is now ready for review!