Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Python 3 for running emsdk #273

Merged
merged 2 commits into from Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion emsdk
@@ -1,4 +1,7 @@
#!/usr/bin/env python
#!/bin/sh
# Following line is responsible for selecting the best python for current host
# This script can be called directly: `./emsdk` or indirectly: `python ./emsdk` `sh ./emsdk` or `bash ./emsdk`
"exec" "`dirname $0`/python_selector" "$0" "$@"

from __future__ import print_function

Expand Down
29 changes: 29 additions & 0 deletions python_selector
@@ -0,0 +1,29 @@
#!/usr/bin/env python

# Copyright 2019 The Emscripten Authors. All rights reserved.
# Emscripten is available under two separate licenses, the MIT license and the
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.

"""Provides a way to run a script on the preferred Python version"""

import os
import subprocess
import sys


def which(program):
for path in [""] + os.environ.get("PATH", "").split(os.pathsep):
exe_file = os.path.join(path, program)
if os.path.isfile(exe_file) and os.access(exe_file, os.X_OK):
return exe_file
return None

# Look for the best choice for python, favours Python3 over Python2
# In case of Windows it uses always python that was used for this script
if sys.platform in ["linux", "linux2", "darwin"]:
python = which("python3") or which("python") or sys.executable
else:
python = sys.executable

sys.exit(subprocess.call([python] + sys.argv[1:]))