Skip to content

Commit 89326c8

Browse files
authored
Merge pull request #10450 from pradyunsg/docs/requirements-format
Add a dedicated page for "Requirements File Format"
2 parents 0de0b8d + 005fc1c commit 89326c8

File tree

5 files changed

+157
-122
lines changed

5 files changed

+157
-122
lines changed

docs/html/cli/pip_install.rst

Lines changed: 1 addition & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -149,120 +149,10 @@ profile:
149149
``setup_requires``.
150150

151151

152-
.. _`Requirements File Format`:
153-
154152
Requirements File Format
155153
------------------------
156154

157-
Each line of the requirements file indicates something to be installed,
158-
and like arguments to :ref:`pip install`, the following forms are supported::
159-
160-
[[--option]...]
161-
<requirement specifier> [; markers] [[--option]...]
162-
<archive url/path>
163-
[-e] <local project path>
164-
[-e] <vcs project url>
165-
166-
For details on requirement specifiers, see :ref:`Requirement Specifiers`.
167-
168-
See the :ref:`pip install Examples<pip install Examples>` for examples of all these forms.
169-
170-
A line that begins with ``#`` is treated as a comment and ignored. Whitespace
171-
followed by a ``#`` causes the ``#`` and the remainder of the line to be
172-
treated as a comment.
173-
174-
A line ending in an unescaped ``\`` is treated as a line continuation
175-
and the newline following it is effectively ignored.
176-
177-
Comments are stripped *after* line continuations are processed.
178-
179-
To interpret the requirements file in UTF-8 format add a comment
180-
``# -*- coding: utf-8 -*-`` to the first or second line of the file.
181-
182-
The following options are supported:
183-
184-
.. pip-requirements-file-options-ref-list::
185-
186-
Please note that the above options are global options, and should be specified on their individual lines.
187-
The options which can be applied to individual requirements are
188-
:ref:`--install-option <install_--install-option>`, :ref:`--global-option <install_--global-option>` and ``--hash``.
189-
190-
For example, to specify :ref:`--pre <install_--pre>`, :ref:`--no-index <install_--no-index>` and two
191-
:ref:`--find-links <install_--find-links>` locations:
192-
193-
::
194-
195-
--pre
196-
--no-index
197-
--find-links /my/local/archives
198-
--find-links http://some.archives.com/archives
199-
200-
201-
If you wish, you can refer to other requirements files, like this::
202-
203-
-r more_requirements.txt
204-
205-
You can also refer to :ref:`constraints files <Constraints Files>`, like this::
206-
207-
-c some_constraints.txt
208-
209-
.. _`Using Environment Variables`:
210-
211-
Using Environment Variables
212-
^^^^^^^^^^^^^^^^^^^^^^^^^^^
213-
214-
Since version 10, pip supports the use of environment variables inside the
215-
requirements file. You can now store sensitive data (tokens, keys, etc.) in
216-
environment variables and only specify the variable name for your requirements,
217-
letting pip lookup the value at runtime. This approach aligns with the commonly
218-
used `12-factor configuration pattern <https://12factor.net/config>`_.
219-
220-
You have to use the POSIX format for variable names including brackets around
221-
the uppercase name as shown in this example: ``${API_TOKEN}``. pip will attempt
222-
to find the corresponding environment variable defined on the host system at
223-
runtime.
224-
225-
.. note::
226-
227-
There is no support for other variable expansion syntaxes such as
228-
``$VARIABLE`` and ``%VARIABLE%``.
229-
230-
231-
.. _`Example Requirements File`:
232-
233-
Example Requirements File
234-
^^^^^^^^^^^^^^^^^^^^^^^^^
235-
236-
Use ``pip install -r example-requirements.txt`` to install::
237-
238-
#
239-
####### example-requirements.txt #######
240-
#
241-
###### Requirements without Version Specifiers ######
242-
nose
243-
nose-cov
244-
beautifulsoup4
245-
#
246-
###### Requirements with Version Specifiers ######
247-
# See https://www.python.org/dev/peps/pep-0440/#version-specifiers
248-
docopt == 0.6.1 # Version Matching. Must be version 0.6.1
249-
keyring >= 4.1.1 # Minimum version 4.1.1
250-
coverage != 3.5 # Version Exclusion. Anything except version 3.5
251-
Mopidy-Dirble ~= 1.1 # Compatible release. Same as >= 1.1, == 1.*
252-
#
253-
###### Refer to other requirements files ######
254-
-r other-requirements.txt
255-
#
256-
#
257-
###### A particular file ######
258-
./downloads/numpy-1.9.2-cp34-none-win32.whl
259-
http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl
260-
#
261-
###### Additional Requirements without Version Specifiers ######
262-
# Same as 1st section, just here to show that you can put things in any order.
263-
rejected
264-
green
265-
#
155+
This section has been moved to :doc:`../reference/requirements-file-format`.
266156

267157
.. _`Requirement Specifiers`:
268158

docs/html/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ getting-started
1414
installation
1515
user_guide
1616
topics/index
17+
reference/index
1718
cli/index
1819
```
1920

docs/html/reference/index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Reference
2+
3+
Reference provides information about various file formats, interfaces and
4+
interoperability standards that pip utilises/implements.
5+
6+
```{toctree}
7+
:titlesonly:
8+
9+
requirements-file-format
10+
```

docs/html/reference/index.rst

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Requirements File Format
2+
3+
Requirements files serve as a list of items to be installed by pip, when
4+
using {ref}`pip install`. Files that use this format are often called
5+
"pip requirements.txt files", since `requirements.txt` is usually what
6+
these files are named (although, that is not a requirement).
7+
8+
```{note}
9+
The requirements file format is closely tied to a number of internal details of
10+
pip (e.g., pip's command line options). The basic format is relatively stable
11+
and portable but the full syntax, as described here, is only intended for
12+
consumption by pip, and other tools should take that into account before using
13+
it for their own purposes.
14+
```
15+
16+
## Structure
17+
18+
Each line of the requirements file indicates something to be installed,
19+
or arguments to {ref}`pip install`. The following forms are supported:
20+
21+
- `[[--option]...]`
22+
- `<requirement specifier> [; markers] [[--option]...]`
23+
- `<archive url/path>`
24+
- `[-e] <local project path>`
25+
- `[-e] <vcs project url>`
26+
27+
For details on requirement specifiers, see {ref}`Requirement Specifiers`. For
28+
examples of all these forms, see {ref}`pip install Examples`.
29+
30+
### Encoding
31+
32+
Requirements files are `utf-8` encoding by default and also support
33+
{pep}`263` style comments to change the encoding (i.e.
34+
`# -*- coding: <encoding name> -*-`).
35+
36+
### Line continuations
37+
38+
A line ending in an unescaped `\` is treated as a line continuation
39+
and the newline following it is effectively ignored.
40+
41+
### Comments
42+
43+
A line that begins with `#` is treated as a comment and ignored. Whitespace
44+
followed by a `#` causes the `#` and the remainder of the line to be
45+
treated as a comment.
46+
47+
Comments are stripped _after_ line continuations are processed.
48+
49+
## Supported options
50+
51+
Requirements files only supports certain pip install options, which are listed
52+
below.
53+
54+
### Global options
55+
56+
The following options have an effect on the _entire_ `pip install` run, and
57+
must be specified on their individual lines.
58+
59+
```{eval-rst}
60+
.. pip-requirements-file-options-ref-list::
61+
```
62+
63+
````{admonition} Example
64+
To specify {ref}`--pre <install_--pre>`, {ref}`--no-index <install_--no-index>`
65+
and two {ref}`--find-links <install_--find-links>` locations:
66+
67+
```
68+
--pre
69+
--no-index
70+
--find-links /my/local/archives
71+
--find-links http://some.archives.com/archives
72+
```
73+
````
74+
75+
### Per-requirement options
76+
77+
The options which can be applied to individual requirements are:
78+
79+
- {ref}`--install-option <install_--install-option>`
80+
- {ref}`--global-option <install_--global-option>`
81+
- `--hash` (for {ref}`Hash-Checking mode`)
82+
83+
If you wish, you can refer to other requirements files, like this:
84+
85+
```
86+
-r more_requirements.txt
87+
```
88+
89+
You can also refer to {ref}`constraints files <Constraints Files>`, like this:
90+
91+
```
92+
-c some_constraints.txt
93+
```
94+
95+
## Using environment variables
96+
97+
```{versionadded} 10.0
98+
99+
```
100+
101+
pip supports the use of environment variables inside the
102+
requirements file.
103+
104+
You have to use the POSIX format for variable names including brackets around
105+
the uppercase name as shown in this example: `${API_TOKEN}`. pip will attempt
106+
to find the corresponding environment variable defined on the host system at
107+
runtime.
108+
109+
```{note}
110+
There is no support for other variable expansion syntaxes such as `$VARIABLE`
111+
and `%VARIABLE%`.
112+
```
113+
114+
You can now store sensitive data (tokens, keys, etc.) in environment variables
115+
and only specify the variable name for your requirements, letting pip lookup
116+
the value at runtime. This approach aligns with the commonly used
117+
[12-factor configuration pattern](https://12factor.net/config).
118+
119+
## Example
120+
121+
```
122+
###### Requirements without Version Specifiers ######
123+
pytest
124+
pytest-cov
125+
beautifulsoup4
126+
127+
###### Requirements with Version Specifiers ######
128+
# See https://www.python.org/dev/peps/pep-0440/#version-specifiers
129+
docopt == 0.6.1 # Version Matching. Must be version 0.6.1
130+
keyring >= 4.1.1 # Minimum version 4.1.1
131+
coverage != 3.5 # Version Exclusion. Anything except version 3.5
132+
Mopidy-Dirble ~= 1.1 # Compatible release. Same as >= 1.1, == 1.*
133+
134+
###### Refer to other requirements files ######
135+
-r other-requirements.txt
136+
137+
###### A particular file ######
138+
./downloads/numpy-1.9.2-cp34-none-win32.whl
139+
http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl
140+
141+
###### Additional Requirements without Version Specifiers ######
142+
# Same as 1st section, just here to show that you can put things in any order.
143+
rejected
144+
green
145+
```

0 commit comments

Comments
 (0)