Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/pip/req/req_file.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author | bcclaywell |
---|---|
date | Mon, 12 Oct 2015 17:43:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d67268158946 |
---|---|
1 from __future__ import absolute_import | |
2 | |
3 import os | |
4 import re | |
5 | |
6 from pip._vendor.six.moves.urllib import parse as urllib_parse | |
7 | |
8 from pip.download import get_file_content | |
9 from pip.req.req_install import InstallRequirement | |
10 from pip.utils import normalize_name | |
11 | |
12 _scheme_re = re.compile(r'^(http|https|file):', re.I) | |
13 | |
14 | |
15 def _remove_prefixes(line, short_prefix, long_prefix): | |
16 if line.startswith(short_prefix): | |
17 return line[len(short_prefix):].lstrip() | |
18 else: | |
19 return _remove_prefix(line, long_prefix) | |
20 | |
21 | |
22 def _remove_prefix(line, prefix): | |
23 """Remove the prefix and eventually one '=' or spaces""" | |
24 return re.sub(r'\s*=?\s*', '', line[len(prefix):]) | |
25 | |
26 | |
27 def parse_requirements(filename, finder=None, comes_from=None, options=None, | |
28 session=None): | |
29 if session is None: | |
30 raise TypeError( | |
31 "parse_requirements() missing 1 required keyword argument: " | |
32 "'session'" | |
33 ) | |
34 | |
35 skip_match = None | |
36 skip_regex = options.skip_requirements_regex if options else None | |
37 if skip_regex: | |
38 skip_match = re.compile(skip_regex) | |
39 reqs_file_dir = os.path.dirname(os.path.abspath(filename)) | |
40 filename, content = get_file_content( | |
41 filename, | |
42 comes_from=comes_from, | |
43 session=session, | |
44 ) | |
45 for line_number, line in enumerate(content.splitlines(), 1): | |
46 line = line.strip() | |
47 | |
48 # Remove comments from file and all spaces before it | |
49 line = re.sub(r"(^|\s)+#.*$", "", line) | |
50 | |
51 if not line: | |
52 continue | |
53 if skip_match and skip_match.search(line): | |
54 continue | |
55 if line.startswith(('-r', '--requirement')): | |
56 req_url = _remove_prefixes(line, '-r', '--requirement') | |
57 if _scheme_re.search(filename): | |
58 # Relative to a URL | |
59 req_url = urllib_parse.urljoin(filename, req_url) | |
60 elif not _scheme_re.search(req_url): | |
61 req_url = os.path.join(os.path.dirname(filename), req_url) | |
62 for item in parse_requirements( | |
63 req_url, finder, | |
64 comes_from=filename, | |
65 options=options, | |
66 session=session): | |
67 yield item | |
68 elif line.startswith(('-Z', '--always-unzip')): | |
69 # No longer used, but previously these were used in | |
70 # requirement files, so we'll ignore. | |
71 pass | |
72 elif line.startswith(('-f', '--find-links')): | |
73 find_links = _remove_prefixes(line, '-f', '--find-links') | |
74 # FIXME: it would be nice to keep track of the source of | |
75 # the find_links: | |
76 # support a find-links local path relative to a requirements file | |
77 relative_to_reqs_file = os.path.join(reqs_file_dir, find_links) | |
78 if os.path.exists(relative_to_reqs_file): | |
79 find_links = relative_to_reqs_file | |
80 if finder: | |
81 finder.find_links.append(find_links) | |
82 elif line.startswith(('-i', '--index-url')): | |
83 index_url = _remove_prefixes(line, '-i', '--index-url') | |
84 if finder: | |
85 finder.index_urls = [index_url] | |
86 elif line.startswith('--extra-index-url'): | |
87 line = _remove_prefix(line, '--extra-index-url') | |
88 if finder: | |
89 finder.index_urls.append(line) | |
90 elif line.startswith('--use-wheel'): | |
91 # Default in 1.5 | |
92 pass | |
93 elif line.startswith('--no-use-wheel'): | |
94 if finder: | |
95 finder.use_wheel = False | |
96 elif line.startswith('--no-index'): | |
97 if finder: | |
98 finder.index_urls = [] | |
99 elif line.startswith("--allow-external"): | |
100 line = _remove_prefix(line, '--allow-external') | |
101 if finder: | |
102 finder.allow_external |= set([normalize_name(line).lower()]) | |
103 elif line.startswith("--allow-all-external"): | |
104 if finder: | |
105 finder.allow_all_external = True | |
106 # Remove in 7.0 | |
107 elif line.startswith("--no-allow-external"): | |
108 pass | |
109 # Remove in 7.0 | |
110 elif line.startswith("--no-allow-insecure"): | |
111 pass | |
112 # Remove after 7.0 | |
113 elif line.startswith("--allow-insecure"): | |
114 line = _remove_prefix(line, '--allow-insecure') | |
115 if finder: | |
116 finder.allow_unverified |= set([normalize_name(line).lower()]) | |
117 elif line.startswith("--allow-unverified"): | |
118 line = _remove_prefix(line, '--allow-unverified') | |
119 if finder: | |
120 finder.allow_unverified |= set([normalize_name(line).lower()]) | |
121 else: | |
122 comes_from = '-r %s (line %s)' % (filename, line_number) | |
123 if line.startswith(('-e', '--editable')): | |
124 editable = _remove_prefixes(line, '-e', '--editable') | |
125 req = InstallRequirement.from_editable( | |
126 editable, | |
127 comes_from=comes_from, | |
128 default_vcs=options.default_vcs if options else None, | |
129 isolated=options.isolated_mode if options else False, | |
130 ) | |
131 else: | |
132 req = InstallRequirement.from_line( | |
133 line, | |
134 comes_from, | |
135 isolated=options.isolated_mode if options else False, | |
136 ) | |
137 yield req |