Skip to content

Commit c622582

Browse files
committed
Execute python scripts with the same interpreter
This reads the python interpreter’s path and executes any other scripts using the same interpreter. This way, mbed CLI is guaranteed to execute subscripts in `python2`, rather than the system default `python`.
1 parent 1bf1eaa commit c622582

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

mbed/mbed.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
# Default paths to Mercurial and Git
4343
hg_cmd = 'hg'
4444
git_cmd = 'git'
45+
python_cmd = sys.executable
4546

4647
ignores = [
4748
# Version control folders
@@ -2175,7 +2176,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
21752176
source = [os.path.relpath(program.path, orig_path)]
21762177

21772178
if supported:
2178-
popen(['python2', '-u', os.path.join(tools_dir, 'make.py')]
2179+
popen([python_cmd, '-u', os.path.join(tools_dir, 'make.py')]
21792180
+ (['-S'] if supported else []) + (['-v'] if very_verbose else [])
21802181
+ (['--app-config', app_config] if app_config else [])
21812182
+ args,
@@ -2188,7 +2189,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
21882189

21892190
if compile_config:
21902191
# Compile configuration
2191-
popen(['python2', os.path.join(tools_dir, 'get_config.py')]
2192+
popen([python_cmd, os.path.join(tools_dir, 'get_config.py')]
21922193
+ ['-t', tchain, '-m', target]
21932194
+ list(chain.from_iterable(izip(repeat('--profile'), profile or [])))
21942195
+ list(chain.from_iterable(izip(repeat('--source'), source)))
@@ -2207,7 +2208,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
22072208
if not build_path:
22082209
build_path = os.path.join(os.path.relpath(program.path, orig_path), program.build_dir, 'libraries', os.path.basename(orig_path), target, tchain)
22092210

2210-
popen(['python2', '-u', os.path.join(tools_dir, 'build.py')]
2211+
popen([python_cmd, '-u', os.path.join(tools_dir, 'build.py')]
22112212
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
22122213
+ ['-t', tchain, '-m', target]
22132214
+ list(chain.from_iterable(izip(repeat('--profile'), profile or [])))
@@ -2223,7 +2224,7 @@ def compile_(toolchain=None, target=None, profile=False, compile_library=False,
22232224
if not build_path:
22242225
build_path = os.path.join(os.path.relpath(program.path, orig_path), program.build_dir, target, tchain)
22252226

2226-
popen(['python2', '-u', os.path.join(tools_dir, 'make.py')]
2227+
popen([python_cmd, '-u', os.path.join(tools_dir, 'make.py')]
22272228
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
22282229
+ ['-t', tchain, '-m', target]
22292230
+ list(chain.from_iterable(izip(repeat('--profile'), profile or [])))
@@ -2292,7 +2293,7 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
22922293
test_spec = os.path.join(build_path, 'test_spec.json')
22932294

22942295
if compile_list:
2295-
popen(['python2', '-u', os.path.join(tools_dir, 'test.py'), '--list']
2296+
popen([python_cmd, '-u', os.path.join(tools_dir, 'test.py'), '--list']
22962297
+ list(chain.from_iterable(izip(repeat('--profile'), profile or [])))
22972298
+ ['-t', tchain, '-m', target]
22982299
+ list(chain.from_iterable(izip(repeat('--source'), source)))
@@ -2307,7 +2308,7 @@ def test_(toolchain=None, target=None, compile_list=False, run_list=False, compi
23072308
if not build:
23082309
program.ignore_build_dir()
23092310

2310-
popen(['python2', '-u', os.path.join(tools_dir, 'test.py')]
2311+
popen([python_cmd, '-u', os.path.join(tools_dir, 'test.py')]
23112312
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
23122313
+ list(chain.from_iterable(izip(repeat('--profile'), profile or [])))
23132314
+ ['-t', tchain, '-m', target]
@@ -2364,7 +2365,7 @@ def export(ide=None, target=None, source=False, clean=False, supported=False):
23642365
env = program.get_env()
23652366

23662367
if supported:
2367-
popen(['python2', '-u', os.path.join(tools_dir, 'project.py')]
2368+
popen([python_cmd, '-u', os.path.join(tools_dir, 'project.py')]
23682369
+ (['-S'] if supported else []) + (['-v'] if very_verbose else []),
23692370
env=env)
23702371
return
@@ -2380,7 +2381,7 @@ def export(ide=None, target=None, source=False, clean=False, supported=False):
23802381

23812382
program.ignore_build_dir()
23822383

2383-
popen(['python2', '-u', os.path.join(tools_dir, 'project.py')]
2384+
popen([python_cmd, '-u', os.path.join(tools_dir, 'project.py')]
23842385
+ list(chain.from_iterable(izip(repeat('-D'), macros)))
23852386
+ ['-i', ide.lower()]
23862387
+ ['-m', target]
@@ -2412,7 +2413,7 @@ def detect():
24122413
# Prepare environment variables
24132414
env = program.get_env()
24142415

2415-
popen(['python2', '-u', os.path.join(tools_dir, 'detect_targets.py')]
2416+
popen([python_cmd, '-u', os.path.join(tools_dir, 'detect_targets.py')]
24162417
+ args,
24172418
env=env)
24182419
else:

0 commit comments

Comments
 (0)