diff --git a/pex/pex.py b/pex/pex.py index 0d5f10876..f5cf0bd24 100644 --- a/pex/pex.py +++ b/pex/pex.py @@ -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: @@ -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): @@ -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. diff --git a/tests/test_integration.py b/tests/test_integration.py index f68159711..898561b28 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -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(): @@ -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