Skip to content

Commit

Permalink
Copy fix_python_path() in more standalone files.
Browse files Browse the repository at this point in the history
This script ensure that the current python is prepended on any python script
invoked and that 'python' is replaced with the current python instance and not
the system one.

NOTRY=true
TBR=csharp@chromium.org
BUG=
TEST=


Review URL: https://chromiumcodereview.appspot.com/10449089

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139801 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
maruel@chromium.org committed May 31, 2012
1 parent c616499 commit 4bf4d63
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 11 additions & 2 deletions testing/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


def fix_python_path(cmd):
"""Returns the fixed command line to call the right python executable."""
out = cmd[:]
if out[0] == 'python':
out[0] = sys.executable
elif out[0].endswith('.py'):
out.insert(0, sys.executable)
return out


def run_executable(cmd, env):
"""Runs an executable with:
- environment variable CR_SOURCE_ROOT set to the root directory.
Expand All @@ -25,8 +35,7 @@ def run_executable(cmd, env):
env['CR_SOURCE_ROOT'] = os.path.abspath(ROOT_DIR).encode('utf-8')
# Ensure paths are correctly separated on windows.
cmd[0] = cmd[0].replace('/', os.path.sep)
if cmd[0].endswith('.py'):
cmd.insert(0, sys.executable)
cmd = fix_python_path(cmd)
try:
return subprocess.call(cmd, env=env)
except OSError:
Expand Down
11 changes: 11 additions & 0 deletions tools/isolate/run_test_from_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ def get_free_space(path):
return f.f_bfree * f.f_frsize


def fix_python_path(cmd):
"""Returns the fixed command line to call the right python executable."""
out = cmd[:]
if out[0] == 'python':
out[0] = sys.executable
elif out[0].endswith('.py'):
out.insert(0, sys.executable)
return out


class Cache(object):
"""Stateful LRU cache.
Expand Down Expand Up @@ -267,6 +277,7 @@ def run_tha_test(manifest, cache_dir, remote, max_cache_size, min_free_space):
cmd = manifest['command']
# Ensure paths are correctly separated on windows.
cmd[0] = cmd[0].replace('/', os.path.sep)
cmd = fix_python_path(cmd)
logging.info('Running %s, cwd=%s' % (cmd, cwd))
try:
return subprocess.call(cmd, cwd=cwd)
Expand Down

0 comments on commit 4bf4d63

Please sign in to comment.