# HG changeset patch # User fubar # Date 1597116281 14400 # Node ID ce2b1f8ea68df78ace2ceffd83893aac2f4abede # Parent 5d38cb3d9be8d3bed7e8277607b2c1e43be5f42c passes flake8 tests finally :) diff -r 5d38cb3d9be8 -r ce2b1f8ea68d toolfactory/galaxyxml/__init__.py --- a/toolfactory/galaxyxml/__init__.py Sat Aug 08 19:55:55 2020 -0400 +++ b/toolfactory/galaxyxml/__init__.py Mon Aug 10 23:24:41 2020 -0400 @@ -4,23 +4,24 @@ class GalaxyXML(object): - def __init__(self): - self.root = etree.Element('root') + self.root = etree.Element("root") def export(self): - return etree.tostring(self.root, pretty_print=True, encoding='unicode') + return etree.tostring(self.root, pretty_print=True, encoding="unicode") class Util(object): - @classmethod def coerce(cls, data, kill_lists=False): """Recursive data sanitisation """ if isinstance(data, dict): - return {k: cls.coerce(v, kill_lists=kill_lists) for k, v in - list(data.items()) if v is not None} + return { + k: cls.coerce(v, kill_lists=kill_lists) + for k, v in list(data.items()) + if v is not None + } elif isinstance(data, list): if kill_lists: return cls.coerce(data[0]) @@ -45,22 +46,22 @@ @classmethod def clean_kwargs(cls, params, final=False): - if 'kwargs' in params: - kwargs = params['kwargs'] + if "kwargs" in params: + kwargs = params["kwargs"] for k in kwargs: params[k] = kwargs[k] - del params['kwargs'] - if 'self' in params: - del params['self'] + del params["kwargs"] + if "self" in params: + del params["self"] - if '__class__' in params: - del params['__class__'] + if "__class__" in params: + del params["__class__"] # There will be more params, it would be NICE to use a whitelist # instead of a blacklist, but until we have more data let's just # blacklist stuff we see commonly. if final: - for blacklist in ('positional',): + for blacklist in ("positional",): if blacklist in params: del params[blacklist] return params diff -r 5d38cb3d9be8 -r ce2b1f8ea68d toolfactory/galaxyxml/tool/__init__.py --- a/toolfactory/galaxyxml/tool/__init__.py Sat Aug 08 19:55:55 2020 -0400 +++ b/toolfactory/galaxyxml/tool/__init__.py Mon Aug 10 23:24:41 2020 -0400 @@ -4,56 +4,68 @@ from galaxyxml import Util, GalaxyXML from galaxyxml.tool.parameters import XMLParam -VALID_TOOL_TYPES = ('data_source', 'data_source_async') -VALID_URL_METHODS = ('get', 'post') +VALID_TOOL_TYPES = ("data_source", "data_source_async") +VALID_URL_METHODS = ("get", "post") logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) class Tool(GalaxyXML): - - def __init__(self, name, id, version, description, executable, hidden=False, - tool_type=None, URL_method=None, workflow_compatible=True, - interpreter=None, version_command='interpreter filename.exe --version', - command_line_override=None): + def __init__( + self, + name, + id, + version, + description, + executable, + hidden=False, + tool_type=None, + URL_method=None, + workflow_compatible=True, + interpreter=None, + version_command="interpreter filename.exe --version", + command_line_override=None, + ): self.executable = executable self.interpreter = interpreter self.command_line_override = command_line_override kwargs = { - 'name': name, - 'id': id, - 'version': version, - 'hidden': hidden, - 'workflow_compatible': workflow_compatible, + "name": name, + "id": id, + "version": version, + "hidden": hidden, + "workflow_compatible": workflow_compatible, } self.version_command = version_command # Remove some of the default values to make tools look a bit nicer if not hidden: - del kwargs['hidden'] + del kwargs["hidden"] if workflow_compatible: - del kwargs['workflow_compatible'] + del kwargs["workflow_compatible"] kwargs = Util.coerce(kwargs) - self.root = etree.Element('tool', **kwargs) + self.root = etree.Element("tool", **kwargs) if tool_type is not None: if tool_type not in VALID_TOOL_TYPES: - raise Exception("Tool type must be one of %s" % - ','.join(VALID_TOOL_TYPES)) + raise Exception( + "Tool type must be one of %s" % ",".join(VALID_TOOL_TYPES) + ) else: - kwargs['tool_type'] = tool_type + kwargs["tool_type"] = tool_type if URL_method is not None: if URL_method in VALID_URL_METHODS: - kwargs['URL_method'] = URL_method + kwargs["URL_method"] = URL_method else: - raise Exception("URL_method must be one of %s" % - ','.join(VALID_URL_METHODS)) + raise Exception( + "URL_method must be one of %s" % ",".join(VALID_URL_METHODS) + ) - description_node = etree.SubElement(self.root, 'description') + description_node = etree.SubElement(self.root, "description") description_node.text = description def add_comment(self, comment_txt): @@ -61,7 +73,7 @@ self.root.insert(0, comment) def append_version_command(self): - version_command = etree.SubElement(self.root, 'version_command') + version_command = etree.SubElement(self.root, "version_command") try: version_command.text = etree.CDATA(self.version_command) except Exception: @@ -76,10 +88,10 @@ def clean_command_string(self, command_line): clean = [] for x in command_line: - if x is not [] and x is not ['']: + if x is not [] and x is not [""]: clean.append(x) - return '\n'.join(clean) + return "\n".join(clean) def export(self, keep_old_command=False): # noqa @@ -105,7 +117,7 @@ except Exception: pass - if self.command_line_override != None: + if self.command_line_override: command_line = self.command_line_override else: command_line = [] @@ -120,8 +132,8 @@ pass # Add stdio section - stdio = etree.SubElement(export_xml.root, 'stdio') - etree.SubElement(stdio, 'exit_code', range='1:', level='fatal') + stdio = etree.SubElement(export_xml.root, "stdio") + etree.SubElement(stdio, "exit_code", range="1:", level="fatal") # Append version command export_xml.append_version_command() @@ -129,21 +141,25 @@ # Steal interpreter from kwargs command_kwargs = {} if export_xml.interpreter is not None: - command_kwargs['interpreter'] = export_xml.interpreter + command_kwargs["interpreter"] = export_xml.interpreter # Add command section - command_node = etree.SubElement(export_xml.root, 'command', **command_kwargs) + command_node = etree.SubElement(export_xml.root, "command", **command_kwargs) if keep_old_command: - if getattr(self, 'command', None): + if getattr(self, "command", None): command_node.text = etree.CDATA(export_xml.command) else: - logger.warning('The tool does not have any old command stored. ' + - 'Only the command line is written.') + logger.warning( + "The tool does not have any old command stored. " + + "Only the command line is written." + ) command_node.text = export_xml.executable else: actual_cli = "%s %s" % ( - export_xml.executable, export_xml.clean_command_string(command_line)) + export_xml.executable, + export_xml.clean_command_string(command_line), + ) command_node.text = etree.CDATA(actual_cli.strip()) try: @@ -161,7 +177,7 @@ except Exception: pass - help_element = etree.SubElement(export_xml.root, 'help') + help_element = etree.SubElement(export_xml.root, "help") help_element.text = etree.CDATA(export_xml.help) try: diff -r 5d38cb3d9be8 -r ce2b1f8ea68d toolfactory/galaxyxml/tool/import_xml.py --- 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 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 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 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 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 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