Skip to content

Commit

Permalink
fix infinite recursion when PEX_PYTHON points at a symlink.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Landis committed Nov 19, 2015
1 parent 000a8e5 commit 1aeb863
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 1 addition & 2 deletions pex/pex_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def maybe_reexec_pex():
target = find_in_path(target_python)
if not target:
die('Failed to find interpreter specified by PEX_PYTHON: %s' % target)
current = os.path.realpath(sys.executable)
if os.path.exists(target) and target != current:
if os.path.exists(target) and os.path.realpath(target) != os.path.realpath(sys.executable):
TRACER.log('Detected PEX_PYTHON, re-exec to %s' % target)
ENV.delete('PEX_PYTHON')
os.execve(target, [target_python] + sys.argv, ENV.copy())
Expand Down
17 changes: 16 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import os
import sys

from twitter.common.contextutil import temporary_file
from twitter.common.contextutil import environment_as, temporary_dir, temporary_file

from pex.testing import run_simple_pex_test

Expand All @@ -30,3 +31,17 @@ def test_pex_interpreter():
so, rc = run_simple_pex_test("", args=(fp.name,), coverage=True, env=env)
assert so == b'Hello world\n'
assert rc == 0


def test_pex_python_symlink():
with temporary_dir() as td:
with environment_as(HOME=td):
symlink_path = os.path.join(td, 'python-symlink')
os.symlink(sys.executable, symlink_path)
pexrc_path = os.path.join(td, '.pexrc')
with open(pexrc_path, 'w') as pexrc:
pexrc.write("PEX_PYTHON=%s" % symlink_path)

body = "print('Hello')"
_, rc = run_simple_pex_test(body, coverage=True)
assert rc == 0

0 comments on commit 1aeb863

Please sign in to comment.