Mercurial > repos > fubar > tool_factory_2
comparison toolfactory/galaxyxml/tool/parameters/__init__.py @ 38:a30536c100bf draft
Updated history outputs
author | fubar |
---|---|
date | Wed, 12 Aug 2020 01:43:46 -0400 |
parents | ce2b1f8ea68d |
children |
comparison
equal
deleted
inserted
replaced
37:099047ee7094 | 38:a30536c100bf |
---|---|
1 from builtins import object | |
1 from builtins import str | 2 from builtins import str |
2 from builtins import object | 3 |
4 from galaxyxml import Util | |
5 | |
3 from lxml import etree | 6 from lxml import etree |
4 from galaxyxml import Util | 7 |
5 | 8 |
6 | 9 |
7 class XMLParam(object): | 10 class XMLParam(object): |
8 name = "node" | 11 name = "node" |
9 | 12 |
21 if issubclass(type(sub_node), XMLParam): | 24 if issubclass(type(sub_node), XMLParam): |
22 self.node.append(sub_node.node) | 25 self.node.append(sub_node.node) |
23 self.children.append(sub_node) | 26 self.children.append(sub_node) |
24 else: | 27 else: |
25 raise Exception( | 28 raise Exception( |
26 "Child was unacceptable to parent (%s is not appropriate for %s)" | 29 "Child was unacceptable to parent (%s is not appropriate for %s)" % (type(self), type(sub_node)) |
27 % (type(self), type(sub_node)) | |
28 ) | 30 ) |
29 else: | 31 else: |
30 raise Exception( | 32 raise Exception( |
31 "Child was unacceptable to parent (%s is not appropriate for %s)" | 33 "Child was unacceptable to parent (%s is not appropriate for %s)" % (type(self), type(sub_node)) |
32 % (type(self), type(sub_node)) | |
33 ) | 34 ) |
34 | 35 |
35 def validate(self): | 36 def validate(self): |
36 # Very few need validation, but some nodes we may want to have | 37 # Very few need validation, but some nodes we may want to have |
37 # validation routines on. Should only be called when DONE. | 38 # validation routines on. Should only be called when DONE. |
153 class Requirements(XMLParam): | 154 class Requirements(XMLParam): |
154 name = "requirements" | 155 name = "requirements" |
155 # This bodes to be an issue -__- | 156 # This bodes to be an issue -__- |
156 | 157 |
157 def acceptable_child(self, child): | 158 def acceptable_child(self, child): |
158 return issubclass(type(child), Requirement) or issubclass( | 159 return issubclass(type(child), Requirement) or issubclass(type(child), Container) |
159 type(child), Container | |
160 ) | |
161 | 160 |
162 | 161 |
163 class Requirement(XMLParam): | 162 class Requirement(XMLParam): |
164 name = "requirement" | 163 name = "requirement" |
165 | 164 |
185 | 184 |
186 class Configfiles(XMLParam): | 185 class Configfiles(XMLParam): |
187 name = "configfiles" | 186 name = "configfiles" |
188 | 187 |
189 def acceptable_child(self, child): | 188 def acceptable_child(self, child): |
190 return issubclass(type(child), Configfile) or issubclass( | 189 return issubclass(type(child), Configfile) or issubclass(type(child), ConfigfileDefaultInputs) |
191 type(child), ConfigfileDefaultInputs | |
192 ) | |
193 | 190 |
194 | 191 |
195 class Configfile(XMLParam): | 192 class Configfile(XMLParam): |
196 name = "configfile" | 193 name = "configfile" |
197 | 194 |
215 | 212 |
216 class Inputs(XMLParam): | 213 class Inputs(XMLParam): |
217 name = "inputs" | 214 name = "inputs" |
218 # This bodes to be an issue -__- | 215 # This bodes to be an issue -__- |
219 | 216 |
220 def __init__( | 217 def __init__(self, action=None, check_value=None, method=None, target=None, nginx_upload=None, **kwargs): |
221 self, | |
222 action=None, | |
223 check_value=None, | |
224 method=None, | |
225 target=None, | |
226 nginx_upload=None, | |
227 **kwargs, | |
228 ): | |
229 params = Util.clean_kwargs(locals().copy()) | 218 params = Util.clean_kwargs(locals().copy()) |
230 super(Inputs, self).__init__(**params) | 219 super(Inputs, self).__init__(**params) |
231 | 220 |
232 def acceptable_child(self, child): | 221 def acceptable_child(self, child): |
233 return issubclass(type(child), InputParameter) | 222 return issubclass(type(child), InputParameter) |
260 # https://wiki.galaxyproject.org/Tools/BestPractices#Parameter_help | 249 # https://wiki.galaxyproject.org/Tools/BestPractices#Parameter_help |
261 if "label" in kwargs: | 250 if "label" in kwargs: |
262 # TODO: replace with positional attribute | 251 # TODO: replace with positional attribute |
263 if len(self.flag()) > 0: | 252 if len(self.flag()) > 0: |
264 if kwargs["label"] is None: | 253 if kwargs["label"] is None: |
265 kwargs[ | 254 kwargs["label"] = "Author did not provide help for this parameter... " |
266 "label" | |
267 ] = "Author did not provide help for this parameter... " | |
268 if not self.positional: | 255 if not self.positional: |
269 kwargs["argument"] = self.flag() | 256 kwargs["argument"] = self.flag() |
270 | 257 |
271 super(InputParameter, self).__init__(**kwargs) | 258 super(InputParameter, self).__init__(**kwargs) |
272 | 259 |
295 return self.command_line_override | 282 return self.command_line_override |
296 except Exception: | 283 except Exception: |
297 if self.positional: | 284 if self.positional: |
298 return self.mako_name() | 285 return self.mako_name() |
299 else: | 286 else: |
300 return "%s%s%s" % ( | 287 return "%s%s%s" % (self.flag(), self.space_between_arg, self.mako_name()) |
301 self.flag(), | |
302 self.space_between_arg, | |
303 self.mako_name(), | |
304 ) | |
305 | 288 |
306 def mako_name(self): | 289 def mako_name(self): |
307 # TODO: enhance logic to check up parents for things like | 290 # TODO: enhance logic to check up parents for things like |
308 # repeat>condotion>param | 291 # repeat>condotion>param |
309 return "$" + self.mako_identifier | 292 return "$" + self.mako_identifier |
351 def __init__(self, name, **kwargs): | 334 def __init__(self, name, **kwargs): |
352 params = Util.clean_kwargs(locals().copy()) | 335 params = Util.clean_kwargs(locals().copy()) |
353 super(Conditional, self).__init__(**params) | 336 super(Conditional, self).__init__(**params) |
354 | 337 |
355 def acceptable_child(self, child): | 338 def acceptable_child(self, child): |
356 return issubclass(type(child), InputParameter) and not isinstance( | 339 return issubclass(type(child), InputParameter) and not isinstance(child, Conditional) |
357 child, Conditional | |
358 ) | |
359 | 340 |
360 def validate(self): | 341 def validate(self): |
361 # Find a way to check if one of the kids is a WHEN | 342 # Find a way to check if one of the kids is a WHEN |
362 pass | 343 pass |
363 | 344 |
381 params = Util.clean_kwargs(locals().copy()) | 362 params = Util.clean_kwargs(locals().copy()) |
382 params["type"] = self.type | 363 params["type"] = self.type |
383 super(Param, self).__init__(**params) | 364 super(Param, self).__init__(**params) |
384 | 365 |
385 if type(self) == Param: | 366 if type(self) == Param: |
386 raise Exception( | 367 raise Exception("Param class is not an actual parameter type, use a subclass of Param") |
387 "Param class is not an actual parameter type, use a subclass of Param" | 368 |
388 ) | 369 def acceptable_child(self, child): |
389 | 370 return issubclass(type(child, InputParameter) or isinstance(child), ValidatorParam) |
390 def acceptable_child(self, child): | |
391 return issubclass( | |
392 type(child, InputParameter) or isinstance(child), ValidatorParam | |
393 ) | |
394 | 371 |
395 | 372 |
396 class TextParam(Param): | 373 class TextParam(Param): |
397 type = "text" | 374 type = "text" |
398 | 375 |
399 def __init__( | 376 def __init__(self, name, optional=None, label=None, help=None, value=None, **kwargs): |
400 self, name, optional=None, label=None, help=None, value=None, **kwargs | |
401 ): | |
402 params = Util.clean_kwargs(locals().copy()) | 377 params = Util.clean_kwargs(locals().copy()) |
403 super(TextParam, self).__init__(**params) | 378 super(TextParam, self).__init__(**params) |
404 | 379 |
405 def command_line_actual(self): | 380 def command_line_actual(self): |
406 try: | 381 try: |
411 else: | 386 else: |
412 return f"{self.flag}{self.space_between_arg}'{self.mako_name()}'" | 387 return f"{self.flag}{self.space_between_arg}'{self.mako_name()}'" |
413 | 388 |
414 | 389 |
415 class _NumericParam(Param): | 390 class _NumericParam(Param): |
416 def __init__( | 391 def __init__(self, name, value, optional=None, label=None, help=None, min=None, max=None, **kwargs): |
417 self, | |
418 name, | |
419 value, | |
420 optional=None, | |
421 label=None, | |
422 help=None, | |
423 min=None, | |
424 max=None, | |
425 **kwargs, | |
426 ): | |
427 params = Util.clean_kwargs(locals().copy()) | 392 params = Util.clean_kwargs(locals().copy()) |
428 super(_NumericParam, self).__init__(**params) | 393 super(_NumericParam, self).__init__(**params) |
429 | 394 |
430 | 395 |
431 class IntegerParam(_NumericParam): | 396 class IntegerParam(_NumericParam): |
438 | 403 |
439 class BooleanParam(Param): | 404 class BooleanParam(Param): |
440 type = "boolean" | 405 type = "boolean" |
441 | 406 |
442 def __init__( | 407 def __init__( |
443 self, | 408 self, name, optional=None, label=None, help=None, checked=False, truevalue=None, falsevalue=None, **kwargs |
444 name, | |
445 optional=None, | |
446 label=None, | |
447 help=None, | |
448 checked=False, | |
449 truevalue=None, | |
450 falsevalue=None, | |
451 **kwargs, | |
452 ): | 409 ): |
453 params = Util.clean_kwargs(locals().copy()) | 410 params = Util.clean_kwargs(locals().copy()) |
454 | 411 |
455 super(BooleanParam, self).__init__(**params) | 412 super(BooleanParam, self).__init__(**params) |
456 if truevalue is None: | 413 if truevalue is None: |
475 | 432 |
476 | 433 |
477 class DataParam(Param): | 434 class DataParam(Param): |
478 type = "data" | 435 type = "data" |
479 | 436 |
480 def __init__( | 437 def __init__(self, name, optional=None, label=None, help=None, format=None, multiple=None, **kwargs): |
481 self, | |
482 name, | |
483 optional=None, | |
484 label=None, | |
485 help=None, | |
486 format=None, | |
487 multiple=None, | |
488 **kwargs, | |
489 ): | |
490 params = Util.clean_kwargs(locals().copy()) | 438 params = Util.clean_kwargs(locals().copy()) |
491 super(DataParam, self).__init__(**params) | 439 super(DataParam, self).__init__(**params) |
492 | 440 |
493 | 441 |
494 class SelectParam(Param): | 442 class SelectParam(Param): |
503 data_ref=None, | 451 data_ref=None, |
504 display=None, | 452 display=None, |
505 multiple=None, | 453 multiple=None, |
506 options=None, | 454 options=None, |
507 default=None, | 455 default=None, |
508 **kwargs, | 456 **kwargs |
509 ): | 457 ): |
510 params = Util.clean_kwargs(locals().copy()) | 458 params = Util.clean_kwargs(locals().copy()) |
511 del params["options"] | 459 del params["options"] |
512 del params["default"] | 460 del params["default"] |
513 | 461 |
542 | 490 |
543 | 491 |
544 class Options(InputParameter): | 492 class Options(InputParameter): |
545 name = "options" | 493 name = "options" |
546 | 494 |
547 def __init__( | 495 def __init__(self, from_dataset=None, from_file=None, from_data_table=None, from_parameter=None, **kwargs): |
548 self, | |
549 from_dataset=None, | |
550 from_file=None, | |
551 from_data_table=None, | |
552 from_parameter=None, | |
553 **kwargs, | |
554 ): | |
555 params = Util.clean_kwargs(locals().copy()) | 496 params = Util.clean_kwargs(locals().copy()) |
556 super(Options, self).__init__(None, **params) | 497 super(Options, self).__init__(None, **params) |
557 | 498 |
558 def acceptable_child(self, child): | 499 def acceptable_child(self, child): |
559 return issubclass(type(child), Column) or issubclass(type(child), Filter) | 500 return issubclass(type(child), Column) or issubclass(type(child), Filter) |
581 separator=None, | 522 separator=None, |
582 keep=None, | 523 keep=None, |
583 value=None, | 524 value=None, |
584 ref_attribute=None, | 525 ref_attribute=None, |
585 index=None, | 526 index=None, |
586 **kwargs, | 527 **kwargs |
587 ): | 528 ): |
588 params = Util.clean_kwargs(locals().copy()) | 529 params = Util.clean_kwargs(locals().copy()) |
589 super(Filter, self).__init__(**params) | 530 super(Filter, self).__init__(**params) |
590 | 531 |
591 | 532 |
600 metadata_name=None, | 541 metadata_name=None, |
601 metadata_column=None, | 542 metadata_column=None, |
602 line_startswith=None, | 543 line_startswith=None, |
603 min=None, | 544 min=None, |
604 max=None, | 545 max=None, |
605 **kwargs, | 546 **kwargs |
606 ): | 547 ): |
607 params = Util.clean_kwargs(locals().copy()) | 548 params = Util.clean_kwargs(locals().copy()) |
608 super(ValidatorParam, self).__init__(**params) | 549 super(ValidatorParam, self).__init__(**params) |
609 | 550 |
610 | 551 |
628 format_source=None, | 569 format_source=None, |
629 metadata_source=None, | 570 metadata_source=None, |
630 label=None, | 571 label=None, |
631 from_work_dir=None, | 572 from_work_dir=None, |
632 hidden=False, | 573 hidden=False, |
633 **kwargs, | 574 **kwargs |
634 ): | 575 ): |
635 # TODO: validate format_source&metadata_source against something in the | 576 # TODO: validate format_source&metadata_source against something in the |
636 # XMLParam children tree. | 577 # XMLParam children tree. |
637 self.mako_identifier = name | 578 self.mako_identifier = name |
638 if "num_dashes" in kwargs: | 579 if "num_dashes" in kwargs: |
657 def flag(self): | 598 def flag(self): |
658 flag = "-" * self.num_dashes | 599 flag = "-" * self.num_dashes |
659 return flag + self.mako_identifier | 600 return flag + self.mako_identifier |
660 | 601 |
661 def acceptable_child(self, child): | 602 def acceptable_child(self, child): |
662 return ( | 603 return isinstance(child, OutputFilter) or isinstance(child, ChangeFormat) or isinstance(child, DiscoverDatasets) |
663 isinstance(child, OutputFilter) | |
664 or isinstance(child, ChangeFormat) | |
665 or isinstance(child, DiscoverDatasets) | |
666 ) | |
667 | 604 |
668 | 605 |
669 class OutputFilter(XMLParam): | 606 class OutputFilter(XMLParam): |
670 name = "filter" | 607 name = "filter" |
671 | 608 |
711 label=None, | 648 label=None, |
712 format_source=None, | 649 format_source=None, |
713 type_source=None, | 650 type_source=None, |
714 structured_like=None, | 651 structured_like=None, |
715 inherit_format=None, | 652 inherit_format=None, |
716 **kwargs, | 653 **kwargs |
717 ): | 654 ): |
718 params = Util.clean_kwargs(locals().copy()) | 655 params = Util.clean_kwargs(locals().copy()) |
719 super(OutputCollection, self).__init__(**params) | 656 super(OutputCollection, self).__init__(**params) |
720 | 657 |
721 def acceptable_child(self, child): | 658 def acceptable_child(self, child): |
722 return ( | 659 return isinstance(child, OutputData) or isinstance(child, OutputFilter) or isinstance(child, DiscoverDatasets) |
723 isinstance(child, OutputData) | |
724 or isinstance(child, OutputFilter) | |
725 or isinstance(child, DiscoverDatasets) | |
726 ) | |
727 | 660 |
728 | 661 |
729 class DiscoverDatasets(XMLParam): | 662 class DiscoverDatasets(XMLParam): |
730 name = "discover_datasets" | 663 name = "discover_datasets" |
731 | 664 |
732 def __init__( | 665 def __init__(self, pattern, directory=None, format=None, ext=None, visible=None, **kwargs): |
733 self, pattern, directory=None, format=None, ext=None, visible=None, **kwargs | |
734 ): | |
735 params = Util.clean_kwargs(locals().copy()) | 666 params = Util.clean_kwargs(locals().copy()) |
736 super(DiscoverDatasets, self).__init__(**params) | 667 super(DiscoverDatasets, self).__init__(**params) |
737 | 668 |
738 | 669 |
739 class Tests(XMLParam): | 670 class Tests(XMLParam): |
771 md5=None, | 702 md5=None, |
772 checksum=None, | 703 checksum=None, |
773 compare=None, | 704 compare=None, |
774 lines_diff=None, | 705 lines_diff=None, |
775 delta=None, | 706 delta=None, |
776 **kwargs, | 707 **kwargs |
777 ): | 708 ): |
778 params = Util.clean_kwargs(locals().copy()) | 709 params = Util.clean_kwargs(locals().copy()) |
779 super(TestOutput, self).__init__(**params) | 710 super(TestOutput, self).__init__(**params) |
780 | 711 |
781 | 712 |