Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pex/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def execute_script(self, script_name):

entry_point = get_entry_point_from_console_script(script_name, dists)
if entry_point:
return self.execute_entry(entry_point)
sys.exit(self.execute_entry(entry_point))

dist, script_path, script_content = get_script_from_distributions(script_name, dists)
if not dist:
Expand Down Expand Up @@ -426,7 +426,7 @@ def execute_content(cls, name, content, argv0=None):
@classmethod
def execute_entry(cls, entry_point):
runner = cls.execute_pkg_resources if ':' in entry_point else cls.execute_module
runner(entry_point)
return runner(entry_point)

@staticmethod
def execute_module(module_name):
Expand All @@ -444,7 +444,7 @@ def execute_pkg_resources(spec):
else:
# setuptools < 11.3
runner = entry.load(require=False)
runner()
return runner()

def cmdline(self, args=()):
"""The commandline to run this environment.
Expand Down
34 changes: 32 additions & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

import os
import sys
from textwrap import dedent

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

from pex.compatibility import WINDOWS
from pex.testing import run_pex_command, run_simple_pex_test
from pex.util import named_temporary_file
from pex.installer import EggInstaller
from pex.testing import run_pex_command, run_simple_pex_test, temporary_content
from pex.util import DistributionHelper, named_temporary_file


def test_pex_execute():
Expand Down Expand Up @@ -88,3 +90,31 @@ def test_pex_python_symlink():
body = "print('Hello')"
_, rc = run_simple_pex_test(body, coverage=True)
assert rc == 0


def test_entry_point_exit_code():
setup_py = dedent("""
from setuptools import setup

setup(
name='my_app',
version='0.0.0',
zip_safe=True,
packages=[''],
entry_points={'console_scripts': ['my_app = my_app:do_something']},
)
""")

error_msg = 'setuptools expects this to exit non-zero'

my_app = dedent("""
def do_something():
return '%s'
""" % error_msg)

with temporary_content({'setup.py': setup_py, 'my_app.py': my_app}) as project_dir:
installer = EggInstaller(project_dir)
dist = DistributionHelper.distribution_from_path(installer.bdist())
so, rc = run_simple_pex_test('', env={'PEX_SCRIPT': 'my_app'}, dists=[dist])
assert so.decode('utf-8').strip() == error_msg
assert rc == 1