Skip to content

Commit 3b4373c

Browse files
committed
Merge pull request #2537 from gvalkov/reqfileopts
Add --install-options and --global-options to the requirements file parser.
2 parents c6e149f + 3315242 commit 3b4373c

File tree

8 files changed

+694
-205
lines changed

8 files changed

+694
-205
lines changed

docs/reference/pip_install.rst

+38
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Each line of the requirements file indicates something to be installed,
7474
and like arguments to :ref:`pip install`, the following forms are supported::
7575

7676
<requirement specifier>
77+
<requirement specifier> [--install-option="..."] [--global-option="..."]
7778
<archive url/path>
7879
[-e] <local project path>
7980
[-e] <vcs project url>
@@ -90,6 +91,9 @@ A line that begins with ``#`` is treated as a comment and ignored. Whitespace
9091
followed by a ``#`` causes the ``#`` and the remainder of the line to be
9192
treated as a comment.
9293

94+
A line ending in an unescaped ``\`` is treated as a line continuation
95+
and the newline following it is effectively ignored.
96+
9397
Additionally, the following Package Index Options are supported:
9498

9599
* :ref:`-i, --index-url <--index-url>`
@@ -138,6 +142,40 @@ Some Examples:
138142
Don't use single or double quotes in a ``requirements.txt`` file.
139143

140144

145+
.. _`Per-requirement Overrides`:
146+
147+
Per-requirement Overrides
148+
+++++++++++++++++++++++++
149+
150+
When pip installs packages, it normally executes the ``setup.py`` file
151+
behind the scenes. You may extend the arguments with which the
152+
``setup.py`` file is called through the ``--global-option`` and
153+
``--install-option`` options. For example:
154+
155+
::
156+
157+
FooProject >= 1.2 --global-option="--no-user-cfg" \
158+
--install-option="--prefix='/usr/local'" \
159+
--install-option="--no-compile"
160+
161+
The above translates roughly into running FooProject's ``setup.py``
162+
script as:
163+
164+
::
165+
166+
python setup.py --no-user-cfg install --prefix='/usr/local' --no-compile
167+
168+
Note that the only way of giving more than one option to ``setup.py``
169+
is through multiple ``--global-option`` and ``--install-option``
170+
options, as shown in the example above. The value of each option is
171+
passed as a single argument to the ``setup.py`` script. Therefore, a
172+
line such as the following is invalid and would result in an
173+
installation error.
174+
175+
::
176+
177+
# Invalid. Please use '--install-option' twice as shown above.
178+
FooProject >= 1.2 --install-option="--prefix=/usr/local --no-compile"
141179

142180

143181
.. _`Pre Release Versions`:

pip/exceptions.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ class DistributionNotFound(InstallationError):
1818
"""Raised when a distribution cannot be found to satisfy a requirement"""
1919

2020

21+
class RequirementsFileParseError(PipError):
22+
"""Raised when an invalid state is encountered during requirement file
23+
parsing."""
24+
25+
2126
class BestVersionAlreadyInstalled(PipError):
2227
"""Raised when the most up-to-date version of a package is already
23-
installed. """
28+
installed."""
2429

2530

2631
class BadCommand(PipError):

0 commit comments

Comments
 (0)