Debian Codegraph @

docs/usage.rst

raw
1 .. # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 # See the License for the specific language governing permissions and
11 # limitations under the License.
12 #
13 # SPDX-License-Identifier: Apache-2.0
14
15 Usage
16 =====
17
18 Requirements parser works very similarly to the way pip actually parses requirement files except that pip typically
19 proceeds to install the relevant packages.
20
21 Requirements come in a variety of forms such as requirement specifiers (such as requirements>=0.0.5), version control
22 URIs, other URIs and local file paths.
23
24 Parsing requirement specifiers
25 ------------------------------
26
27 .. code-block:: python
28
29 import requirements
30 req = "django>=1.5,<1.6"
31 parsed = list(requirements.parse(req))[0]
32 parsed.name # django
33 parsed.specs # [('>=', '1.5'), ('<', '1.6')]
34 parsed.specifier # True
35
36 Parsing version control requirements
37 ------------------------------------
38
39 .. code-block:: python
40
41 req = "-e git+git://github.com/toastdriven/django-haystack@259274e4127f723d76b893c87a82777f9490b960#egg=django_haystack"
42 parsed = list(requirements.parse(req))[0]
43 parsed.name # django_haystack
44 parsed.vcs # git
45 parsed.revision # 259274e4127f723d76b893c87a82777f9490b960
46 parsed.uri # git+git://github.com/toastdriven/django-haystack
47 parsed.editable # True (because of the -e option)
48
49
50 Parsing local files
51 -------------------
52
53 .. code-block:: python
54
55 req = "-e path/to/project"
56 parsed = list(requirements.parse(req))[0]
57 parsed.local_file # True
58 parsed.path # path/to/project