Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/pip/cmdoptions.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 """ | |
2 shared options and groups | |
3 | |
4 The principle here is to define options once, but *not* instantiate them | |
5 globally. One reason being that options with action='append' can carry state | |
6 between parses. pip parse's general options twice internally, and shouldn't | |
7 pass on state. To be consistent, all options will follow this design. | |
8 | |
9 """ | |
10 from __future__ import absolute_import | |
11 | |
12 import copy | |
13 from optparse import OptionGroup, SUPPRESS_HELP, Option | |
14 from pip.index import PyPI | |
15 from pip.locations import CA_BUNDLE_PATH, USER_CACHE_DIR, src_prefix | |
16 | |
17 | |
18 def make_option_group(group, parser): | |
19 """ | |
20 Return an OptionGroup object | |
21 group -- assumed to be dict with 'name' and 'options' keys | |
22 parser -- an optparse Parser | |
23 """ | |
24 option_group = OptionGroup(parser, group['name']) | |
25 for option in group['options']: | |
26 option_group.add_option(option.make()) | |
27 return option_group | |
28 | |
29 | |
30 class OptionMaker(object): | |
31 """Class that stores the args/kwargs that would be used to make an Option, | |
32 for making them later, and uses deepcopy's to reset state.""" | |
33 | |
34 def __init__(self, *args, **kwargs): | |
35 self.args = args | |
36 self.kwargs = kwargs | |
37 | |
38 def make(self): | |
39 args_copy = copy.deepcopy(self.args) | |
40 kwargs_copy = copy.deepcopy(self.kwargs) | |
41 return Option(*args_copy, **kwargs_copy) | |
42 | |
43 ########### | |
44 # options # | |
45 ########### | |
46 | |
47 help_ = OptionMaker( | |
48 '-h', '--help', | |
49 dest='help', | |
50 action='help', | |
51 help='Show help.') | |
52 | |
53 isolated_mode = OptionMaker( | |
54 "--isolated", | |
55 dest="isolated_mode", | |
56 action="store_true", | |
57 default=False, | |
58 help=( | |
59 "Run pip in an isolated mode, ignoring environment variables and user " | |
60 "configuration." | |
61 ), | |
62 ) | |
63 | |
64 require_virtualenv = OptionMaker( | |
65 # Run only if inside a virtualenv, bail if not. | |
66 '--require-virtualenv', '--require-venv', | |
67 dest='require_venv', | |
68 action='store_true', | |
69 default=False, | |
70 help=SUPPRESS_HELP) | |
71 | |
72 verbose = OptionMaker( | |
73 '-v', '--verbose', | |
74 dest='verbose', | |
75 action='count', | |
76 default=0, | |
77 help='Give more output. Option is additive, and can be used up to 3 times.' | |
78 ) | |
79 | |
80 version = OptionMaker( | |
81 '-V', '--version', | |
82 dest='version', | |
83 action='store_true', | |
84 help='Show version and exit.') | |
85 | |
86 quiet = OptionMaker( | |
87 '-q', '--quiet', | |
88 dest='quiet', | |
89 action='count', | |
90 default=0, | |
91 help='Give less output.') | |
92 | |
93 log = OptionMaker( | |
94 "--log", "--log-file", "--local-log", | |
95 dest="log", | |
96 metavar="path", | |
97 help="Path to a verbose appending log." | |
98 ) | |
99 | |
100 log_explicit_levels = OptionMaker( | |
101 # Writes the log levels explicitely to the log' | |
102 '--log-explicit-levels', | |
103 dest='log_explicit_levels', | |
104 action='store_true', | |
105 default=False, | |
106 help=SUPPRESS_HELP) | |
107 | |
108 no_input = OptionMaker( | |
109 # Don't ask for input | |
110 '--no-input', | |
111 dest='no_input', | |
112 action='store_true', | |
113 default=False, | |
114 help=SUPPRESS_HELP) | |
115 | |
116 proxy = OptionMaker( | |
117 '--proxy', | |
118 dest='proxy', | |
119 type='str', | |
120 default='', | |
121 help="Specify a proxy in the form [user:passwd@]proxy.server:port.") | |
122 | |
123 retries = OptionMaker( | |
124 '--retries', | |
125 dest='retries', | |
126 type='int', | |
127 default=5, | |
128 help="Maximum number of retries each connection should attempt " | |
129 "(default %default times).") | |
130 | |
131 timeout = OptionMaker( | |
132 '--timeout', '--default-timeout', | |
133 metavar='sec', | |
134 dest='timeout', | |
135 type='float', | |
136 default=15, | |
137 help='Set the socket timeout (default %default seconds).') | |
138 | |
139 default_vcs = OptionMaker( | |
140 # The default version control system for editables, e.g. 'svn' | |
141 '--default-vcs', | |
142 dest='default_vcs', | |
143 type='str', | |
144 default='', | |
145 help=SUPPRESS_HELP) | |
146 | |
147 skip_requirements_regex = OptionMaker( | |
148 # A regex to be used to skip requirements | |
149 '--skip-requirements-regex', | |
150 dest='skip_requirements_regex', | |
151 type='str', | |
152 default='', | |
153 help=SUPPRESS_HELP) | |
154 | |
155 exists_action = OptionMaker( | |
156 # Option when path already exist | |
157 '--exists-action', | |
158 dest='exists_action', | |
159 type='choice', | |
160 choices=['s', 'i', 'w', 'b'], | |
161 default=[], | |
162 action='append', | |
163 metavar='action', | |
164 help="Default action when a path already exists: " | |
165 "(s)witch, (i)gnore, (w)ipe, (b)ackup.") | |
166 | |
167 cert = OptionMaker( | |
168 '--cert', | |
169 dest='cert', | |
170 type='str', | |
171 default=CA_BUNDLE_PATH, | |
172 metavar='path', | |
173 help="Path to alternate CA bundle.") | |
174 | |
175 client_cert = OptionMaker( | |
176 '--client-cert', | |
177 dest='client_cert', | |
178 type='str', | |
179 default=None, | |
180 metavar='path', | |
181 help="Path to SSL client certificate, a single file containing the " | |
182 "private key and the certificate in PEM format.") | |
183 | |
184 index_url = OptionMaker( | |
185 '-i', '--index-url', '--pypi-url', | |
186 dest='index_url', | |
187 metavar='URL', | |
188 default=PyPI.simple_url, | |
189 help='Base URL of Python Package Index (default %default).') | |
190 | |
191 extra_index_url = OptionMaker( | |
192 '--extra-index-url', | |
193 dest='extra_index_urls', | |
194 metavar='URL', | |
195 action='append', | |
196 default=[], | |
197 help='Extra URLs of package indexes to use in addition to --index-url.') | |
198 | |
199 no_index = OptionMaker( | |
200 '--no-index', | |
201 dest='no_index', | |
202 action='store_true', | |
203 default=False, | |
204 help='Ignore package index (only looking at --find-links URLs instead).') | |
205 | |
206 find_links = OptionMaker( | |
207 '-f', '--find-links', | |
208 dest='find_links', | |
209 action='append', | |
210 default=[], | |
211 metavar='url', | |
212 help="If a url or path to an html file, then parse for links to archives. " | |
213 "If a local path or file:// url that's a directory, then look for " | |
214 "archives in the directory listing.") | |
215 | |
216 # TODO: Remove after 6.0 | |
217 use_mirrors = OptionMaker( | |
218 '-M', '--use-mirrors', | |
219 dest='use_mirrors', | |
220 action='store_true', | |
221 default=False, | |
222 help=SUPPRESS_HELP) | |
223 | |
224 # TODO: Remove after 6.0 | |
225 mirrors = OptionMaker( | |
226 '--mirrors', | |
227 dest='mirrors', | |
228 metavar='URL', | |
229 action='append', | |
230 default=[], | |
231 help=SUPPRESS_HELP) | |
232 | |
233 allow_external = OptionMaker( | |
234 "--allow-external", | |
235 dest="allow_external", | |
236 action="append", | |
237 default=[], | |
238 metavar="PACKAGE", | |
239 help="Allow the installation of a package even if it is externally hosted", | |
240 ) | |
241 | |
242 allow_all_external = OptionMaker( | |
243 "--allow-all-external", | |
244 dest="allow_all_external", | |
245 action="store_true", | |
246 default=False, | |
247 help="Allow the installation of all packages that are externally hosted", | |
248 ) | |
249 | |
250 trusted_host = OptionMaker( | |
251 "--trusted-host", | |
252 dest="trusted_hosts", | |
253 action="append", | |
254 metavar="HOSTNAME", | |
255 default=[], | |
256 help="Mark this host as trusted, even though it does not have valid or " | |
257 "any HTTPS.", | |
258 ) | |
259 | |
260 # Remove after 7.0 | |
261 no_allow_external = OptionMaker( | |
262 "--no-allow-external", | |
263 dest="allow_all_external", | |
264 action="store_false", | |
265 default=False, | |
266 help=SUPPRESS_HELP, | |
267 ) | |
268 | |
269 # Remove --allow-insecure after 7.0 | |
270 allow_unsafe = OptionMaker( | |
271 "--allow-unverified", "--allow-insecure", | |
272 dest="allow_unverified", | |
273 action="append", | |
274 default=[], | |
275 metavar="PACKAGE", | |
276 help="Allow the installation of a package even if it is hosted " | |
277 "in an insecure and unverifiable way", | |
278 ) | |
279 | |
280 # Remove after 7.0 | |
281 no_allow_unsafe = OptionMaker( | |
282 "--no-allow-insecure", | |
283 dest="allow_all_insecure", | |
284 action="store_false", | |
285 default=False, | |
286 help=SUPPRESS_HELP | |
287 ) | |
288 | |
289 # Remove after 1.5 | |
290 process_dependency_links = OptionMaker( | |
291 "--process-dependency-links", | |
292 dest="process_dependency_links", | |
293 action="store_true", | |
294 default=False, | |
295 help="Enable the processing of dependency links.", | |
296 ) | |
297 | |
298 requirements = OptionMaker( | |
299 '-r', '--requirement', | |
300 dest='requirements', | |
301 action='append', | |
302 default=[], | |
303 metavar='file', | |
304 help='Install from the given requirements file. ' | |
305 'This option can be used multiple times.') | |
306 | |
307 editable = OptionMaker( | |
308 '-e', '--editable', | |
309 dest='editables', | |
310 action='append', | |
311 default=[], | |
312 metavar='path/url', | |
313 help=('Install a project in editable mode (i.e. setuptools ' | |
314 '"develop mode") from a local project path or a VCS url.'), | |
315 ) | |
316 | |
317 src = OptionMaker( | |
318 '--src', '--source', '--source-dir', '--source-directory', | |
319 dest='src_dir', | |
320 metavar='dir', | |
321 default=src_prefix, | |
322 help='Directory to check out editable projects into. ' | |
323 'The default in a virtualenv is "<venv path>/src". ' | |
324 'The default for global installs is "<current dir>/src".' | |
325 ) | |
326 | |
327 use_wheel = OptionMaker( | |
328 '--use-wheel', | |
329 dest='use_wheel', | |
330 action='store_true', | |
331 help=SUPPRESS_HELP, | |
332 ) | |
333 | |
334 no_use_wheel = OptionMaker( | |
335 '--no-use-wheel', | |
336 dest='use_wheel', | |
337 action='store_false', | |
338 default=True, | |
339 help=('Do not Find and prefer wheel archives when searching indexes and ' | |
340 'find-links locations.'), | |
341 ) | |
342 | |
343 cache_dir = OptionMaker( | |
344 "--cache-dir", | |
345 dest="cache_dir", | |
346 default=USER_CACHE_DIR, | |
347 metavar="dir", | |
348 help="Store the cache data in <dir>." | |
349 ) | |
350 | |
351 no_cache = OptionMaker( | |
352 "--no-cache-dir", | |
353 dest="cache_dir", | |
354 action="store_false", | |
355 help="Disable the cache.", | |
356 ) | |
357 | |
358 download_cache = OptionMaker( | |
359 '--download-cache', | |
360 dest='download_cache', | |
361 default=None, | |
362 help=SUPPRESS_HELP) | |
363 | |
364 no_deps = OptionMaker( | |
365 '--no-deps', '--no-dependencies', | |
366 dest='ignore_dependencies', | |
367 action='store_true', | |
368 default=False, | |
369 help="Don't install package dependencies.") | |
370 | |
371 build_dir = OptionMaker( | |
372 '-b', '--build', '--build-dir', '--build-directory', | |
373 dest='build_dir', | |
374 metavar='dir', | |
375 help='Directory to unpack packages into and build in.' | |
376 ) | |
377 | |
378 install_options = OptionMaker( | |
379 '--install-option', | |
380 dest='install_options', | |
381 action='append', | |
382 metavar='options', | |
383 help="Extra arguments to be supplied to the setup.py install " | |
384 "command (use like --install-option=\"--install-scripts=/usr/local/" | |
385 "bin\"). Use multiple --install-option options to pass multiple " | |
386 "options to setup.py install. If you are using an option with a " | |
387 "directory path, be sure to use absolute path.") | |
388 | |
389 global_options = OptionMaker( | |
390 '--global-option', | |
391 dest='global_options', | |
392 action='append', | |
393 metavar='options', | |
394 help="Extra global options to be supplied to the setup.py " | |
395 "call before the install command.") | |
396 | |
397 no_clean = OptionMaker( | |
398 '--no-clean', | |
399 action='store_true', | |
400 default=False, | |
401 help="Don't clean up build directories.") | |
402 | |
403 disable_pip_version_check = OptionMaker( | |
404 "--disable-pip-version-check", | |
405 dest="disable_pip_version_check", | |
406 action="store_true", | |
407 default=False, | |
408 help="Don't periodically check PyPI to determine whether a new version " | |
409 "of pip is available for download. Implied with --no-index.") | |
410 | |
411 ########## | |
412 # groups # | |
413 ########## | |
414 | |
415 general_group = { | |
416 'name': 'General Options', | |
417 'options': [ | |
418 help_, | |
419 isolated_mode, | |
420 require_virtualenv, | |
421 verbose, | |
422 version, | |
423 quiet, | |
424 log, | |
425 log_explicit_levels, | |
426 no_input, | |
427 proxy, | |
428 retries, | |
429 timeout, | |
430 default_vcs, | |
431 skip_requirements_regex, | |
432 exists_action, | |
433 trusted_host, | |
434 cert, | |
435 client_cert, | |
436 cache_dir, | |
437 no_cache, | |
438 disable_pip_version_check, | |
439 ] | |
440 } | |
441 | |
442 index_group = { | |
443 'name': 'Package Index Options', | |
444 'options': [ | |
445 index_url, | |
446 extra_index_url, | |
447 no_index, | |
448 find_links, | |
449 use_mirrors, | |
450 mirrors, | |
451 allow_external, | |
452 allow_all_external, | |
453 no_allow_external, | |
454 allow_unsafe, | |
455 no_allow_unsafe, | |
456 process_dependency_links, | |
457 ] | |
458 } |