Skip to content

Commit

Permalink
add github workflow
Browse files Browse the repository at this point in the history
missing deploy so far
  • Loading branch information
bernt-matthias committed Jun 14, 2023
1 parent 67faa41 commit 69b9bed
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 129 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Test Pull Request

on: [push,pull_request]

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8']
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache .cache/pip
uses: actions/cache@v3
id: cache-pip
with:
path: ~/.cache/pip
key: pip_cache_py_${{ matrix.python-version }}
- name: Install package
run: pip install -r requirements.txt flake8
- name: Flake8
run: flake8 --ignore=C901,W503
- name: Check import order
uses: isort/isort-action@v1
with:
isort-version: 5.12.0
configuration: --check --diff --profile black
- name: Black
uses: psf/[email protected]
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8']
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache .cache/pip
uses: actions/cache@v3
id: cache-pip
with:
path: ~/.cache/pip
key: pip_cache_py_${{ matrix.python-version }}
- name: install package
run: python -m pip install .
- name: install packages for testing
run: pip install nose xmldiff
- name: run nosetests
run: nosetests --with-coverage --cover-package=galaxyxml

- name: Run smoke test on example
run: |
python examples/example.py > tmp.xml
xmldiff tmp.xml examples/tool.xml
python examples/example_macros.py > tmp.xml
xmldiff tmp.xml examples/example_macros.xml
4 changes: 2 additions & 2 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
outputs.append(param)
# Collection
collection = gxtp.OutputCollection("supercollection", label="a small label")
discover = gxtp.DiscoverDatasets("(?P<designation>.+)\.pdf.fasta", format="fasta")
discover = gxtp.DiscoverDatasets(r"(?P<designation>.+)\.pdf.fasta", format="fasta")
collection.append(discover)
outputs.append(collection)

Expand All @@ -114,7 +114,7 @@
rep_out.append(param)
test_a.append(rep_out)
test_coll = gxtp.TestOutputCollection(name="pdf_out")
test_elem = gxtp.TestOCElement(name="apdf",file="apdf",ftype="pdf")
test_elem = gxtp.TestOCElement(name="apdf", file="apdf", ftype="pdf")
test_coll.append(test_elem)
test_a.append(test_coll)
rep_out = gxtp.TestRepeat(name="output_repeat")
Expand Down
3 changes: 1 addition & 2 deletions examples/example_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import galaxyxml.tool.parameters as gxtp

# examplify the use of MacrosTool
#

tool = gxt.MacrosTool(
name="aragorn",
Expand Down Expand Up @@ -84,7 +83,7 @@
outputs.append(param)
# Collection
collection = gxtp.OutputCollection("supercollection", label="a small label")
discover = gxtp.DiscoverDatasets("(?P<designation>.+)\.pdf.fasta", format="fasta")
discover = gxtp.DiscoverDatasets(r"(?P<designation>.+)\.pdf.fasta", format="fasta")
collection.append(discover)
outputs.append(collection)

Expand Down
14 changes: 7 additions & 7 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 All @@ -25,7 +22,11 @@ def coerce(cls, data, kill_lists=False):
- kill_lists: True -> replace lists by their first element
"""
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])
Expand All @@ -36,8 +37,7 @@ def coerce(cls, data, kill_lists=False):

@classmethod
def coerce_value(cls, obj):
"""Make everything a string!
"""
"""Make everything a string!"""
if isinstance(obj, bool):
if obj:
return "true"
Expand Down
35 changes: 24 additions & 11 deletions galaxyxml/tool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import copy
import logging

from lxml import etree

from galaxyxml import GalaxyXML, Util
from galaxyxml.tool.parameters import (
Expand,
Expand All @@ -9,11 +11,9 @@
Macro,
Macros,
Outputs,
XMLParam
XMLParam,
)

from lxml import etree

VALID_TOOL_TYPES = ("data_source", "data_source_async")
VALID_URL_METHODS = ("get", "post")

Expand Down Expand Up @@ -63,15 +63,19 @@ def __init__(

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

if URL_method is not None:
if URL_method in VALID_URL_METHODS:
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.text = description
Expand Down Expand Up @@ -169,13 +173,18 @@ def export(self, keep_old_command=False):
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:
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),)
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)

Expand Down Expand Up @@ -227,13 +236,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.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 All @@ -252,7 +261,9 @@ def export(self, keep_old_command=False): # noqa
raise

# Add command section
command_node = etree.SubElement(export_xml.root, 'token', {"name": "%s_INMACRO" % self.id.upper()})
command_node = etree.SubElement(
export_xml.root, "token", {"name": "%s_INMACRO" % self.id.upper()}
)
actual_cli = "%s" % (export_xml.clean_command_string(command_line))
command_node.text = etree.CDATA(actual_cli.strip())

Expand All @@ -261,7 +272,9 @@ def export(self, keep_old_command=False): # noqa
command_line.append(export_xml.outputs.cli())
except Exception:
pass
command_node = etree.SubElement(export_xml.root, 'token', {"name": "%s_OUTMACRO" % self.id.upper()})
command_node = etree.SubElement(
export_xml.root, "token", {"name": "%s_OUTMACRO" % self.id.upper()}
)
actual_cli = "%s" % (export_xml.clean_command_string(command_line))
command_node.text = etree.CDATA(actual_cli.strip())

Expand Down
59 changes: 42 additions & 17 deletions galaxyxml/tool/import_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ 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.")

Expand Down Expand Up @@ -119,7 +119,9 @@ def _load_requirements(self, tool, requirements_root):
value = req.text
if req.tag == "requirement":
version = req.attrib.get("version", None)
tool.requirements.append(gxtp.Requirement(req_type, value, version=version))
tool.requirements.append(
gxtp.Requirement(req_type, value, version=version)
)
elif req.tag == "container":
tool.requirements.append(gxtp.Container(req_type, value))
else:
Expand Down Expand Up @@ -352,7 +354,9 @@ def _load_option_select(self, root, option):
"""
root.append(
gxtp.SelectOption(
option.attrib.get("value", None), option.text, selected=option.attrib.get("selected", False)
option.attrib.get("value", None),
option.text,
selected=option.attrib.get("selected", False),
)
)

Expand Down Expand Up @@ -432,9 +436,13 @@ def _load_select_param(self, root, sel_param):
# 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):
Expand Down Expand Up @@ -535,7 +543,12 @@ def load_inputs(self, root, inputs_root):
try:
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):
Expand Down Expand Up @@ -580,7 +593,9 @@ def _load_change_format(self, root, chfmt_root):
for chfmt_child in chfmt_root:
change_format.append(
gxtp.ChangeFormatWhen(
chfmt_child.attrib["input"], chfmt_child.attrib["format"], chfmt_child.attrib["value"]
chfmt_child.attrib["input"],
chfmt_child.attrib["format"],
chfmt_child.attrib["value"],
)
)
root.append(change_format)
Expand All @@ -607,7 +622,9 @@ def _load_collection(self, outputs_root, coll_root):
try:
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):
Expand Down Expand Up @@ -727,11 +744,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 +765,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 All @@ -765,7 +783,12 @@ def load_inputs(self, repeat, repeat_root):
try:
getattr(self, "_load_{}".format(rep_child.tag))(repeat, rep_child)
except AttributeError:
logger.warning(rep_child.tag + " tag is not processed for <" + repeat_root.tag + "> tag.")
logger.warning(
rep_child.tag
+ " tag is not processed for <"
+ repeat_root.tag
+ "> tag."
)

def load_tests(self, root, tests_root):
"""
Expand All @@ -781,5 +804,7 @@ def load_tests(self, root, tests_root):
try:
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)
Loading

0 comments on commit 69b9bed

Please sign in to comment.