Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection of improvements #37

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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 black==23.3 flake8==6.0 isort==5.12
- 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


deploy:
name: Deploy
needs: [lint, test]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7']
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 }}
- uses: casperdcl/deploy-pypi@v2
with:
password: ${{ secrets.PYPI_TOKEN }}
build: --sdist --wheel --outdir dist .
# only upload if a tag is pushed (otherwise just build & check)
upload: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') }}
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

48 changes: 39 additions & 9 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@

# A float in a section
section = gxtp.Section("float_section", "Float section")
param = gxtp.FloatParam("float", value=0, label="Float label", help="Float help", num_dashes=1)
param = gxtp.FloatParam(
"float", value=0, label="Float label", help="Float help", num_dashes=1
)
param.space_between_arg = " "
section.append(param)
param = gxtp.FloatParam(None, argument="--float-fromarg", value=0, label="Float label", help="Float help")
param = gxtp.FloatParam(
None, argument="--float-fromarg", value=0, label="Float label", help="Float help"
)
section.append(param)
inputs.append(section)

Expand All @@ -41,16 +45,29 @@
param.append(gxtp.SelectParam("Select", options={"hi": "1", "bye": "2"}))
when_a = gxtp.When(value="hi")
when_b = gxtp.When(value="bye")
when_b.append(gxtp.IntegerParam("some_int", value=0, num_dashes=1, label="Advanced value"))
when_b.append(
gxtp.IntegerParam("some_int", value=0, num_dashes=1, label="Advanced value")
)
param.append(when_a)
param.append(when_b)
inputs.append(param)

# Integer parameters
param_min = gxtp.IntegerParam("int_min", label="int_min label", help="int_min help", value=0, num_dashes=1)
param_max = gxtp.IntegerParam("int_max", label="int_max label", help="int_max help", value=0, num_dashes=1)
param_min = gxtp.IntegerParam(
"int_min", label="int_min label", help="int_min help", value=0, num_dashes=1
)
param_max = gxtp.IntegerParam(
"int_max", label="int_max label", help="int_max help", value=0, num_dashes=1
)

posint = gxtp.IntegerParam("posint", label="posint label", positional=True, help="posinthelp", value=0, num_dashes=2)
posint = gxtp.IntegerParam(
"posint",
label="posint label",
positional=True,
help="posinthelp",
value=0,
num_dashes=2,
)

param_min.command_line_override = "-i$int_min,$int_max"
param_max.command_line_override = ""
Expand All @@ -70,10 +87,21 @@
filter_a = gxtp.Filter("sort_by", name="sorted", column="1")
options.append(filter_a)
param.append(options)
validator = gxtp.ValidatorParam(type="regex")
validator.node.text = ".*"
param.append(validator)
inputs.append(param)

param = gxtp.Repeat("repeat", "repeat title")
data = gxtp.DataParam("data", argument="--data", optional=True, format="fasta", multiple=True, label="data label", help="data help")
data = gxtp.DataParam(
"data",
argument="--data",
optional=True,
format="fasta",
multiple=True,
label="data label",
help="data help",
)
param.append(data)
inputs.append(param)

Expand All @@ -88,7 +116,9 @@
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 @@ -111,7 +141,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
30 changes: 23 additions & 7 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 @@ -32,7 +31,9 @@

# A float in a section
section = gxtp.Section("float_section", "Float section")
param = gxtp.FloatParam("float", label="Float label", help="Float help", value=0, num_dashes=1)
param = gxtp.FloatParam(
"float", label="Float label", help="Float help", value=0, num_dashes=1
)
param.space_between_arg = " "
section.append(param)
inputs.append(section)
Expand All @@ -42,16 +43,29 @@
param.append(gxtp.SelectParam("Select", options={"hi": "1", "bye": "2"}))
when_a = gxtp.When(value="hi")
when_b = gxtp.When(value="bye")
when_b.append(gxtp.IntegerParam("some_int", value=0, num_dashes=1, label="Advanced value"))
when_b.append(
gxtp.IntegerParam("some_int", value=0, num_dashes=1, label="Advanced value")
)
param.append(when_a)
param.append(when_b)
inputs.append(param)

# Integer parameters
param_min = gxtp.IntegerParam("int_min", label="int_min label", help="int_min help", value=0, num_dashes=1)
param_max = gxtp.IntegerParam("int_max", label="int_max label", help="int_max help", value=0, num_dashes=1)
param_min = gxtp.IntegerParam(
"int_min", label="int_min label", help="int_min help", value=0, num_dashes=1
)
param_max = gxtp.IntegerParam(
"int_max", label="int_max label", help="int_max help", value=0, num_dashes=1
)

posint = gxtp.IntegerParam("posint", label="posint label", positional=True, help="posinthelp", value=0, num_dashes=2)
posint = gxtp.IntegerParam(
"posint",
label="posint label",
positional=True,
help="posinthelp",
value=0,
num_dashes=2,
)

param_min.command_line_override = "-i$int_min,$int_max"
param_max.command_line_override = ""
Expand Down Expand Up @@ -84,7 +98,9 @@
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
1 change: 1 addition & 0 deletions examples/tool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ select_local $select_local
<column name="value" index="1"/>
<filter name="sorted" type="sort_by" column="1"/>
</options>
<validator type="regex">.*</validator>
</param>
<repeat name="repeat" title="repeat title">
<param name="data" argument="--data" type="data" optional="true" label="data label" help="data help" format="fasta" multiple="true"/>
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
Loading