Skip to content

Commit

Permalink
Merge pull request #38 from fubar2/master
Browse files Browse the repository at this point in the history
 IUC want profile in the <tool> and detect_errors in the <command>
  • Loading branch information
hexylena authored Sep 22, 2023
2 parents 9281659 + cab0cb3 commit 72c6921
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 120 deletions.
4 changes: 0 additions & 4 deletions examples/tool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
<requirement version="1.0.0" type="package">samtools</requirement>
<container type="docker">one_super_image</container>
</requirements>
<stdio>
<exit_code range="1:" level="fatal"/>
</stdio>
<expand macro="stdio"/>
<version_command><![CDATA[aragorn.exe --version]]></version_command>
<command><![CDATA[aragorn.exe $flag
-float $float_section.float
Expand Down
5 changes: 1 addition & 4 deletions galaxyxml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from builtins import (
object,
str
)
from builtins import object, str

from lxml import etree

Expand Down
53 changes: 26 additions & 27 deletions galaxyxml/tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@
import logging

from galaxyxml import GalaxyXML, Util
from galaxyxml.tool.parameters import (
Expand,
Import,
Inputs,
Macro,
Macros,
Outputs,
XMLParam
)
from galaxyxml.tool.parameters import Expand, Import, Inputs, Macro, Macros, Outputs, XMLParam, Command

from lxml import etree

Expand All @@ -37,18 +29,21 @@ def __init__(
version_command="interpreter filename.exe --version",
command_override=None,
macros=[],
profile=None,
):

self.id = id
self.executable = executable
self.interpreter = interpreter
self.command_override = command_override
self.profile = profile
kwargs = {
"name": name,
"id": id,
"version": version,
"hidden": hidden,
"workflow_compatible": workflow_compatible,
"profile": profile
}
self.version_command = version_command

Expand Down Expand Up @@ -81,6 +76,7 @@ def __init__(
self.macros.append(Import(m))
self.inputs = Inputs()
self.outputs = Outputs()
self.command = Command()

def add_comment(self, comment_txt):
comment = etree.Comment(comment_txt)
Expand Down Expand Up @@ -134,13 +130,11 @@ def export(self, keep_old_command=False):
stdio_element = export_xml.stdios
except Exception:
stdio_element = None
if not stdio_element:
stdio_element = etree.SubElement(export_xml.root, "stdio")
etree.SubElement(stdio_element, "exit_code", range="1:", level="fatal")
try:
export_xml.append(stdio_element)
except Exception:
export_xml.append(Expand(macro="stdio"))
if stdio_element:
try:
export_xml.append(stdio_element)
except Exception:
export_xml.append(Expand(macro="stdio"))

# Append version command
export_xml.append_version_command()
Expand All @@ -158,25 +152,30 @@ def export(self, keep_old_command=False):
command_line.append(export_xml.outputs.cli())
except Exception:
pass
# Steal interpreter from kwargs
command_kwargs = {}
if export_xml.interpreter is not None:
command_kwargs["interpreter"] = export_xml.interpreter
# Add command section
command_node = etree.SubElement(export_xml.root, "command", **command_kwargs)
command_node_text = None
if keep_old_command:
if getattr(self, "command", None):
command_node.text = etree.CDATA(export_xml.command)
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.")
command_node.text = export_xml.executable
command_node_text = export_xml.executable
else:
if self.command_override:
actual_cli = export_xml.clean_command_string(command_line)
else:
actual_cli = "%s %s" % (export_xml.executable, export_xml.clean_command_string(command_line),)
command_node.text = etree.CDATA(actual_cli.strip())
export_xml.append(command_node)
actual_cli = "%s %s" % (
export_xml.executable,
export_xml.clean_command_string(command_line),
)
command_node_text = actual_cli.strip()
export_xml.command_line = command_node_text
try:
command_element = export_xml.command
except Exception:
command_element = etree.SubElement(export_xml.root, "command", detect_errors=None)
command_element.node.text = etree.CDATA(command_node_text)
export_xml.append(command_element)

try:
export_xml.append(export_xml.configfiles)
Expand Down Expand Up @@ -226,13 +225,13 @@ class MacrosTool(Tool):
TODO all other elements, like requirements are currently ignored
"""

def __init__(self, *args, **kwargs):
super(MacrosTool, self).__init__(*args, **kwargs)
self.root = etree.Element('macros')
self.inputs = Macro("%s_inmacro" % self.id)
self.outputs = Macro("%s_outmacro" % self.id)


def export(self, keep_old_command=False): # noqa

export_xml = copy.deepcopy(self)
Expand Down
34 changes: 20 additions & 14 deletions galaxyxml/tool/import_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def _init_tool(self, xml_root):
description = child.text
elif child.tag == "command":
executable = child.text.split()[0]
command = child.text
elif child.tag == "version_command":
version_cmd = child.text

Expand All @@ -43,7 +42,6 @@ def _init_tool(self, xml_root):
workflow_compatible=xml_root.attrib.get("workflow_compatible", True),
version_command=version_cmd,
)
tool.command = command
return tool

def _load_description(self, tool, desc_root):
Expand Down Expand Up @@ -77,21 +75,28 @@ def _load_stdio(self, tool, stdio_root):
"""
tool.stdios = gxtp.Stdios()
for std in stdio_root:
slevel = std.attrib['level']
srange = std.attrib['range']
slevel = std.attrib["level"]
srange = std.attrib["range"]
tool.stdios.append(gxtp.Stdio(level=slevel, range=srange))
logger.info("<stdio> loaded.")

def _load_command(self, tool, desc_root):
def _load_command(self, tool, command_root):
"""
<command> is already loaded during initiation.
:param tool: Tool object from galaxyxml.
:type tool: :class:`galaxyxml.tool.Tool`
:param desc_root: root of <command> tag.
:type desc_root: :class:`xml.etree._Element`
"""
logger.info("<command> 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):
"""
Expand Down Expand Up @@ -727,11 +732,12 @@ def _load_element(self, test_root, element_root):
:param repeat_root: root of <output_collection> 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):
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 72c6921

Please sign in to comment.