Skip to content

Commit 3c84621

Browse files
committed
Move "Requirements File Format" docs to reference/
This is a better, more visible location for this file format. It is more discoverable and more likely to show up in search results.
1 parent 2ae532a commit 3c84621

File tree

3 files changed

+145
-111
lines changed

3 files changed

+145
-111
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/reference/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ Reference provides information about various file formats, interfaces and
44
interoperability standards that pip utilises/implements.
55

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

0 commit comments

Comments
 (0)