Skip to content

Commit 2beb556

Browse files
author
Matt Landis
committed
fix infinite recursion when PEX_PYTHON points at a symlink
1 parent 000a8e5 commit 2beb556

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pex/pex_bootstrapper.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ def maybe_reexec_pex():
8282
target = find_in_path(target_python)
8383
if not target:
8484
die('Failed to find interpreter specified by PEX_PYTHON: %s' % target)
85-
current = os.path.realpath(sys.executable)
86-
if os.path.exists(target) and target != current:
85+
if os.path.exists(target) and os.path.realpath(target) != os.path.realpath(sys.executable):
8786
TRACER.log('Detected PEX_PYTHON, re-exec to %s' % target)
8887
ENV.delete('PEX_PYTHON')
8988
os.execve(target, [target_python] + sys.argv, ENV.copy())

tests/test_integration.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# Licensed under the Apache License, Version 2.0 (see LICENSE).
33

44
import os
5+
import sys
56

6-
from twitter.common.contextutil import temporary_file
7+
from twitter.common.contextutil import environment_as, temporary_dir, temporary_file
78

89
from pex.testing import run_simple_pex_test
910

@@ -30,3 +31,17 @@ def test_pex_interpreter():
3031
so, rc = run_simple_pex_test("", args=(fp.name,), coverage=True, env=env)
3132
assert so == b'Hello world\n'
3233
assert rc == 0
34+
35+
36+
def test_pex_python_symlink():
37+
with temporary_dir() as td:
38+
with environment_as(HOME=td):
39+
symlink_path = os.path.join(td, 'python-symlink')
40+
os.symlink(sys.executable, symlink_path)
41+
pexrc_path = os.path.join(td, '.pexrc')
42+
with open(pexrc_path, 'w') as pexrc:
43+
pexrc.write("PEX_PYTHON=%s" % symlink_path)
44+
45+
body = "print('Hello')"
46+
_, rc = run_simple_pex_test(body, coverage=True)
47+
assert rc == 0

0 commit comments

Comments
 (0)