diff --git a/examples/tool.xml b/examples/tool.xml index 2347717..9e11993 100644 --- a/examples/tool.xml +++ b/examples/tool.xml @@ -5,10 +5,6 @@ samtools one_super_image - - - - loaded.") - def _load_command(self, tool, desc_root): + def _load_command(self, tool, command_root): """ - is already loaded during initiation. - :param tool: Tool object from galaxyxml. :type tool: :class:`galaxyxml.tool.Tool` :param desc_root: root of tag. :type desc_root: :class:`xml.etree._Element` """ - logger.info(" is loaded during initiation of the object.") + try: + detect_errors = command_root.attrib['detect_errors'] + except KeyError: + detect_errors = None + ctext = command_root.text + command = gxtp.Command(detect_errors=detect_errors) + command.node.text = ctext + tool.command_line = ctext + tool.command = command + tool.executable = ctext.split()[0] def _load_help(self, tool, help_root): """ @@ -727,11 +732,12 @@ def _load_element(self, test_root, element_root): :param repeat_root: root of tag. :param repeat_root: :class:`xml.etree._Element` """ - test_root.append(gxtp.TestOCElement( - name=element_root.attrib.get("name", None), - ftype=element_root.attrib.get("ftype", None), - file=element_root.attrib.get("file", None) - ) + test_root.append( + gxtp.TestOCElement( + name=element_root.attrib.get("name", None), + ftype=element_root.attrib.get("ftype", None), + file=element_root.attrib.get("file", None), + ) ) def _load_repeat(self, test_root, repeat_root): @@ -747,7 +753,7 @@ def _load_repeat(self, test_root, repeat_root): repeat_root.attrib.get("title", None), min=repeat_root.attrib.get("min", None), max=repeat_root.attrib.get("max", None), - default=repeat_root.attrib.get("default", None) + default=repeat_root.attrib.get("default", None), ) # Deal with child nodes self.load_inputs(repeat, repeat_root) diff --git a/galaxyxml/tool/parameters/__init__.py b/galaxyxml/tool/parameters/__init__.py index ee9e647..04c0b53 100644 --- a/galaxyxml/tool/parameters/__init__.py +++ b/galaxyxml/tool/parameters/__init__.py @@ -1,9 +1,5 @@ import logging -from builtins import ( - object, - str -) - +from builtins import (object, str) from galaxy.tool_util.parser.util import _parse_name from galaxyxml import Util @@ -79,6 +75,14 @@ def command_line(self, mako_path=None): return None +class Command(XMLParam): + name = "command" + + def __init__(self, detect_errors=None, **kwargs): + params = Util.clean_kwargs(locals().copy()) + super(Command, self).__init__(**params) + + class Stdios(XMLParam): name = "stdio" @@ -129,6 +133,7 @@ class Expand(XMLParam): """ """ + name = "expand" def __init__(self, macro): @@ -151,6 +156,7 @@ class ExpandIO(Expand): but an additional token with the same name but in upper case is added to the command section. can only be used in Inputs and Outputs """ + name = "expand" def __init__(self, macro): @@ -170,8 +176,7 @@ def __init__(self, **kwargs): self.node = etree.Element(self.name) def acceptable_child(self, child): - return isinstance(child, RequestParamTranslation) \ - or isinstance(child, Expand) + return isinstance(child, RequestParamTranslation) or isinstance(child, Expand) class RequestParam(XMLParam): @@ -185,8 +190,7 @@ def __init__(self, galaxy_name, remote_name, missing, **kwargs): super(RequestParam, self).__init__(**params) def acceptable_child(self, child): - return isinstance(child, AppendParam) and self.galaxy_name == "URL" \ - or isinstance(child, Expand) + return isinstance(child, AppendParam) and self.galaxy_name == "URL" or isinstance(child, Expand) class AppendParam(XMLParam): @@ -215,8 +219,7 @@ class EdamOperations(XMLParam): name = "edam_operations" def acceptable_child(self, child): - return issubclass(type(child), EdamOperation) \ - or isinstance(child, Expand) + return issubclass(type(child), EdamOperation) or isinstance(child, Expand) def has_operation(self, edam_operation): """ @@ -242,8 +245,7 @@ class EdamTopics(XMLParam): name = "edam_topics" def acceptable_child(self, child): - return issubclass(type(child), EdamTopic) \ - or isinstance(child, Expand) + return issubclass(type(child), EdamTopic) or isinstance(child, Expand) def has_topic(self, edam_topic): """ @@ -270,9 +272,7 @@ class Requirements(XMLParam): # This bodes to be an issue -__- def acceptable_child(self, child): - return issubclass(type(child), Requirement) \ - or issubclass(type(child), Container) \ - or isinstance(child, Expand) + return issubclass(type(child), Requirement) or issubclass(type(child), Container) or isinstance(child, Expand) class Requirement(XMLParam): @@ -302,9 +302,11 @@ class Configfiles(XMLParam): name = "configfiles" def acceptable_child(self, child): - return issubclass(type(child), Configfile) \ - or issubclass(type(child), ConfigfileDefaultInputs) \ + return ( + issubclass(type(child), Configfile) + or issubclass(type(child), ConfigfileDefaultInputs) or isinstance(child, Expand) + ) class Configfile(XMLParam): @@ -337,18 +339,20 @@ def __init__(self, action=None, check_value=None, method=None, target=None, ngin super(Inputs, self).__init__(**params) def acceptable_child(self, child): - return issubclass(type(child), InputParameter) \ - or issubclass(type(child), Expand) \ + return ( + issubclass(type(child), InputParameter) + or issubclass(type(child), Expand) or issubclass(type(child), ExpandIO) + ) class InputParameter(XMLParam): def __init__(self, name, **kwargs): # TODO: look at - if "argument" in kwargs and kwargs['argument']: - self.flag_identifier = kwargs['argument'].lstrip() - self.num_dashes = len(kwargs['argument']) - len(self.flag_identifier) - self.mako_identifier = _parse_name(name, kwargs['argument']) + if "argument" in kwargs and kwargs["argument"]: + self.flag_identifier = kwargs["argument"].lstrip() + self.num_dashes = len(kwargs["argument"]) - len(self.flag_identifier) + self.mako_identifier = _parse_name(name, kwargs["argument"]) else: self.flag_identifier = name self.mako_identifier = name @@ -379,8 +383,8 @@ def __init__(self, name, **kwargs): if len(self.flag()) > 0: if kwargs["label"] is None: kwargs["label"] = "Author did not provide help for this parameter... " -# if not self.positional and "argument" not in kwargs: -# kwargs["argument"] = self.flag() + # if not self.positional and "argument" not in kwargs: + # kwargs["argument"] = self.flag() super(InputParameter, self).__init__(**kwargs) @@ -442,8 +446,7 @@ def command_line(self, mako_path=None): return "\n".join(cli) def acceptable_child(self, child): - return issubclass(type(child), InputParameter) \ - or isinstance(child, Expand) + return issubclass(type(child), InputParameter) or isinstance(child, Expand) class Repeat(InputParameter): @@ -460,8 +463,7 @@ def command_line_after(self): return "#end for" def acceptable_child(self, child): - return issubclass(type(child), InputParameter) \ - or isinstance(child, Expand) + return issubclass(type(child), InputParameter) or isinstance(child, Expand) def command_line_actual(self, mako_path): lines = [] @@ -486,7 +488,8 @@ def acceptable_child(self, child): return True else: return False -# return issubclass(type(child), InputParameter) and not isinstance(child, Conditional) + + # return issubclass(type(child), InputParameter) and not isinstance(child, Conditional) def command_line(self, mako_path=None): lines = [] @@ -495,7 +498,7 @@ def command_line(self, mako_path=None): continue lines.append('#if str(%s) == "%s"' % (self.children[0].mako_name(mako_path), c.value)) lines.append(c.cli()) - lines.append('#end if') + lines.append("#end if") return "\n".join(lines) def validate(self): @@ -511,8 +514,7 @@ def __init__(self, value): super(When, self).__init__(None, **params) def acceptable_child(self, child): - return issubclass(type(child), InputParameter) \ - or isinstance(child, Expand) + return issubclass(type(child), InputParameter) or isinstance(child, Expand) class Param(InputParameter): @@ -521,18 +523,16 @@ class Param(InputParameter): # This...isn't really valid as-is, and shouldn't be used. def __init__(self, name, argument=None, value=None, optional=None, label=None, help=None, **kwargs): params = Util.clean_kwargs(locals().copy()) - params = dict([("name", params["name"]), - ("argument", params["argument"]), - ("type", self.type)] + list(params.items())) + params = dict( + [("name", params["name"]), ("argument", params["argument"]), ("type", self.type)] + list(params.items()) + ) super(Param, self).__init__(**params) if type(self) == Param: raise Exception("Param class is not an actual parameter type, use a subclass of Param") def acceptable_child(self, child): - return issubclass(type(child), InputParameter) \ - or isinstance(child, ValidatorParam) \ - or isinstance(child, Expand) + return issubclass(type(child), InputParameter) or isinstance(child, ValidatorParam) or isinstance(child, Expand) class TextParam(Param): @@ -571,7 +571,16 @@ class BooleanParam(Param): type = "boolean" def __init__( - self, name, argument=None, optional=None, checked=False, truevalue=None, falsevalue=None, label=None, help=None, **kwargs + self, + name, + argument=None, + optional=None, + checked=False, + truevalue=None, + falsevalue=None, + label=None, + help=None, + **kwargs, ): params = Util.clean_kwargs(locals().copy()) @@ -638,9 +647,7 @@ def __init__( self.append(SelectOption(k, v, selected=selected)) def acceptable_child(self, child): - return issubclass(type(child), SelectOption) \ - or issubclass(type(child), Options) \ - or isinstance(child, Expand) + return issubclass(type(child), SelectOption) or issubclass(type(child), Options) or isinstance(child, Expand) class SelectOption(InputParameter): @@ -666,9 +673,7 @@ def __init__(self, from_dataset=None, from_file=None, from_data_table=None, from super(Options, self).__init__(None, **params) def acceptable_child(self, child): - return issubclass(type(child), Column) \ - or issubclass(type(child), Filter) \ - or isinstance(child, Expand) + return issubclass(type(child), Column) or issubclass(type(child), Filter) or isinstance(child, Expand) class Column(InputParameter): @@ -724,15 +729,16 @@ class Outputs(XMLParam): name = "outputs" def acceptable_child(self, child): - return isinstance(child, OutputData) \ - or isinstance(child, OutputCollection) \ - or isinstance(child, Expand) \ + return ( + isinstance(child, OutputData) + or isinstance(child, OutputCollection) + or isinstance(child, Expand) or isinstance(child, ExpandIO) + ) class OutputData(XMLParam): - """Copypasta of InputParameter, needs work - """ + """Copypasta of InputParameter, needs work""" name = "data" @@ -774,10 +780,12 @@ def flag(self): return flag + self.mako_identifier def acceptable_child(self, child): - return isinstance(child, OutputFilter) \ - or isinstance(child, ChangeFormat) \ - or isinstance(child, DiscoverDatasets) \ + return ( + isinstance(child, OutputFilter) + or isinstance(child, ChangeFormat) + or isinstance(child, DiscoverDatasets) or isinstance(child, Expand) + ) class OutputFilter(XMLParam): @@ -801,8 +809,7 @@ def __init__(self, **kwargs): super(ChangeFormat, self).__init__(**params) def acceptable_child(self, child): - return isinstance(child, ChangeFormatWhen) \ - or isinstance(child, Expand) + return isinstance(child, ChangeFormatWhen) or isinstance(child, Expand) class ChangeFormatWhen(XMLParam): @@ -861,19 +868,20 @@ class Tests(XMLParam): name = "tests" def acceptable_child(self, child): - return issubclass(type(child), Test) \ - or isinstance(child, Expand) + return issubclass(type(child), Test) or isinstance(child, Expand) class Test(XMLParam): name = "test" def acceptable_child(self, child): - return isinstance(child, TestParam) \ - or isinstance(child, TestOutput) \ - or isinstance(child, TestOutputCollection) \ - or isinstance(child, TestRepeat) \ + return ( + isinstance(child, TestParam) + or isinstance(child, TestOutput) + or isinstance(child, TestOutputCollection) + or isinstance(child, TestRepeat) or isinstance(child, Expand) + ) class TestParam(XMLParam): @@ -964,9 +972,11 @@ def __init__( super(TestRepeat, self).__init__(**params) def acceptable_child(self, child): - return issubclass(type(child), TestParam) \ - or issubclass(type(child), TestOutput) \ + return ( + issubclass(type(child), TestParam) + or issubclass(type(child), TestOutput) or issubclass(type(child), TestOutputCollection) + ) def command_line_before(self, mako_path): return "" % self.name @@ -985,8 +995,7 @@ class Citations(XMLParam): name = "citations" def acceptable_child(self, child): - return issubclass(type(child), Citation) \ - or isinstance(child, Expand) + return issubclass(type(child), Citation) or isinstance(child, Expand) def has_citation(self, type, value): """ @@ -996,8 +1005,7 @@ def has_citation(self, type, value): :type value: STRING """ for citation in self.children: - if citation.node.attrib['type'] == type \ - and citation.node.text == value: + if citation.node.attrib["type"] == type and citation.node.text == value: return True return False diff --git a/setup.py b/setup.py index 762a7d0..af18d01 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="galaxyxml", - version="0.4.14", + version="0.4.15", description="Galaxy XML generation library", author="Helena Rasche", author_email="hxr@hx42.org", diff --git a/test/import_xml.xml b/test/import_xml.xml index c1656d6..132118e 100644 --- a/test/import_xml.xml +++ b/test/import_xml.xml @@ -18,7 +18,8 @@ v_command - + + diff --git a/test/unit_test_import_xml.py b/test/unit_test_import_xml.py index 7560006..4f4d0d7 100644 --- a/test/unit_test_import_xml.py +++ b/test/unit_test_import_xml.py @@ -31,6 +31,17 @@ def test_override(self): self.assertTrue(co in exml) +class TestCommand(TestImport): + def test_command(self): + try: + de = self.tool.command.node.attrib["detect_errors"] + except KeyError: + de = None + self.assertEqual(de, None) + ctext = self.tool.command.node.text + self.assertEqual(ctext.strip(), "command") + + class TestImportXml(TestImport): def test_init_tool(self): xml_root = self.tool.root diff --git a/tox.ini b/tox.ini index 61e9aca..27d8501 100644 --- a/tox.ini +++ b/tox.ini @@ -1,3 +1,22 @@ +[tox] +env_list = py{38,310}-lint, py{38,310}-test +source_dir = galaxyxml +test_dir = test + [flake8] max-line-length = 230 max-complexity = 10 +ignore = E2,E3,E4,E5,W3,W505,C901,E501,E128,E203,E402,E501,E741,W503,W504, +exclude = .ci, .git, .tox, .venv + + +[testenv] +deps = + lint: flake8 + lint: black + test: pytest + +commands = + lint: flake8 + lint: black --check --diff . + test: pytest