-
Notifications
You must be signed in to change notification settings - Fork 119
Python 3 Support #184
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 Support #184
Conversation
|
Well, I've been testing on Windows and the Doug sent me a patch for that, but I haven't integrated it into this PR yet because it's not my code. So, just be aware that travis is not actually testing with python 3.6 yet; https://travis-ci.org/graalvm/mx/jobs/472104216#L638 |
90b89ea to
2ed1ba8
Compare
|
@dougxc That should be it. |
|
FWIW I have uploaded a patch that adds (at least partial) python 3 support to the graal/compiler suite: https://github.com/JornVernee/graal/tree/p3_compiler On Windows I can run gate on python 3.6 until hitting oracle/graal#833 Maybe you could use that patch to test with as well. |
|
Thanks @JornVernee . I have the internal merge ready to go and it should be pushed today. |
|
Hi @JornVernee , discussing this offline with colleagues, we're opting to build on your PR and extend it further in the direction of promoting pure Python 3 code. That is, we want to end up with mx and all downstream suites containing only Python 3 code. This means using only Python 3 module and functions everywhere and having only a Python 2 portability layer. Portability imports and definitions would be guarded by Given the solid start you've provided in this PR means this should not take me too long to complete. |
|
Hi @dougxc What will that mean for this PR? Will it still be merged? |
|
Yes, this PR will be merged. |
|
@dougxc FWIW, I ran gate again after pulling master and it seems that you forgot to add I see ci.jsonnet is still using pylint 1.1.0. It was not working for me when running on python 3.6 (that's why I made the pylint patch). I guess the ci is using an earlier version of python 3? |
|
Sorry for the missing and badly formatted pylint suppression comments. I'll apply your patch. Can you help with that? |
|
I've now installed pylint 1.9.3 on python2 and it works fine so please ignore the above. |
|
@dougxc It looks like you're using python 3.7: pylint 1.9.3 seems to be the sweet spot for python 2.7 and 3.6, since 1.9.3 is the last version that is supported on python 2. But, afaik python 3.7 requires a later version of pylint to work. I have gotten it working with 2.2.2 which is the latest version of pylint. After the pylint PR, support for other pylint versions should be easy to add; just look for diff --git a/mx.py b/mx.py
index e80319e..25cc612 100755
--- a/mx.py
+++ b/mx.py
@@ -13035,6 +13035,10 @@ pylint_ver_map = {
(1, 9): {
'rcfile': '.pylintrc19',
'additional_options': ['--score=n']
+ },
+ (2, 2): {
+ 'rcfile': '.pylintrc22',
+ 'additional_options': ['--score=n']
}
}
The above depends on the presence of a I didn't add this to the initial PR to keep it simple in the hope of moving things along. (in hindsight it was probably a better idea to add it right away) |
|
I've added support for pylint 2.2 and applied some of the other small fixes you provided: 0b4566a |
Cool, thanks! 👍 |
(Remaking this as one big PR after being requested to per email)
This PR adds python 3 support to mx. It has been tested by running
mx --strict-compliance gate --strict-modeon python 2.7.15 and python 3.6.5, both using pylint 1.9.3 (needed for 3.6). So, this PR depends on my pylint PR; #176 . This PR also definitively drops support for python 2.6 (if it was still working).The cornerstone of this PR is the new
mx_portablefile. Because there are some modules, functions and types that are not available on both python 2 & 3, this module detects the python version and imports the right thing for that version, exposing it under a common, portable name. Then other mx modules can import that portable name from themx_portablemodule [1].The changes made by this PR are;
as.dict.iterkeys(),dict.itervalues()anddict.iteritems()todict.keys(),dict.values()anddict.items(). This slightly changes the behaviour from returning an iterator to returning a list on python 2, and on python 3 these methods return a dictionary 'view'. But, the important part is that the names are portable (theiter*behaviour just doesn't exist in python 3).StringIO,urllib2and__builtins__, these have been exposed under portable names by themx_portablefile [1].basestring,unicodeandlong, these have also been exposed under a more portable name throughmx_portable[1].itertools.ifilter,cmp,raw_input,function.func_codeanddict.viewkeys. I've made portable alternatives for all of them throughmx_portable[1].typesmodule no longer contains the builtin types, instead their builtin names are used. e.g.types.DictType->dict.dict.has_key, but we can use theinkeyword instead, so I've made that switch everywhere.OrderedDict.keys()is no longer indexable, This was a problem in two cases. For the case where the first element element was needed I'm creating an iterator and returning the first element. For the case where actual indexing is needed, I'm converting thekeys()return to alistfirst.__cmp__function, and instead wants developers to implement every comparison operator separately. I've added backwards compatibility by creating aComparableclass which implements the comparison operators in terms of__cmp__. Then I had the classes using__cmp__inherit from thisComparableclass. This was mostly used for sorting dependencies, and I did find out that in some cases the sorting falls back on identity comparison, which doesn't seem very robust, but I've tried to retain that behaviour as well._py3_decodeand_py3_encodefunctions tomx_portable[1] to conditionally go between the 2 encodings, as well as a special version ofsubprocess.check_outputwhich decodes it's return value into a string. In some other cases I just changed whether a file was opened in text or binary mode.I've also made
gateoutput the python version being run, and added a travis job for testing under python 3.6There's a lot of commits right now, and I can try to trim it down some if needed, but I'd rather do that after the review process in case changes need to be made.
[1] : https://github.com/JornVernee/mx/blob/94744aee36e4ae41fbe310f0fb157439cf5f0936/mx_portable.py