Skip to content

Commit 0a10b42

Browse files
committed
make the code run on both python 2 and 3
1 parent 1f4ca0b commit 0a10b42

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
SUITE_SULONG = mx.suite("sulong")
5151

5252

53+
# compatibility between Python versions
54+
PY3 = sys.version_info[0] == 3
55+
if PY3:
56+
raw_input = input
57+
58+
5359
def _get_core_home():
5460
return os.path.join(SUITE.dir, "graalpython", "lib-graalpython")
5561

@@ -854,7 +860,7 @@ def import_python_sources(args):
854860
855861
7. Run the tests and fix any remaining issues.
856862
""".format(mapping))
857-
input("Got it?")
863+
raw_input("Got it?")
858864

859865
cpy_files = []
860866
pypy_files = []
@@ -918,9 +924,9 @@ def import_python_sources(args):
918924

919925
# commit and check back
920926
SUITE.vc.git_command(SUITE.dir, ["add", "."])
921-
input("Check that the updated files look as intended, then press RETURN...")
927+
raw_input("Check that the updated files look as intended, then press RETURN...")
922928
SUITE.vc.commit(SUITE.dir, "Update Python inlined files: %s" % import_version)
923-
answer = input("Should we push python-import (y/N)? ")
929+
answer = raw_input("Should we push python-import (y/N)? ")
924930
if answer and answer in "Yy":
925931
SUITE.vc.git_command(SUITE.dir, ["push", "origin", "python-import:python-import"])
926932
SUITE.vc.update(SUITE.dir, rev=tip)

mx.graalpython/mx_graalpython_benchmark.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ def is_sandboxed_configuration(conf):
7979
return conf == CONFIGURATION_SANDBOXED or conf == CONFIGURATION_SANDBOXED_MULTI
8080

8181

82+
# from six
83+
def add_metaclass(metaclass):
84+
"""Class decorator for creating a class with a metaclass."""
85+
def wrapper(cls):
86+
orig_vars = cls.__dict__.copy()
87+
slots = orig_vars.get('__slots__')
88+
if slots is not None:
89+
if isinstance(slots, str):
90+
slots = [slots]
91+
for slots_var in slots:
92+
orig_vars.pop(slots_var)
93+
orig_vars.pop('__dict__', None)
94+
orig_vars.pop('__weakref__', None)
95+
if hasattr(cls, '__qualname__'):
96+
orig_vars['__qualname__'] = cls.__qualname__
97+
return metaclass(cls.__name__, cls.__bases__, orig_vars)
98+
return wrapper
99+
100+
82101
@contextmanager
83102
def environ(env):
84103
def _handle_var(key_value):
@@ -106,7 +125,8 @@ def _handle_var(key_value):
106125
# the vm definitions
107126
#
108127
# ----------------------------------------------------------------------------------------------------------------------
109-
class AbstractPythonVm(Vm, metaclass=ABCMeta):
128+
@add_metaclass(ABCMeta)
129+
class AbstractPythonVm(Vm):
110130
def __init__(self, config_name, options=None, env=None):
111131
super(AbstractPythonVm, self).__init__()
112132
self._config_name = config_name
@@ -154,7 +174,8 @@ def run(self, cwd, args):
154174
return ret_code, out.data
155175

156176

157-
class AbstractPythonIterationsControlVm(AbstractPythonVm, metaclass=ABCMeta):
177+
@add_metaclass(ABCMeta)
178+
class AbstractPythonIterationsControlVm(AbstractPythonVm):
158179
def __init__(self, config_name, options=None, env=None, iterations=None):
159180
super(AbstractPythonIterationsControlVm, self).__init__(config_name, options=options, env=env)
160181
try:

0 commit comments

Comments
 (0)