Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/planemo/options.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 """ Click definitions for various shared options and arguments. | |
2 """ | |
3 | |
4 import functools | |
5 import os | |
6 | |
7 import click | |
8 from galaxy.tools.deps import docker_util | |
9 from .config import get_default_callback | |
10 | |
11 | |
12 def force_option(what="files"): | |
13 return click.option( | |
14 "-f", | |
15 "--force", | |
16 is_flag=True, | |
17 help="Overwrite existing %s if present." % what, | |
18 ) | |
19 | |
20 | |
21 def test_data_option(): | |
22 return click.option( | |
23 "--test_data", | |
24 type=click.Path(exists=True, file_okay=False, resolve_path=True), | |
25 help="test-data directory to for specified tool(s).", | |
26 ) | |
27 | |
28 | |
29 def tool_data_table_option(): | |
30 return click.option( | |
31 "--tool_data_table", | |
32 type=click.Path(exists=True, file_okay=True, resolve_path=True), | |
33 help="tool_data_table_conf.xml file to for specified tool(s).", | |
34 ) | |
35 | |
36 | |
37 def galaxy_root_option(): | |
38 return click.option( | |
39 "--galaxy_root", | |
40 type=click.Path(exists=True, file_okay=False, resolve_path=True), | |
41 help="Root of development galaxy directory to execute command with.", | |
42 ) | |
43 | |
44 | |
45 def galaxy_port_option(): | |
46 return click.option( | |
47 "--port", | |
48 type=int, | |
49 default=None, | |
50 callback=get_default_callback("9090"), | |
51 help="Port to serve Galaxy on (default is 9090).", | |
52 ) | |
53 | |
54 | |
55 def galaxy_host_option(): | |
56 return click.option( | |
57 "--host", | |
58 type=str, | |
59 default=None, | |
60 callback=get_default_callback("127.0.0.1"), | |
61 help=("Host to bind Galaxy to. Default is 127.0.0.1 that is " | |
62 "restricted to localhost connections for security reasons " | |
63 "set to 0.0.0.0 to bind Galaxy to all ports including " | |
64 "potentially publicly accessible ones."), | |
65 ) | |
66 | |
67 | |
68 def dependency_resolvers_option(): | |
69 return click.option( | |
70 "--dependency_resolvers_config_file", | |
71 type=click.Path( | |
72 exists=True, | |
73 file_okay=True, | |
74 dir_okay=False, | |
75 resolve_path=True | |
76 ), | |
77 help="Dependency resolver configuration for Galaxy to target.", | |
78 ) | |
79 | |
80 | |
81 def brew_dependency_resolution(): | |
82 return click.option( | |
83 "--brew_dependency_resolution", | |
84 is_flag=True, | |
85 help="Configure Galaxy to use plain brew dependency resolution.", | |
86 ) | |
87 | |
88 | |
89 def shed_dependency_resolution(): | |
90 return click.option( | |
91 "--shed_dependency_resolution", | |
92 is_flag=True, | |
93 help=("Configure Galaxy to use brewed Tool Shed dependency" | |
94 " resolution."), | |
95 ) | |
96 | |
97 | |
98 def job_config_option(): | |
99 return click.option( | |
100 "--job_config_file", | |
101 type=click.Path( | |
102 exists=True, | |
103 file_okay=True, | |
104 dir_okay=False, | |
105 resolve_path=True | |
106 ), | |
107 help="Job configuration file for Galaxy to target.", | |
108 ) | |
109 | |
110 | |
111 def tool_dependency_dir_option(): | |
112 return click.option( | |
113 "--tool_dependency_dir", | |
114 type=click.Path( | |
115 exists=True, | |
116 file_okay=False, | |
117 dir_okay=True, | |
118 resolve_path=True | |
119 ), | |
120 help="Tool dependency dir for Galaxy to target.", | |
121 ) | |
122 | |
123 | |
124 def install_galaxy_option(): | |
125 return click.option( | |
126 "--install_galaxy", | |
127 is_flag=True, | |
128 help="Download and configure a disposable copy of Galaxy from github." | |
129 ) | |
130 | |
131 | |
132 def no_cache_galaxy_option(): | |
133 return click.option( | |
134 "--no_cache_galaxy", | |
135 is_flag=True, | |
136 help=("Skip caching of Galaxy source and dependencies obtained with " | |
137 "--install_galaxy. Not caching this results in faster " | |
138 "downloads (no git) - so is better on throw away instances such " | |
139 "with TravisCI. ") | |
140 ) | |
141 | |
142 | |
143 def brew_option(): | |
144 return click.option( | |
145 "--brew", | |
146 type=click.Path(exists=True, file_okay=True, dir_okay=False), | |
147 help="Homebrew 'brew' executable to use." | |
148 ) | |
149 | |
150 | |
151 def required_tool_arg(): | |
152 """ Decorate click method as requiring the path to a single tool. | |
153 """ | |
154 arg_type = click.Path( | |
155 exists=True, | |
156 file_okay=True, | |
157 dir_okay=False, | |
158 readable=True, | |
159 resolve_path=True, | |
160 ) | |
161 return click.argument("path", metavar="TOOL_PATH", type=arg_type) | |
162 | |
163 | |
164 def _optional_tools_default(ctx, param, value): | |
165 if param.name == "paths" and len(value) == 0: | |
166 return [os.path.abspath(os.getcwd())] | |
167 else: | |
168 return value | |
169 | |
170 | |
171 def optional_tools_arg(multiple=False): | |
172 """ Decorate click method as optionally taking in the path to a tool | |
173 or directory of tools. If no such argument is given the current working | |
174 directory will be treated as a directory of tools. | |
175 """ | |
176 arg_type = click.Path( | |
177 exists=True, | |
178 file_okay=True, | |
179 dir_okay=True, | |
180 readable=True, | |
181 resolve_path=True, | |
182 ) | |
183 name = "paths" if multiple else "path" | |
184 nargs = -1 if multiple else 1 | |
185 return click.argument( | |
186 name, | |
187 metavar="TOOL_PATH", | |
188 type=arg_type, | |
189 nargs=nargs, | |
190 callback=_optional_tools_default, | |
191 ) | |
192 | |
193 | |
194 class ProjectOrRepositry(click.Path): | |
195 | |
196 def __init__(self, **kwds): | |
197 super(ProjectOrRepositry, self).__init__(**kwds) | |
198 | |
199 def convert(self, value, param, ctx): | |
200 if value and value.startswith("git:") or value.startswith("git+"): | |
201 return value | |
202 else: | |
203 return super(ProjectOrRepositry, self).convert(value, param, ctx) | |
204 | |
205 | |
206 def shed_project_arg(multiple=True): | |
207 arg_type = ProjectOrRepositry( | |
208 exists=True, | |
209 file_okay=False, | |
210 dir_okay=True, | |
211 writable=True, | |
212 resolve_path=True, | |
213 ) | |
214 name = "paths" if multiple else "path" | |
215 nargs = -1 if multiple else 1 | |
216 return click.argument( | |
217 name, | |
218 metavar="PROJECT", | |
219 default=".", | |
220 type=arg_type, | |
221 nargs=nargs, | |
222 callback=_optional_tools_default, | |
223 ) | |
224 | |
225 | |
226 def optional_project_arg(exists=True): | |
227 arg_type = click.Path( | |
228 exists=exists, | |
229 file_okay=False, | |
230 dir_okay=True, | |
231 writable=True, | |
232 resolve_path=True, | |
233 ) | |
234 return click.argument( | |
235 "path", | |
236 metavar="PROJECT", | |
237 default=".", | |
238 type=arg_type | |
239 ) | |
240 | |
241 | |
242 def no_cleanup_option(): | |
243 return click.option( | |
244 "--no_cleanup", | |
245 is_flag=True, | |
246 help=("Do not cleanup temp files created for and by Galaxy.") | |
247 ) | |
248 | |
249 | |
250 def docker_cmd_option(): | |
251 return click.option( | |
252 "--docker_cmd", | |
253 default=docker_util.DEFAULT_DOCKER_COMMAND, | |
254 help="Command used to launch docker (defaults to docker)." | |
255 ) | |
256 | |
257 | |
258 def docker_sudo_option(): | |
259 return click.option( | |
260 "--docker_sudo", | |
261 is_flag=True, | |
262 help="Flag to use sudo when running docker." | |
263 ) | |
264 | |
265 | |
266 def docker_sudo_cmd_option(): | |
267 return click.option( | |
268 "--docker_sudo_cmd", | |
269 default=None, | |
270 help="sudo command to use when --docker_sudo is enabled " + | |
271 "(defaults to sudo).", | |
272 callback=get_default_callback(docker_util.DEFAULT_SUDO_COMMAND), | |
273 ) | |
274 | |
275 | |
276 def docker_host_option(): | |
277 return click.option( | |
278 "--docker_host", | |
279 default=None, | |
280 help="Docker host to target when executing docker commands " + | |
281 "(defaults to localhost).", | |
282 callback=get_default_callback(docker_util.DEFAULT_HOST), | |
283 ) | |
284 | |
285 | |
286 def shed_owner_option(): | |
287 return click.option( | |
288 "--owner", | |
289 help="Tool Shed repository owner (username)." | |
290 ) | |
291 | |
292 | |
293 def shed_name_option(): | |
294 return click.option( | |
295 "--name", | |
296 help="Tool Shed repository name (defaults to the inferred " | |
297 "tool directory name)." | |
298 ) | |
299 | |
300 | |
301 def validate_shed_target_callback(ctx, param, value): | |
302 target = get_default_callback("toolshed")(ctx, param, value) | |
303 if target is None: | |
304 ctx.fail("default_shed_target set to None, must specify a value for " | |
305 "--shed_target to run this command.") | |
306 return target | |
307 | |
308 | |
309 def shed_target_option(): | |
310 return click.option( | |
311 "-t", | |
312 "--shed_target", | |
313 help="Tool Shed to target (this can be 'toolshed', 'testtoolshed', " | |
314 "'local' (alias for http://localhost:9009/), an arbitrary url " | |
315 "or mappings defined ~/.planemo.yml.", | |
316 default=None, | |
317 callback=validate_shed_target_callback, | |
318 ) | |
319 | |
320 | |
321 def shed_key_option(): | |
322 return click.option( | |
323 "--shed_key", | |
324 help=("API key for Tool Shed access. An API key is required unless " | |
325 "e-mail and password is specified. This key can be specified " | |
326 "with either --shed_key or --shed_key_from_env.") | |
327 ) | |
328 | |
329 | |
330 def shed_key_from_env_option(): | |
331 return click.option( | |
332 "--shed_key_from_env", | |
333 help="Environment variable to read API key for Tool Shed access from." | |
334 ) | |
335 | |
336 | |
337 def shed_email_option(): | |
338 return click.option( | |
339 "--shed_email", | |
340 help="E-mail for Tool Shed auth (required unless shed_key is " | |
341 "specified)." | |
342 ) | |
343 | |
344 | |
345 def shed_password_option(): | |
346 return click.option( | |
347 "--shed_password", | |
348 help="Password for Tool Shed auth (required unless shed_key is " | |
349 "specified)." | |
350 ) | |
351 | |
352 | |
353 def shed_skip_upload(): | |
354 return click.option( | |
355 "--skip_upload", | |
356 is_flag=True, | |
357 help=("Skip upload contents as part of operation, only update " | |
358 "metadata.") | |
359 ) | |
360 | |
361 | |
362 def shed_skip_metadata(): | |
363 return click.option( | |
364 "--skip_metadata", | |
365 is_flag=True, | |
366 help=("Skip metadata update as part of operation, only upload " | |
367 "new contents.") | |
368 ) | |
369 | |
370 | |
371 def shed_message_option(): | |
372 return click.option( | |
373 "-m", | |
374 "--message", | |
375 help="Commit message for tool shed upload." | |
376 ) | |
377 | |
378 | |
379 def shed_force_create_option(): | |
380 return click.option( | |
381 "--force_repository_creation", | |
382 help=("If a repository cannot be found for the specified user/repo " | |
383 "name pair, then automatically create the repository in the " | |
384 "toolshed."), | |
385 is_flag=True, | |
386 default=False | |
387 ) | |
388 | |
389 | |
390 def shed_check_diff_option(): | |
391 return click.option( | |
392 "--check_diff", | |
393 is_flag=True, | |
394 help=("Skip uploading if the shed_diff detects there would be no " | |
395 "'difference' (only attributes populated by the shed would " | |
396 "be updated.)") | |
397 ) | |
398 | |
399 | |
400 def shed_upload_options(): | |
401 return _compose( | |
402 shed_message_option(), | |
403 shed_force_create_option(), | |
404 shed_check_diff_option(), | |
405 ) | |
406 | |
407 | |
408 def shed_realization_options(): | |
409 return _compose( | |
410 shed_project_arg(multiple=True), | |
411 recursive_shed_option(), | |
412 shed_fail_fast_option(), | |
413 ) | |
414 | |
415 | |
416 def shed_repo_options(): | |
417 return _compose( | |
418 shed_owner_option(), | |
419 shed_name_option(), | |
420 ) | |
421 | |
422 | |
423 def shed_publish_options(): | |
424 """ Common options for commands that require publishing to a | |
425 a shed. | |
426 """ | |
427 return _compose( | |
428 shed_realization_options(), | |
429 shed_repo_options(), | |
430 shed_target_options(), | |
431 ) | |
432 | |
433 | |
434 def shed_read_options(): | |
435 """ Common options that require read access to mapped repositories | |
436 in a shed. | |
437 """ | |
438 return _compose( | |
439 shed_realization_options(), | |
440 shed_repo_options(), | |
441 shed_target_options(), | |
442 ) | |
443 | |
444 | |
445 def shed_target_options(): | |
446 """ Common options for commands that require read-only | |
447 interactions with a shed. | |
448 """ | |
449 return _compose( | |
450 shed_email_option(), | |
451 shed_key_option(), | |
452 shed_key_from_env_option(), | |
453 shed_password_option(), | |
454 shed_target_option(), | |
455 ) | |
456 | |
457 | |
458 def galaxy_run_options(): | |
459 return _compose( | |
460 galaxy_target_options(), | |
461 galaxy_port_option(), | |
462 galaxy_host_option(), | |
463 ) | |
464 | |
465 | |
466 def galaxy_config_options(): | |
467 return _compose( | |
468 test_data_option(), | |
469 tool_data_table_option(), | |
470 dependency_resolvers_option(), | |
471 tool_dependency_dir_option(), | |
472 brew_dependency_resolution(), | |
473 shed_dependency_resolution(), | |
474 ) | |
475 | |
476 | |
477 def galaxy_target_options(): | |
478 return _compose( | |
479 galaxy_root_option(), | |
480 install_galaxy_option(), | |
481 no_cache_galaxy_option(), | |
482 no_cleanup_option(), | |
483 job_config_option(), | |
484 ) | |
485 | |
486 | |
487 def galaxy_serve_options(): | |
488 return _compose( | |
489 galaxy_run_options(), | |
490 galaxy_config_options(), | |
491 ) | |
492 | |
493 | |
494 def shed_fail_fast_option(): | |
495 return click.option( | |
496 "--fail_fast", | |
497 is_flag=True, | |
498 default=False, | |
499 help="If multiple repositories are specified and an error occurs " | |
500 "stop immediately instead of processing remaining repositories." | |
501 ) | |
502 | |
503 | |
504 def lint_xsd_option(): | |
505 return click.option( | |
506 "--xsd", | |
507 is_flag=True, | |
508 default=False, | |
509 help=("Include experimental tool XSD validation in linting " | |
510 "process (requires xmllint on PATH or lxml installed).") | |
511 ) | |
512 | |
513 | |
514 def report_level_option(): | |
515 return click.option( | |
516 "--report_level", | |
517 type=click.Choice(["all", "warn", "error"]), | |
518 default="all", | |
519 ) | |
520 | |
521 | |
522 def skip_option(): | |
523 return click.option( | |
524 "-s", | |
525 "--skip", | |
526 default=None, | |
527 help=("Comma-separated list of lint tests to skip (e.g send ." | |
528 "--skip 'citations,xml_order' to skip linting of citations " | |
529 "and best-practice XML ordering.") | |
530 ) | |
531 | |
532 | |
533 def fail_level_option(): | |
534 return click.option( | |
535 "--fail_level", | |
536 type=click.Choice(['warn', 'error']), | |
537 default="warn" | |
538 ) | |
539 | |
540 | |
541 def recursive_shed_option(): | |
542 return recursive_option( | |
543 "Recursively perform command for nested repository directories.", | |
544 ) | |
545 | |
546 | |
547 def recursive_option(help="Recursively perform command for subdirectories."): | |
548 return click.option( | |
549 "-r", | |
550 "--recursive", | |
551 is_flag=True, | |
552 help=help, | |
553 ) | |
554 | |
555 | |
556 def test_options(): | |
557 return _compose( | |
558 click.option( | |
559 "--update_test_data", | |
560 is_flag=True, | |
561 help="Update test-data directory with job outputs (normally" | |
562 " written to directory --job_output_files if specified.)" | |
563 ), | |
564 click.option( | |
565 "--test_output", | |
566 type=click.Path(file_okay=True, resolve_path=True), | |
567 callback=get_default_callback("tool_test_output.html"), | |
568 help=("Output test report (HTML - for humans) defaults to " | |
569 "tool_test_output.html."), | |
570 default=None, | |
571 ), | |
572 click.option( | |
573 "--test_output_text", | |
574 type=click.Path(file_okay=True, resolve_path=True), | |
575 callback=get_default_callback(None), | |
576 help=("Output test report (Basic text - for display in CI)"), | |
577 default=None, | |
578 ), | |
579 click.option( | |
580 "--test_output_markdown", | |
581 type=click.Path(file_okay=True, resolve_path=True), | |
582 callback=get_default_callback(None), | |
583 help=("Output test report (Markdown style - for humans & " | |
584 "computers)"), | |
585 default=None, | |
586 ), | |
587 click.option( | |
588 "--test_output_xunit", | |
589 type=click.Path(file_okay=True, resolve_path=True), | |
590 callback=get_default_callback(None), | |
591 help="Output test report (xUnit style - for computers).", | |
592 default=None, | |
593 ), | |
594 click.option( | |
595 "--test_output_json", | |
596 type=click.Path(file_okay=True, resolve_path=True), | |
597 callback=get_default_callback("tool_test_output.json"), | |
598 help=("Output test report (planemo json) defaults to " | |
599 "tool_test_output.json."), | |
600 default=None, | |
601 ), | |
602 click.option( | |
603 "--job_output_files", | |
604 type=click.Path(file_okay=False, resolve_path=True), | |
605 help="Write job outputs to specified directory.", | |
606 default=None, | |
607 ), | |
608 click.option( | |
609 "--summary", | |
610 type=click.Choice(["none", "minimal", "compact"]), | |
611 default="minimal", | |
612 help=("Summary style printed to planemo's standard output (see " | |
613 "output reports for more complete summary). Set to 'none' " | |
614 "to disable completely.") | |
615 ) | |
616 ) | |
617 | |
618 | |
619 def _compose(*functions): | |
620 def compose2(f, g): | |
621 return lambda x: f(g(x)) | |
622 return functools.reduce(compose2, functions) | |
623 | |
624 | |
625 def dependencies_script_options(): | |
626 return _compose( | |
627 click.option( | |
628 "--download_cache", | |
629 type=click.Path(file_okay=False, resolve_path=True), | |
630 callback=get_default_callback(None), | |
631 help=("Directory to cache downloaded files, default is $DOWNLOAD_CACHE"), | |
632 default=None, | |
633 ), | |
634 ) |