Skip to content

Commit 5d387aa

Browse files
brbsixkwlzn
authored andcommitted
Fix bdist_pex --pex-args (#285)
* Fix bdist_pex --pex-args Splitting on spaces with break on commands like: python setup.py bdist_pex \ --pex-args="--python-shebang='#!/usr/bin/env python'" This uses shlex.split instead. * Add tests for bdist_pex --pex-args shebang with and without spaces
1 parent 9f0d604 commit 5d387aa

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

pex/commands/bdist_pex.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import shlex
23
from distutils import log
34

45
from setuptools import Command
@@ -29,7 +30,7 @@ def initialize_options(self):
2930
self.pex_args = ''
3031

3132
def finalize_options(self):
32-
self.pex_args = self.pex_args.split()
33+
self.pex_args = shlex.split(self.pex_args)
3334

3435
def _write(self, pex_builder, target, script=None):
3536
builder = pex_builder.clone()

tests/test_bdist_pex.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,30 @@ def do_something():
4040
assert stdout == b'hello world!\n'
4141

4242

43+
def assert_pex_args_shebang(shebang):
44+
setup_py = dedent("""
45+
from setuptools import setup
46+
47+
setup(
48+
name='my_app',
49+
version='0.0.0',
50+
zip_safe=True,
51+
packages=[''],
52+
)
53+
""")
54+
55+
with temporary_content({'setup.py': setup_py}) as project_dir:
56+
with pushd(project_dir):
57+
assert subprocess.check_call(
58+
[sys.executable, 'setup.py', 'bdist_pex',
59+
'--pex-args=--python-shebang="%(shebang)s"' %
60+
dict(shebang=shebang)]) == 0
61+
62+
with open(os.path.join(project_dir, 'dist',
63+
'my_app-0.0.0.pex'), 'rb') as fp:
64+
assert fp.readline().decode().rstrip() == shebang
65+
66+
4367
def test_entry_points_dict():
4468
assert_entry_points({'console_scripts': ['my_app = my_app:do_something']})
4569

@@ -49,3 +73,11 @@ def test_entry_points_ini_string():
4973
[console_scripts]
5074
my_app=my_app:do_something
5175
"""))
76+
77+
78+
def test_pex_args_shebang_with_spaces():
79+
assert_pex_args_shebang('#!/usr/bin/env python')
80+
81+
82+
def test_pex_args_shebang_without_spaces():
83+
assert_pex_args_shebang('#!/usr/bin/python')

0 commit comments

Comments
 (0)