|
23 | 23 | # OF THE POSSIBILITY OF SUCH DAMAGE.
|
24 | 24 | from __future__ import print_function
|
25 | 25 |
|
26 |
| -import itertools |
27 | 26 | import functools
|
| 27 | +import shutil |
28 | 28 | import statistics
|
29 | 29 | import sys
|
30 | 30 | import os
|
@@ -200,23 +200,19 @@ def override_iterations(self, requested_iterations):
|
200 | 200 |
|
201 | 201 | @property
|
202 | 202 | 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 |
220 | 216 |
|
221 | 217 | def run_vm(self, args, *splat, **kwargs):
|
222 | 218 | for idx, arg in enumerate(args):
|
|
0 commit comments