Skip to content

Commit b6d6e10

Browse files
committed
don't just globally set GRAAL_PYTHONHOME
1 parent 165a7ba commit b6d6e10

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def do_run_python(args, extra_vm_args=None, env=None, jdk=None, **kwargs):
116116
args.insert(0, "--python.CAPI=%s" % capi_home)
117117

118118
if not env:
119-
env = os.environ
119+
env = os.environ.copy()
120+
env.setdefault("GRAAL_PYTHONHOME", _dev_pythonhome())
120121

121122
check_vm_env = env.get('GRAALPYTHON_MUST_USE_GRAAL', False)
122123
if check_vm_env:
@@ -163,14 +164,27 @@ def do_run_python(args, extra_vm_args=None, env=None, jdk=None, **kwargs):
163164
return mx.run_java(vm_args + graalpython_args, jdk=jdk, env=env, **kwargs)
164165

165166

167+
def _pythonhome_context():
168+
return set_env(GRAAL_PYTHONHOME=mx.dependency("GRAALPYTHON_GRAALVM_SUPPORT").get_output())
169+
170+
171+
def _dev_pythonhome_context():
172+
home = os.environ.get("GRAAL_PYTHONHOME", _dev_pythonhome())
173+
return set_env(GRAAL_PYTHONHOME=home)
174+
175+
176+
def _dev_pythonhome():
177+
return os.path.join(SUITE.dir, "graalpython")
178+
179+
166180
def punittest(ars):
167181
if '--regex' not in ars:
168182
args = ['--regex', r'(graal\.python)|(com\.oracle\.truffle\.tck\.tests)']
169183
args += ["-Dgraal.TruffleCompilationExceptionsAreFatal=false",
170184
"-Dgraal.TruffleCompilationExceptionsArePrinted=true",
171185
"-Dgraal.TrufflePerformanceWarningsAreFatal=false"]
172186
args += ars
173-
with set_env(GRAAL_PYTHONHOME=mx.dependency("GRAALPYTHON_GRAALVM_SUPPORT").get_output()):
187+
with _pythonhome_context():
174188
mx_unittest.unittest(args)
175189

176190

@@ -190,7 +204,7 @@ def nativeclean(args):
190204

191205
def python3_unittests(args):
192206
"""run the cPython stdlib unittests"""
193-
mx.run(["python3", "graalpython/com.oracle.graal.python.test/src/python_unittests.py", "-v"] + args)
207+
python(["graalpython/com.oracle.graal.python.test/src/python_unittests.py", "-v"] + args)
194208

195209

196210
def retag_unittests(args):
@@ -619,7 +633,7 @@ def run_shared_lib_test(args=None):
619633
mx.log("Running " + progname + " with LD_LIBRARY_PATH " + svm_lib_path)
620634
mx.run(["ls", "-l", progname])
621635
mx.run(["ls", "-l", svm_lib_path])
622-
run_env = {"LD_LIBRARY_PATH": svm_lib_path, "GRAAL_PYTHONHOME": os.environ["GRAAL_PYTHONHOME"]}
636+
run_env = {"LD_LIBRARY_PATH": svm_lib_path, "GRAAL_PYTHONHOME": _dev_pythonhome()}
623637
mx.log(repr(run_env))
624638
mx.run([progname], env=run_env)
625639
finally:
@@ -1011,18 +1025,6 @@ def verify_ci(dest_suite, common_ci_dir="ci_common", args=None, ext=('.jsonnet',
10111025
))
10121026

10131027

1014-
# ----------------------------------------------------------------------------------------------------------------------
1015-
#
1016-
# set our GRAAL_PYTHONHOME if not already set
1017-
#
1018-
# ----------------------------------------------------------------------------------------------------------------------
1019-
if not os.getenv("GRAAL_PYTHONHOME"):
1020-
home = os.path.join(SUITE.dir, "graalpython")
1021-
if not os.path.exists(home):
1022-
home = [d for d in SUITE.dists if d.name == "GRAALPYTHON_GRAALVM_SUPPORT"][0].output
1023-
os.environ["GRAAL_PYTHONHOME"] = home
1024-
1025-
10261028
# ----------------------------------------------------------------------------------------------------------------------
10271029
#
10281030
# post init
@@ -1144,7 +1146,7 @@ def __init__(self, args, project):
11441146
def __str__(self):
11451147
return 'Building C API project {} with setuptools'.format(self.subject.name)
11461148

1147-
def run(self, args, env, cwd):
1149+
def run(self, args, env=None, cwd=None):
11481150
return do_run_python(args, env=env, cwd=cwd)
11491151

11501152
def _dev_headers_dir(self):
@@ -1168,7 +1170,6 @@ def build(self):
11681170
# importlib PathFinder initializes it's directory finders
11691171
mx.ensure_dir_exists(os.path.join(self.subject.get_output_root(), "modules"))
11701172

1171-
env = os.environ.copy()
11721173
cwd = os.path.join(self.subject.get_output_root(), "mxbuild_temp")
11731174
args = []
11741175
if mx._opts.verbose:
@@ -1177,7 +1178,7 @@ def build(self):
11771178
args.append("-q")
11781179
args += ["-S", os.path.join(self.src_dir(), "setup.py"), self.subject.get_output_root()]
11791180
mx.ensure_dir_exists(cwd)
1180-
rc = self.run(args, env=env, cwd=cwd)
1181+
rc = self.run(args, cwd=cwd)
11811182
shutil.rmtree(cwd) # remove the temporary build files
11821183
return min(rc, 1)
11831184

0 commit comments

Comments
 (0)