Skip to content

Commit b96d733

Browse files
fix prog/tool naming issues
1 parent 8e24580 commit b96d733

File tree

8 files changed

+46
-41
lines changed

8 files changed

+46
-41
lines changed

argparse2tool/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,11 @@ def load_conflicting_package(name, not_name, module_number):
4848
imp.load_module(random_name, f, pathname, desc)
4949
return sys.modules[random_name]
5050
return None
51+
52+
53+
def remove_extension(name):
54+
if name is not None:
55+
name = name.replace('.py', '')
56+
name = name.replace('-', '_')
57+
name = name.replace(' ', '_')
58+
return name

argparse2tool/dropins/argparse/__init__.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import re
22
import sys
3-
from argparse2tool import load_argparse
3+
from argparse2tool import (
4+
load_argparse,
5+
remove_extension
6+
)
47
from argparse2tool.cmdline2gxml import Arg2GxmlParser
58
from argparse2tool.cmdline2cwl import Arg2CWLParser
69

@@ -53,9 +56,9 @@ def __init__(self,
5356
self.argument_names = []
5457
tools.append(self)
5558
if len(parents) > 0:
56-
p = set([_.prog.split()[-1] for _ in parents])
59+
p = set([remove_extension(_.prog) for _ in parents])
5760
macros = macros.union(p)
58-
used_macros[prog.split()[-1]] = p
61+
used_macros[remove_extension(prog)] = p
5962
super(ArgumentParser, self).__init__(prog=prog,
6063
usage=usage,
6164
description=description,
@@ -177,7 +180,7 @@ def parse_args_galaxy(self, *args, **kwargs):
177180
if directory:
178181
if directory[-1] != '/':
179182
directory += '/'
180-
filename = argp.prog.split()[-1] + ".xml"
183+
filename = remove_extension(argp.prog) + ".xml"
181184
filename = directory + filename
182185
with open(filename, 'w') as f:
183186
f.write(data)
@@ -196,21 +199,15 @@ def _parse_args_galaxy_argp(self, argp, macro):
196199
except AttributeError: # handle the potential absence of print_version
197200
version = '1.0'
198201

199-
prog = argp.prog
200-
if prog is not None:
201-
prog = prog.replace("-", "_")
202-
prog = prog.replace(".py ", " ")
203-
if prog.endswith(".py"):
204-
prog = prog[:-3]
205-
202+
prog = remove_extension(argp.prog)
206203

207-
tid = argp.prog.split()[-1]
204+
# tid = argp.prog.split()[-1]
208205

209206
# get the list of file names of the used macros
210-
mx = used_macros.get(tid, [])
211-
mx = ["%s.xml" % _ for _ in mx]
207+
mx = used_macros.get(prog, [])
208+
mx = sorted(["%s.xml" % _.split(" ")[-1] for _ in mx])
212209

213-
if tid not in macros:
210+
if prog not in macros:
214211
tpe = gxt.Tool
215212
if macro:
216213
mx.append(macro)
@@ -244,12 +241,12 @@ def _parse_args_galaxy_argp(self, argp, macro):
244241
else:
245242
outputs.append(gxt_parameter)
246243

247-
if tid in used_macros:
248-
for m in used_macros[tid]:
244+
if prog in used_macros:
245+
for m in sorted(used_macros[prog]):
249246
inputs.append(gxtp.ExpandIO(m + "_inmacro"))
250247
outputs.append(gxtp.ExpandIO(m + "_outmacro"))
251248

252-
if tid not in macros:
249+
if prog not in macros:
253250
# TODO: replace with argparse-esque library to do this.
254251
stdout = gxtp.OutputData('default', 'txt')
255252
stdout.command_line_override = '> $default'

examples/example-sub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
parser_foo.add_argument('integers', metavar='N', type=int, nargs='+',
1818
help='an integer for the accumulator')
1919
parser_foo.add_argument('--sum', '-s', dest='accumulate', action='store_const',
20-
const=sum, default=max,
20+
const=sum, default=max,
2121
help='sum the integers (default: find the max)')
2222
parser_foo.add_argument('--foo', nargs='?', help='foo help')
2323
parser_foo.add_argument('--bar', nargs='*', default=[1, 2, 3], help='BAR!')
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<tool name="example_sub bar" id="example_sub_bar" version="2.0">
1+
<tool name="example_sub_bar" id="example_sub_bar" version="2.0">
22
<description/>
33
<macros>
4-
<import>qux.xml</import>
4+
<import>example_sub_qux.xml</import>
55
</macros>
66
<stdio>
77
<exit_code range="1:" level="fatal"/>
@@ -18,8 +18,8 @@
1818
#if $mode and $mode is not None:
1919
--mode $mode
2020
#end if
21-
@QUX_INMACRO@
22-
@QUX_OUTMACRO@
21+
@EXAMPLE_SUB_QUX_INMACRO@
22+
@EXAMPLE_SUB_QUX_OUTMACRO@
2323
> $default]]></command>
2424
<inputs>
2525
<param label="Store a false" checked="false" type="boolean" name="false" argument="--false" truevalue="--false" falsevalue=""/>
@@ -34,10 +34,10 @@
3434
<option value="rock">rock</option>
3535
<option selected="true" value="scissors">scissors</option>
3636
</param>
37-
<expand macro="qux_inmacro"/>
37+
<expand macro="example_sub_qux_inmacro"/>
3838
</inputs>
3939
<outputs>
40-
<expand macro="qux_outmacro"/>
40+
<expand macro="example_sub_qux_outmacro"/>
4141
<data name="default" format="txt" hidden="false"/>
4242
</outputs>
4343
<help><![CDATA[TODO: Write help]]></help>
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<macros>
22
<token name="EXAMPLE_SUB_BAZ_INMACRO"><![CDATA[--baz $baz
3-
@QUX_INMACRO@]]></token>
4-
<token name="EXAMPLE_SUB_BAZ_OUTMACRO"><![CDATA[@QUX_OUTMACRO@]]></token>
3+
@EXAMPLE_SUB_QUX_INMACRO@]]></token>
4+
<token name="EXAMPLE_SUB_BAZ_OUTMACRO"><![CDATA[@EXAMPLE_SUB_QUX_OUTMACRO@]]></token>
55
<xml name="example_sub_baz_inmacro">
66
<param optional="true" label="baz help" type="text" name="baz" argument="--baz"/>
7-
<expand macro="qux_inmacro"/>
7+
<expand macro="example_sub_qux_inmacro"/>
88
</xml>
99
<xml name="example_sub_baz_outmacro">
10-
<expand macro="qux_outmacro"/>
10+
<expand macro="example_sub_qux_outmacro"/>
1111
</xml>
1212
</macros>
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<tool name="example_sub foo" id="example_sub_foo" version="1.0">
1+
<tool name="example_sub_foo" id="example_sub_foo" version="1.0">
22
<description/>
33
<macros>
4-
<import>qux.xml</import>
5-
<import>baz.xml</import>
4+
<import>example_sub_baz.xml</import>
5+
<import>example_sub_qux.xml</import>
66
</macros>
77
<stdio>
88
<exit_code range="1:" level="fatal"/>
@@ -23,10 +23,10 @@ $sum
2323
--bar "$repeat_var_4"
2424
2525
$true
26-
@QUX_INMACRO@
27-
@BAZ_INMACRO@
28-
@QUX_OUTMACRO@
29-
@BAZ_OUTMACRO@
26+
@EXAMPLE_SUB_BAZ_INMACRO@
27+
@EXAMPLE_SUB_QUX_INMACRO@
28+
@EXAMPLE_SUB_BAZ_OUTMACRO@
29+
@EXAMPLE_SUB_QUX_OUTMACRO@
3030
> $default]]></command>
3131
<inputs>
3232
<param label="action keyword" type="text" name="keyword"/>
@@ -39,12 +39,12 @@ $true
3939
<param optional="true" label="BAR!" value="1" type="text" name="bar" argument="--bar"/>
4040
</repeat>
4141
<param label="Store a true" checked="false" type="boolean" name="true" argument="--true" truevalue="--true" falsevalue=""/>
42-
<expand macro="qux_inmacro"/>
43-
<expand macro="baz_inmacro"/>
42+
<expand macro="example_sub_baz_inmacro"/>
43+
<expand macro="example_sub_qux_inmacro"/>
4444
</inputs>
4545
<outputs>
46-
<expand macro="qux_outmacro"/>
47-
<expand macro="baz_outmacro"/>
46+
<expand macro="example_sub_baz_outmacro"/>
47+
<expand macro="example_sub_qux_outmacro"/>
4848
<data name="default" format="txt" hidden="false"/>
4949
</outputs>
5050
<help><![CDATA[TODO: Write help]]></help>

examples/example.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<tool name="example.py" id="example.py" version="2.0">
1+
<tool name="example" id="example" version="2.0">
22
<description>Process some integers.</description>
33
<stdio>
44
<exit_code range="1:" level="fatal"/>

0 commit comments

Comments
 (0)