Skip to content

Commit 0882aff

Browse files
committed
Do not shlex.split() and flatten value of global|install_options
1 parent fcc415f commit 0882aff

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

docs/reference/pip_install.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,27 @@ Some Examples:
9898
Per-requirement Overrides
9999
+++++++++++++++++++++++++
100100

101-
It is possible to set ``--install-option`` and ``--global-option``
102-
for each requirement in the requirements file:
101+
When pip installs packages, it normally executes the ``setup.py`` file
102+
behind the scenes. You may extend the arguments with which the
103+
``setup.py`` file is called through the ``--global-option`` and
104+
``--install-option`` options. For example:
103105

104106
::
105107

106-
FooProject >= 1.2 --install-option="--prefix='/usr/local'" \
107-
--global-option="--no-user-cfg"
108+
FooProject >= 1.2 --global-option="--no-user-cfg" \
109+
--install-option="--prefix='/usr/local'" \
110+
--install-option="--no-compile"
108111

109112
The above translates roughly into running FooProject's ``setup.py``
110113
script as:
111114

112115
::
113116

114-
python setup.py --no-user-cfg install --prefix='/usr/local'
117+
python setup.py --no-user-cfg install --prefix='/usr/local' --no-compile
118+
119+
Note that the correct way of giving more than one option to
120+
``setup.py`` is through multiple ``--global-option`` and
121+
``--install-option`` options, as shown in the example above.
115122

116123

117124
.. _`Pre Release Versions`:

pip/req/req_file.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,6 @@ def parse_requirement_options(args):
243243
args = shlex.split(args)
244244
opts, _ = _req_parser.parse_args(args)
245245

246-
if opts.install_options:
247-
opts.install_options = flat_shlex_split(opts.install_options)
248-
if opts.global_options:
249-
opts.global_options = flat_shlex_split(opts.global_options)
250-
251246
# Remove None keys from result.
252247
keys = [opt for opt in opts.__dict__ if getattr(opts, opt) is None]
253248
for key in keys:
@@ -303,12 +298,4 @@ def partition_line(line):
303298
return firstword, rest
304299

305300

306-
def flat_shlex_split(x):
307-
'''
308-
>>> flat_shlex_split(['--one --two', '--three "4" --five'])
309-
['--one', '--two', '--three', '4', '--five']
310-
'''
311-
return [j for i in x for j in shlex.split(i)]
312-
313-
314301
__all__ = 'parse_requirements'

tests/functional/test_install_reqs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def getsetuppyargs(contents):
134134
'''
135135

136136
args = getsetuppyargs(reqfile)
137-
expected = set(['--one', '--two', '--three', '--four', '-5', '-6'])
137+
expected = set(['--one --two', '--three', '--four -5', '-6'])
138138
assert expected.issubset(set(args))
139139

140140

tests/unit/test_req.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,16 +555,22 @@ def test_parse_flags_from_requirements(finder):
555555

556556
def test_get_requirement_options():
557557
res = parse_requirement_options('--install-option="--abc --zxc"')
558-
assert res == {'install_options': ['--abc', '--zxc']}
558+
assert res == {'install_options': ['--abc --zxc']}
559+
560+
res = parse_requirement_options('--global-option "--abc"')
561+
assert res == {'global_options': ['--abc']}
559562

560563
line = (
561-
'INITools==2.0 --global-option="--one --two -3" '
562-
'--install-option="--prefix=/opt"'
564+
'INITools==2.0 '
565+
'--global-option="--one --two -3" '
566+
'--global-option="--four" '
567+
'--install-option="--prefix=/opt" '
568+
'--install-option="--help" '
563569
)
564570
assert parse_line(line) == (REQUIREMENT, (
565571
'INITools==2.0', {
566-
'global_options': ['--one', '--two', '-3'],
567-
'install_options': ['--prefix=/opt'],
572+
'global_options': ['--one --two -3', '--four'],
573+
'install_options': ['--prefix=/opt', '--help'],
568574
}))
569575

570576

@@ -588,7 +594,7 @@ def test_install_requirements_with_options(tmpdir, finder, session):
588594
pass
589595

590596
call = popen.call_args_list[0][0][0]
591-
for i in '--one', '--two', '-3', '--prefix=/opt':
597+
for i in '--one --two -3', '--prefix=/opt':
592598
assert i in call
593599

594600
# TODO: assert that --global-option come before --install-option.

0 commit comments

Comments
 (0)