Skip to content

Commit edab8a5

Browse files
committed
[GR-69444] Fix looking up CPython for benchmarks
PullRequest: graalpython/3987
2 parents 01e7d58 + 5bd2fa7 commit edab8a5

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

mx.graalpython/mx_graalpython_benchmark.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
# OF THE POSSIBILITY OF SUCH DAMAGE.
2424
from __future__ import print_function
2525

26-
import itertools
2726
import functools
27+
import shutil
2828
import statistics
2929
import sys
3030
import os
@@ -200,23 +200,19 @@ def override_iterations(self, requested_iterations):
200200

201201
@property
202202
def interpreter(self):
203-
candidates_pre = [
204-
self._virtualenv,
205-
mx.get_env("VIRTUAL_ENV"),
206-
mx.get_env("PYTHON3_HOME"),
207-
]
208-
candidates_suf = [
209-
join("bin", "python3"),
210-
join("bin", "python"),
211-
"python3",
212-
"python",
213-
sys.executable,
214-
]
215-
for p, s in itertools.product(candidates_pre, candidates_suf):
216-
if os.path.exists(exe := os.path.join(p or "", s)):
217-
mx.log(f"CPython VM {exe=}")
218-
return exe
219-
assert False, "sys.executable should really exist"
203+
if venv := self._virtualenv:
204+
path = os.path.join(venv, 'bin', 'python')
205+
mx.log(f"Using CPython from virtualenv: {path}")
206+
elif python3_home := mx.get_env('PYTHON3_HOME'):
207+
path = os.path.join(python3_home, 'python')
208+
mx.log(f"Using CPython from PYTHON3_HOME: {path}")
209+
elif path := shutil.which('python'):
210+
mx.log(f"Using CPython from PATH: {path}")
211+
else:
212+
assert sys.implementation.name == 'cpython', "Cannot find CPython"
213+
path = sys.executable
214+
mx.log(f"Using CPython from sys.executable: {path}")
215+
return path
220216

221217
def run_vm(self, args, *splat, **kwargs):
222218
for idx, arg in enumerate(args):

0 commit comments

Comments
 (0)