Mercurial > repos > fubar > tool_factory_2
diff toolfactory/galaxyxml/tool/import_xml.py @ 36:ce2b1f8ea68d draft
passes flake8 tests finally :)
author | fubar |
---|---|
date | Mon, 10 Aug 2020 23:24:41 -0400 |
parents | 5d38cb3d9be8 |
children | a30536c100bf |
line wrap: on
line diff
--- a/toolfactory/galaxyxml/tool/import_xml.py Sat Aug 08 19:55:55 2020 -0400 +++ b/toolfactory/galaxyxml/tool/import_xml.py Mon Aug 10 23:24:41 2020 -0400 @@ -22,24 +22,26 @@ version_cmd = None description = None for child in xml_root: - if child.tag == 'description': + if child.tag == "description": description = child.text - elif child.tag == 'command': + elif child.tag == "command": executable = child.text.split()[0] command = child.text - elif child.tag == 'version_command': + elif child.tag == "version_command": version_cmd = child.text - tool = gxt.Tool(xml_root.attrib['name'], - xml_root.attrib['id'], - xml_root.attrib.get('version', None), - description, - executable, - hidden=xml_root.attrib.get('hidden', False), - tool_type=xml_root.attrib.get('tool_type', None), - URL_method=xml_root.attrib.get('URL_method', None), - workflow_compatible=xml_root.attrib.get('workflow_compatible', True), - version_command=version_cmd) + tool = gxt.Tool( + xml_root.attrib["name"], + xml_root.attrib["id"], + xml_root.attrib.get("version", None), + description, + executable, + hidden=xml_root.attrib.get("hidden", False), + tool_type=xml_root.attrib.get("tool_type", None), + URL_method=xml_root.attrib.get("URL_method", None), + workflow_compatible=xml_root.attrib.get("workflow_compatible", True), + version_command=version_cmd, + ) tool.command = command return tool @@ -109,15 +111,17 @@ """ tool.requirements = gxtp.Requirements() for req in requirements_root: - req_type = req.attrib['type'] + req_type = req.attrib["type"] value = req.text - if req.tag == 'requirement': - version = req.attrib.get('version', None) - tool.requirements.append(gxtp.Requirement(req_type, value, version=version)) - elif req.tag == 'container': + if req.tag == "requirement": + version = req.attrib.get("version", None) + tool.requirements.append( + gxtp.Requirement(req_type, value, version=version) + ) + elif req.tag == "container": tool.requirements.append(gxtp.Container(req_type, value)) else: - logger.warning(req.tag + ' is not a valid tag for requirements child') + logger.warning(req.tag + " is not a valid tag for requirements child") def _load_edam_topics(self, tool, topics_root): """ @@ -156,7 +160,7 @@ """ tool.configfiles = gxtp.Configfiles() for conf in configfiles_root: - name = conf.attrib['name'] + name = conf.attrib["name"] value = conf.text tool.configfiles.append(gxtp.Configfile(name, value)) @@ -171,7 +175,7 @@ """ tool.citations = gxtp.Citations() for cit in citations_root: - cit_type = cit.attrib['type'] + cit_type = cit.attrib["type"] value = cit.text tool.citations.append(gxtp.Citation(cit_type, value)) @@ -228,7 +232,7 @@ # Now we import each tag's field for child in xml_root: try: - getattr(self, '_load_{}'.format(child.tag))(tool, child) + getattr(self, "_load_{}".format(child.tag))(tool, child) except AttributeError: logger.warning(child.tag + " tag is not processed.") return tool @@ -247,11 +251,15 @@ :param text_param: root of <param> tag. :type text_param: :class:`xml.etree._Element` """ - root.append(gxtp.TextParam(text_param.attrib['name'], - optional=text_param.get('optional', None), - label=text_param.get('label', None), - help=text_param.get('help', None), - value=text_param.get('value', None))) + root.append( + gxtp.TextParam( + text_param.attrib["name"], + optional=text_param.get("optional", None), + label=text_param.get("label", None), + help=text_param.get("help", None), + value=text_param.get("value", None), + ) + ) def _load_data_param(self, root, data_param): """ @@ -261,12 +269,16 @@ :param data_param: root of <param> tag. :type data_param: :class:`xml.etree._Element` """ - root.append(gxtp.DataParam(data_param.attrib['name'], - optional=data_param.attrib.get('optional', None), - label=data_param.attrib.get('label', None), - help=data_param.attrib.get('help', None), - format=data_param.attrib.get('format', None), - multiple=data_param.attrib.get('multiple', None))) + root.append( + gxtp.DataParam( + data_param.attrib["name"], + optional=data_param.attrib.get("optional", None), + label=data_param.attrib.get("label", None), + help=data_param.attrib.get("help", None), + format=data_param.attrib.get("format", None), + multiple=data_param.attrib.get("multiple", None), + ) + ) def _load_boolean_param(self, root, bool_param): """ @@ -276,13 +288,17 @@ :param bool_param: root of <param> tag. :type bool_param: :class:`xml.etree._Element` """ - root.append(gxtp.BooleanParam(bool_param.attrib['name'], - optional=bool_param.attrib.get('optional', None), - label=bool_param.attrib.get('label', None), - help=bool_param.attrib.get('help', None), - checked=bool_param.attrib.get('checked', False), - truevalue=bool_param.attrib.get('truevalue', None), - falsevalue=bool_param.attrib.get('falsevalue', None))) + root.append( + gxtp.BooleanParam( + bool_param.attrib["name"], + optional=bool_param.attrib.get("optional", None), + label=bool_param.attrib.get("label", None), + help=bool_param.attrib.get("help", None), + checked=bool_param.attrib.get("checked", False), + truevalue=bool_param.attrib.get("truevalue", None), + falsevalue=bool_param.attrib.get("falsevalue", None), + ) + ) def _load_integer_param(self, root, int_param): """ @@ -292,13 +308,17 @@ :param int_param: root of <param> tag. :type int_param: :class:`xml.etree._Element` """ - root.append(gxtp.IntegerParam(int_param.attrib['name'], - int_param.attrib.get('value', None), - optional=int_param.attrib.get('optional', None), - label=int_param.attrib.get('label', None), - help=int_param.attrib.get('help', None), - min=int_param.attrib.get('min', None), - max=int_param.attrib.get('max', None))) + root.append( + gxtp.IntegerParam( + int_param.attrib["name"], + int_param.attrib.get("value", None), + optional=int_param.attrib.get("optional", None), + label=int_param.attrib.get("label", None), + help=int_param.attrib.get("help", None), + min=int_param.attrib.get("min", None), + max=int_param.attrib.get("max", None), + ) + ) def _load_float_param(self, root, float_param): """ @@ -308,13 +328,17 @@ :param float_param: root of <param> tag. :type float_param: :class:`xml.etree._Element` """ - root.append(gxtp.FloatParam(float_param.attrib['name'], - float_param.attrib.get('value', None), - optional=float_param.attrib.get('optional', None), - label=float_param.attrib.get('label', None), - help=float_param.attrib.get('help', None), - min=float_param.attrib.get('min', None), - max=float_param.attrib.get('max', None))) + root.append( + gxtp.FloatParam( + float_param.attrib["name"], + float_param.attrib.get("value", None), + optional=float_param.attrib.get("optional", None), + label=float_param.attrib.get("label", None), + help=float_param.attrib.get("help", None), + min=float_param.attrib.get("min", None), + max=float_param.attrib.get("max", None), + ) + ) def _load_option_select(self, root, option): """ @@ -324,9 +348,13 @@ :param option: root of <option> tag. :type float_param: :class:`xml.etree._Element` """ - root.append(gxtp.SelectOption(option.attrib.get('value', None), - option.text, - selected=option.attrib.get('selected', False))) + root.append( + gxtp.SelectOption( + option.attrib.get("value", None), + option.text, + selected=option.attrib.get("selected", False), + ) + ) def _load_column_options(self, root, column): """ @@ -336,7 +364,7 @@ :param option: root of <column> tag. :type float_param: :class:`xml.etree._Element` """ - root.append(gxtp.Column(column.attrib['name'], column.attrib['index'])) + root.append(gxtp.Column(column.attrib["name"], column.attrib["index"])) def _load_filter_options(self, root, filter): """ @@ -346,17 +374,21 @@ :param option: root of <filter> tag. :type float_param: :class:`xml.etree._Element` """ - root.append(gxtp.Filter(filter.attrib['type'], - column=filter.attrib.get('column', None), - name=filter.attrib.get('name', None), - ref=filter.attrib.get('ref', None), - key=filter.attrib.get('key', None), - multiple=filter.attrib.get('multiple', None), - separator=filter.attrib.get('separator', None), - keep=filter.attrib.get('keep', None), - value=filter.attrib.get('value', None), - ref_attribute=filter.attrib.get('ref_attribute', None), - index=filter.attrib.get('index', None))) + root.append( + gxtp.Filter( + filter.attrib["type"], + column=filter.attrib.get("column", None), + name=filter.attrib.get("name", None), + ref=filter.attrib.get("ref", None), + key=filter.attrib.get("key", None), + multiple=filter.attrib.get("multiple", None), + separator=filter.attrib.get("separator", None), + keep=filter.attrib.get("keep", None), + value=filter.attrib.get("value", None), + ref_attribute=filter.attrib.get("ref_attribute", None), + index=filter.attrib.get("index", None), + ) + ) def _load_options_select(self, root, options): """ @@ -366,14 +398,16 @@ :param option: root of <options> tag. :type float_param: :class:`xml.etree._Element` """ - opts = gxtp.Options(from_dataset=options.attrib.get('from_dataset', None), - from_file=options.attrib.get('from_file', None), - from_data_table=options.attrib.get('from_data_table', None), - from_parameter=options.attrib.get('from_parameter', None)) + opts = gxtp.Options( + from_dataset=options.attrib.get("from_dataset", None), + from_file=options.attrib.get("from_file", None), + from_data_table=options.attrib.get("from_data_table", None), + from_parameter=options.attrib.get("from_parameter", None), + ) # Deal with child nodes (usually filter and column) for opt_child in options: try: - getattr(self, '_load_{}_options'.format(opt_child.tag))(opts, opt_child) + getattr(self, "_load_{}_options".format(opt_child.tag))(opts, opt_child) except AttributeError: logger.warning(opt_child.tag + " tag is not processed for <options>.") root.append(opts) @@ -386,19 +420,25 @@ :param sel_param: root of <param> tag. :type sel_param: :class:`xml.etree._Element` """ - select_param = gxtp.SelectParam(sel_param.attrib['name'], - optional=sel_param.attrib.get('optional', None), - label=sel_param.attrib.get('label', None), - help=sel_param.attrib.get('help', None), - data_ref=sel_param.attrib.get('data_ref', None), - display=sel_param.attrib.get('display', None), - multiple=sel_param.attrib.get('multiple', None)) + select_param = gxtp.SelectParam( + sel_param.attrib["name"], + optional=sel_param.attrib.get("optional", None), + label=sel_param.attrib.get("label", None), + help=sel_param.attrib.get("help", None), + data_ref=sel_param.attrib.get("data_ref", None), + display=sel_param.attrib.get("display", None), + multiple=sel_param.attrib.get("multiple", None), + ) # Deal with child nodes (usually option and options) for sel_child in sel_param: try: - getattr(self, '_load_{}_select'.format(sel_child.tag))(select_param, sel_child) + getattr(self, "_load_{}_select".format(sel_child.tag))( + select_param, sel_child + ) except AttributeError: - logger.warning(sel_child.tag + " tag is not processed for <param type='select'>.") + logger.warning( + sel_child.tag + " tag is not processed for <param type='select'>." + ) root.append(select_param) def _load_param(self, root, param_root): @@ -409,9 +449,9 @@ :param param_root: root of <param> tag. :type param_root: :class:`xml.etree._Element` """ - param_type = param_root.attrib['type'] + param_type = param_root.attrib["type"] try: - getattr(self, '_load_{}_param'.format(param_type))(root, param_root) + getattr(self, "_load_{}_param".format(param_type))(root, param_root) except AttributeError: logger.warning(param_type + " tag is not processed for <param>.") @@ -423,7 +463,7 @@ :param when_root: root of <when> tag. :type when_root: :class:`xml.etree._Element` """ - when = gxtp.When(when_root.attrib['value']) + when = gxtp.When(when_root.attrib["value"]) # Deal with child nodes self.load_inputs(when, when_root) root.append(when) @@ -436,13 +476,15 @@ :param conditional_root: root of <conditional> tag. :type conditional_root: :class:`xml.etree._Element` """ - value_ref_in_group = conditional_root.attrib.get('value_ref_in_group', None) + value_ref_in_group = conditional_root.attrib.get("value_ref_in_group", None) # Other optional parameters need to be added to conditional object - conditional = gxtp.Conditional(conditional_root.attrib['name'], - value_from=conditional_root.attrib.get('value_from', None), - value_ref=conditional_root.attrib.get('value_ref', None), - value_ref_in_group=value_ref_in_group, - label=conditional_root.attrib.get('label', None)) + conditional = gxtp.Conditional( + conditional_root.attrib["name"], + value_from=conditional_root.attrib.get("value_from", None), + value_ref=conditional_root.attrib.get("value_ref", None), + value_ref_in_group=value_ref_in_group, + label=conditional_root.attrib.get("label", None), + ) # Deal with child nodes self.load_inputs(conditional, conditional_root) root.append(conditional) @@ -455,10 +497,12 @@ :param section_root: root of <section> tag. :type section_root: :class:`xml.etree._Element` """ - section = gxtp.Section(section_root.attrib['name'], - section_root.attrib['title'], - expanded=section_root.attrib.get('expanded', None), - help=section_root.attrib.get('help', None)) + section = gxtp.Section( + section_root.attrib["name"], + section_root.attrib["title"], + expanded=section_root.attrib.get("expanded", None), + help=section_root.attrib.get("help", None), + ) # Deal with child nodes self.load_inputs(section, section_root) root.append(section) @@ -471,11 +515,13 @@ :param repeat_root: root of <repeat> tag. :param repeat_root: :class:`xml.etree._Element` """ - repeat = gxtp.Repeat(repeat_root.attrib['name'], - repeat_root.attrib['title'], - min=repeat_root.attrib.get('min', None), - max=repeat_root.attrib.get('max', None), - default=repeat_root.attrib.get('default', None)) + repeat = gxtp.Repeat( + repeat_root.attrib["name"], + repeat_root.attrib["title"], + min=repeat_root.attrib.get("min", None), + max=repeat_root.attrib.get("max", None), + default=repeat_root.attrib.get("default", None), + ) # Deal with child nodes self.load_inputs(repeat, repeat_root) root.append(repeat) @@ -491,10 +537,14 @@ """ for inp_child in inputs_root: try: - getattr(self, '_load_{}'.format(inp_child.tag))(root, inp_child) + getattr(self, "_load_{}".format(inp_child.tag))(root, inp_child) except AttributeError: - logger.warning(inp_child.tag + " tag is not processed for <" + - inputs_root.tag + "> tag.") + logger.warning( + inp_child.tag + + " tag is not processed for <" + + inputs_root.tag + + "> tag." + ) class OutputsParser(object): @@ -510,17 +560,19 @@ :param data_root: root of <data> tag. :param data_root: :class:`xml.etree._Element` """ - data = gxtp.OutputData(data_root.attrib.get('name', None), - data_root.attrib.get('format', None), - format_source=data_root.attrib.get('format_source', None), - metadata_source=data_root.attrib.get('metadata_source', None), - label=data_root.attrib.get('label', None), - from_work_dir=data_root.attrib.get('from_work_dir', None), - hidden=data_root.attrib.get('hidden', False)) + data = gxtp.OutputData( + data_root.attrib.get("name", None), + data_root.attrib.get("format", None), + format_source=data_root.attrib.get("format_source", None), + metadata_source=data_root.attrib.get("metadata_source", None), + label=data_root.attrib.get("label", None), + from_work_dir=data_root.attrib.get("from_work_dir", None), + hidden=data_root.attrib.get("hidden", False), + ) # Deal with child nodes for data_child in data_root: try: - getattr(self, '_load_{}'.format(data_child.tag))(data, data_child) + getattr(self, "_load_{}".format(data_child.tag))(data, data_child) except AttributeError: logger.warning(data_child.tag + " tag is not processed for <data>.") outputs_root.append(data) @@ -535,9 +587,13 @@ """ change_format = gxtp.ChangeFormat() for chfmt_child in chfmt_root: - change_format.append(gxtp.ChangeFormatWhen(chfmt_child.attrib['input'], - chfmt_child.attrib['format'], - chfmt_child.attrib['value'])) + change_format.append( + gxtp.ChangeFormatWhen( + chfmt_child.attrib["input"], + chfmt_child.attrib["format"], + chfmt_child.attrib["value"], + ) + ) root.append(change_format) def _load_collection(self, outputs_root, coll_root): @@ -548,22 +604,23 @@ :param coll_root: root of <collection> tag. :param coll_root: :class:`xml.etree._Element` """ - collection = gxtp.OutputCollection(coll_root.attrib['name'], - type=coll_root.attrib.get('type', None), - label=coll_root.attrib.get('label', None), - format_source=coll_root.attrib.get('format_source', - None), - type_source=coll_root.attrib.get('type_source', None), - structured_like=coll_root.attrib.get('structured_like', - None), - inherit_format=coll_root.attrib.get('inherit_format', - None)) + collection = gxtp.OutputCollection( + coll_root.attrib["name"], + type=coll_root.attrib.get("type", None), + label=coll_root.attrib.get("label", None), + format_source=coll_root.attrib.get("format_source", None), + type_source=coll_root.attrib.get("type_source", None), + structured_like=coll_root.attrib.get("structured_like", None), + inherit_format=coll_root.attrib.get("inherit_format", None), + ) # Deal with child nodes for coll_child in coll_root: try: - getattr(self, '_load_{}'.format(coll_child.tag))(collection, coll_child) + getattr(self, "_load_{}".format(coll_child.tag))(collection, coll_child) except AttributeError: - logger.warning(coll_child.tag + " tag is not processed for <collection>.") + logger.warning( + coll_child.tag + " tag is not processed for <collection>." + ) outputs_root.append(collection) def _load_discover_datasets(self, root, disc_root): @@ -574,11 +631,15 @@ :param disc_root: root of <discover_datasets> tag. :param disc_root: :class:`xml.etree._Element` """ - root.append(gxtp.DiscoverDatasets(disc_root.attrib['pattern'], - directory=disc_root.attrib.get('directory', None), - format=disc_root.attrib.get('format', None), - ext=disc_root.attrib.get('ext', None), - visible=disc_root.attrib.get('visible', None))) + root.append( + gxtp.DiscoverDatasets( + disc_root.attrib["pattern"], + directory=disc_root.attrib.get("directory", None), + format=disc_root.attrib.get("format", None), + ext=disc_root.attrib.get("ext", None), + visible=disc_root.attrib.get("visible", None), + ) + ) def _load_filter(self, root, filter_root): """ @@ -600,7 +661,7 @@ """ for out_child in outputs_root: try: - getattr(self, '_load_{}'.format(out_child.tag))(root, out_child) + getattr(self, "_load_{}".format(out_child.tag))(root, out_child) except AttributeError: logger.warning(out_child.tag + " tag is not processed for <outputs>.") @@ -618,10 +679,14 @@ :param repeat_root: root of <param> tag. :param repeat_root: :class:`xml.etree._Element` """ - test_root.append(gxtp.TestParam(param_root.attrib['name'], - value=param_root.attrib.get('value', None), - ftype=param_root.attrib.get('ftype', None), - dbkey=param_root.attrib.get('dbkey', None))) + test_root.append( + gxtp.TestParam( + param_root.attrib["name"], + value=param_root.attrib.get("value", None), + ftype=param_root.attrib.get("ftype", None), + dbkey=param_root.attrib.get("dbkey", None), + ) + ) def _load_output(self, test_root, output_root): """ @@ -631,16 +696,20 @@ :param repeat_root: root of <output> tag. :param repeat_root: :class:`xml.etree._Element` """ - test_root.append(gxtp.TestOutput(name=output_root.attrib.get('name', None), - file=output_root.attrib.get('file', None), - ftype=output_root.attrib.get('ftype', None), - sort=output_root.attrib.get('sort', None), - value=output_root.attrib.get('value', None), - md5=output_root.attrib.get('md5', None), - checksum=output_root.attrib.get('checksum', None), - compare=output_root.attrib.get('compare', None), - lines_diff=output_root.attrib.get('lines_diff', None), - delta=output_root.attrib.get('delta', None))) + test_root.append( + gxtp.TestOutput( + name=output_root.attrib.get("name", None), + file=output_root.attrib.get("file", None), + ftype=output_root.attrib.get("ftype", None), + sort=output_root.attrib.get("sort", None), + value=output_root.attrib.get("value", None), + md5=output_root.attrib.get("md5", None), + checksum=output_root.attrib.get("checksum", None), + compare=output_root.attrib.get("compare", None), + lines_diff=output_root.attrib.get("lines_diff", None), + delta=output_root.attrib.get("delta", None), + ) + ) def load_tests(self, root, tests_root): """ @@ -654,7 +723,9 @@ test = gxtp.Test() for test_child in test_root: try: - getattr(self, '_load_{}'.format(test_child.tag))(test, test_child) + getattr(self, "_load_{}".format(test_child.tag))(test, test_child) except AttributeError: - logger.warning(test_child.tag + " tag is not processed within <test>.") + logger.warning( + test_child.tag + " tag is not processed within <test>." + ) root.append(test)