-
Notifications
You must be signed in to change notification settings - Fork 17
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
Pr15 split part3 #18
Pr15 split part3 #18
Conversation
The first patch ( However, the second patch is definitely not Py2-safe, so we can't take it in that form. See: https://python-future.org/compatible_idioms.html#urllib-module Judging by the three of those, I'd suggest using the python-future option for compatibility, as that's available in xs8 & xs9, and just a small change (again) in terms of imports. |
XSConsoleRemoteTest.py
Outdated
@@ -13,27 +13,27 @@ | |||
# with this program; if not, write to the Free Software Foundation, Inc., | |||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |||
|
|||
import os, socket, xmlrpclib | |||
import os, socket, xmlrpc.client |
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.
import os, socket, xmlrpc.client | |
import os | |
import socket |
See my 2nd requested change below, Andrew's comment and my change request for context.
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.
With reference to Andrew's comment and with consideration that future is not maintained anymore and is broken in Python3.12, please use the two hunks I suggested instead of the 2nd commit, which also make the changes considerably smaller.
XSConsoleRemoteTest.py
Outdated
import socketserver | ||
import xmlrpc.server |
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.
import socketserver | |
import xmlrpc.server | |
try: | |
import xmlrpclib | |
import SocketServer | |
import SimpleXMLRPCServer | |
except: | |
import xmlrpc.client as xmlrpclib | |
import socketserver as SocketServer | |
import xmlrpc.server as SimpleXMLRPCServer |
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.
I advocate for this simple solution to replace this entire commit with these two hunks.
The main reason is that the the python-future module became unmaintained and projects are already forced to drop their use of python-future because of this when they want to support Python 3.12. One Example:
https://github.com/gkovacs/lz-string-python/pull/6/files
A fixup for this particular issue of future using import imp
which has been dropped has been submitted 3 weeks ago, but the maintainers of future have gone missing in January, which is now 9 months without any commit or merge.
The deprecation warning for the removal of imp
was added starting from release of 3.7.
3.10 announced will be removed by 3.12:
# python3.10 -Wdefault -c 'from future import standard_library;standard_library.install_aliases()'
/usr/lib/python3/dist-packages/future/standard_library/__init__.py:65:
DeprecationWarning:
the imp module is deprecated in favour of importlib and slated for removal in Python 3.12;
see the module's documentation for alternative uses
import imp
Python 3.12 did follow thru and removed imp
:
# python3.12 -c 'from future import standard_library;standard_library.install_aliases()'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3/dist-packages/future/standard_library/__init__.py", line 65, in <module>
import imp
ModuleNotFoundError: No module named 'imp'
Therefore, just use the simple try: import method and no change to the actual code.
That's fully in line with Andrew's demand for Python2 compat and it avoids having dependency on no longer maintained packages (there is also six.moves, but that also is a not needed dependency which can become unmaintained). Besides, when pylint would used (may be good when developing new code), two pylint warnings would have to be disabled, because installing the aliases would have to be put on top, violating the import order:
# pylint: disable=wrong-import-position,wrong-import-order
from future import standard_library
standard_library.install_aliases()
Lovely... I'll defer to your suggestion for how best to do this. |
Again, I want to highlight, The only usage of py2 of XSConsole is for Yangtze, which will be EoL in 2025. On the other side, to make master compatible for py2, we make the code unnecessary complicated. |
Hmm, on second thoughts, you're right. There's no dependency of xsconsole that's going to need it to stay py2 compatible, and we're not going to be backporting anything but critical fixes to ytz. (Need to double check the way branches are handled in the spec repo, but I expect that will be fine.) So, new plan, move for Py3.6 baseline. However, So, please can we collect together all commits which are py2-safe fixes, which can get reviewed and merged freely, and please keep all commits which break compatibility with py2 in a separate single PR so it can be merged all in one go. The final commit on the py3 branch should bump the major version number of xsconsole seeing as its a bit step change. Sound ok? |
Sounds a good and reasonable plan for me @qinzhang22 your thoughts? |
By default, file objectes are opened in binary mode in python3. With universal_newlines=True, the file objects stdin, stdout and stderr will be opened in text mode. And it is provided for backwards compatibility. Signed-off-by: Qin Zhang (张琴) <qin.zhang@citrix.com>
|
64153bc
to
7514fde
Compare
I updated the PR per our agreement that collecting together all commits which are py2-safe fixes. Hopefully it can be reviewed and merged freely. |
Signed-off-by: Qin Zhang (张琴) <qin.zhang@citrix.com>
Signed-off-by: Qin Zhang (张琴) <qin.zhang@citrix.com>
Signed-off-by: Qin Zhang (张琴) <qin.zhang@citrix.com>
7514fde
to
0cb382b
Compare
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.
Everything else LGTM.
@@ -112,7 +112,7 @@ def MenuRegenerator(cls, inList, inMenu): | |||
srList = [ sr for sr in HotAccessor().visible_sr if sr.other_config({}).get('xensource_internal', '') != 'true' ] | |||
|
|||
# Sort list by SR shared flag then name | |||
srList.sort(lambda x, y: cmp(y.shared(False), x.shared(False)) or cmp (x.name_label(''), y.name_label())) | |||
srList.sort(key=lambda sr: (-sr.shared(False), sr.name_label(''))) |
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.
is -sr
right here?
Personally, I think the logic would be easier to follow as
# Sort list by SR shared flag then name
srList.sort(key=lambda sr: sr.name_label(''))
srList.sort(key=lambda sr: sr.shared(False))
maybe with a reverse=True
in the second line if I've interpreted the intent of the negation properly ?
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.
Alternatively, srList.sort(key=lambda sr: (not sr.shared(False), sr.name_label('')))
might be better ? At least it makes clear that the first part of the tuple is supposed to be a boolean.
As a tangent, passing the default-if-missing value in makes this code horrible to read and follow. Do you happen to know if this is a local artifact, or a property of the API?
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.
is -sr right here?
Yes, it is correct. The 1st half of the original cmp(y.shared(False), x.shared(False))
had y and x reversed, so the primary sort order is reversed.
Splitting the nested sort into two consecutive sorts would make the result reliant of the sort algorithm chosen by the Python interpreter for the given data and I'd like the result to be kept clearly defined as a nested sort with two sort keys. Therefore, I see the change is correct!
Because the sort is already commented using a meaningful comment, the sort does not need further explanation:
# Sort list by SR shared flag then name
srList.sort(key=lambda sr: (-sr.shared(False), sr.name_label('')))
Even though the comment says that sr.shared(False)
returns a flag, nothing here ensures that it will always return a boolean. In principle, it could return anything (numbers, floats or a mix of all that). Therefore I think keeping -sr.shared(False)
is the safe thing to do (does not change the behavior at all) and it's clear that -
means negation.
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.
Reviewed the changes and checked the sort lambdas.
@@ -112,7 +112,7 @@ def MenuRegenerator(cls, inList, inMenu): | |||
srList = [ sr for sr in HotAccessor().visible_sr if sr.other_config({}).get('xensource_internal', '') != 'true' ] | |||
|
|||
# Sort list by SR shared flag then name | |||
srList.sort(lambda x, y: cmp(y.shared(False), x.shared(False)) or cmp (x.name_label(''), y.name_label())) | |||
srList.sort(key=lambda sr: (-sr.shared(False), sr.name_label(''))) |
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.
is -sr right here?
Yes, it is correct. The 1st half of the original cmp(y.shared(False), x.shared(False))
had y and x reversed, so the primary sort order is reversed.
Splitting the nested sort into two consecutive sorts would make the result reliant of the sort algorithm chosen by the Python interpreter for the given data and I'd like the result to be kept clearly defined as a nested sort with two sort keys. Therefore, I see the change is correct!
Because the sort is already commented using a meaningful comment, the sort does not need further explanation:
# Sort list by SR shared flag then name
srList.sort(key=lambda sr: (-sr.shared(False), sr.name_label('')))
Even though the comment says that sr.shared(False)
returns a flag, nothing here ensures that it will always return a boolean. In principle, it could return anything (numbers, floats or a mix of all that). Therefore I think keeping -sr.shared(False)
is the safe thing to do (does not change the behavior at all) and it's clear that -
means negation.
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.
Approve basing on my review, and the discussion.
Note by Bernhard: As per the agreement with Andrew in xapi-project#18, we shall keep master py2-compatible and py3-only changes go to a py3 branch: Andrew wrote: > However, master needs to remain atomically py2 or py3 compatible, > and not a mix of fixes which leaves it broken in both. [...] > please keep all commits which break compatibility with py2 in a > separate single PR so it can be merged all in one go. > The final commit on the py3 branch should [...] Reference: xapi-project#18 (comment) Therefore, I'll squash this commit with the next commit for fixing it up keep master py2-compatible, at least until all py3 checks and a complete manual test was done by QA. Original commit message by Qin Zhang (张琴): Remove the use of 'encode' as it's used to turn a Unicode string into a regular string in Python2 Final Remarks by Bernhard, for completeleness: - This commit also adds conversion from curses input bytes to str. - Rebased to apply on the current master branch. Co-authored-by: Bernhard Kaindl <bernhard.kaindl@cloud.com> Signed-off-by: Qin Zhang (张琴) <qin.zhang@citrix.com>
Note by Bernhard: As per the agreement with Andrew in xapi-project#18, we shall keep master py2-compatible and py3-only changes go to a py3 branch: Andrew wrote: > However, master needs to remain atomically py2 or py3 compatible, > and not a mix of fixes which leaves it broken in both. [...] > please keep all commits which break compatibility with py2 in a > separate single PR so it can be merged all in one go. > The final commit on the py3 branch should [...] Reference: xapi-project#18 (comment) Therefore, I'll squash this commit with the next commit for fixing it up keep master py2-compatible, at least until all py3 checks and a complete manual test was done by QA. Original commit message by Qin Zhang (张琴): Remove the use of 'encode' as it's used to turn a Unicode string into a regular string in Python2 Final Remarks by Bernhard, for completeleness: - This commit also adds conversion from curses input bytes to str. - Rebased to apply on the current master branch. Co-authored-by: Bernhard Kaindl <bernhard.kaindl@cloud.com> Signed-off-by: Qin Zhang (张琴) <qin.zhang@citrix.com>
Note by Bernhard: As per the agreement with Andrew in xapi-project#18, we shall keep master py2-compatible and py3-only changes go to a py3 branch: Andrew wrote: > However, master needs to remain atomically py2 or py3 compatible, > and not a mix of fixes which leaves it broken in both. [...] > please keep all commits which break compatibility with py2 in a > separate single PR so it can be merged all in one go. > The final commit on the py3 branch should [...] Reference: xapi-project#18 (comment) Therefore, I'll squash this commit with the next commit for fixing it up keep master py2-compatible, at least until all py3 checks and a complete manual test was done by QA. Original commit message by Qin Zhang (张琴): Remove the use of 'encode' as it's used to turn a Unicode string into a regular string in Python2 Final Remarks by Bernhard, for completeleness: - This commit also adds conversion from curses input bytes to str. - Rebased to apply on the current master branch. Co-authored-by: Bernhard Kaindl <bernhard.kaindl@cloud.com> Signed-off-by: Qin Zhang (张琴) <qin.zhang@citrix.com>
Note by Bernhard: As per the agreement with Andrew in #18, we shall keep master py2-compatible and py3-only changes go to a py3 branch: Andrew wrote: > However, master needs to remain atomically py2 or py3 compatible, > and not a mix of fixes which leaves it broken in both. [...] > please keep all commits which break compatibility with py2 in a > separate single PR so it can be merged all in one go. > The final commit on the py3 branch should [...] Reference: #18 (comment) Therefore, I'll squash this commit with the next commit for fixing it up keep master py2-compatible, at least until all py3 checks and a complete manual test was done by QA. Original commit message by Qin Zhang (张琴): Remove the use of 'encode' as it's used to turn a Unicode string into a regular string in Python2 Final Remarks by Bernhard, for completeleness: - This commit also adds conversion from curses input bytes to str. - Rebased to apply on the current master branch. Co-authored-by: Bernhard Kaindl <bernhard.kaindl@cloud.com> Signed-off-by: Qin Zhang (张琴) <qin.zhang@citrix.com>
This is removing the use 'file' and updating 'xmlrpc, socketserver, urllib' syntax for python3. For this part, we didn't consider python2 compatibility considering it will make code complicated.