Skip to content

Commit 0549e4b

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

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

pex/pex_bootstrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def maybe_reexec_pex():
7979
from .tracer import TRACER
8080

8181
target_python = ENV.PEX_PYTHON
82-
target = find_in_path(target_python)
82+
target = os.path.realpath(find_in_path(target_python))
8383
if not target:
8484
die('Failed to find interpreter specified by PEX_PYTHON: %s' % target)
8585
current = os.path.realpath(sys.executable)

tests/test_integration.py

Lines changed: 19 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,20 @@ 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+
try:
43+
with open(pexrc_path, 'w') as pexrc:
44+
pexrc.write("PEX_PYTHON=%s" % symlink_path)
45+
46+
body = "print('Hello')"
47+
_, rc = run_simple_pex_test(body, coverage=True)
48+
assert rc == 0
49+
finally:
50+
os.unlink(pexrc_path)

0 commit comments

Comments
 (0)