Skip to content

Commit 175e80b

Browse files
authored
Merge pull request #63 from bernt-matthias/topic/improvements
some improvements
2 parents cf080f2 + 1e831c4 commit 175e80b

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

argparse/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ def _parse_args_galaxy_argp(self, argp):
155155
version = '1.0'
156156
tool = gxt.Tool(
157157
argp.prog,
158-
argp.prog,
158+
argp.prog.replace(" ", "_"),
159159
version,
160160
argp.description,
161-
argp.prog,
162-
interpreter='python',
163-
version_command='python %s --version' % sys.argv[0])
161+
"python "+argp.prog,
162+
interpreter=None,
163+
version_command='python %s --version' % argp.prog)
164164

165165
inputs = gxtp.Inputs()
166166
outputs = gxtp.Outputs()

argparse/argparse_galaxy_translation.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import galaxyxml.tool.parameters as gxtp
2+
from collections import Counter
23
from pydoc import locate
34

45

@@ -11,11 +12,16 @@ def __gxtp_param_from_type(self, param, flag, label, num_dashes, gxparam_extra_k
1112
if default is None and (param.type in (int, float)):
1213
default = 0
1314

14-
if param.choices is not None:
15+
if param.type == int:
16+
mn = None
17+
mx = None
18+
if param.choices is not None:
19+
mn = min(param.choices)
20+
mx = max(param.choices)
21+
gxparam = gxtp.IntegerParam(flag, default, label=label, min=mn, max=mx, num_dashes=num_dashes, **gxparam_extra_kwargs)
22+
elif param.choices is not None:
1523
choices = {k: k for k in param.choices}
1624
gxparam = gxtp.SelectParam(flag, default=default, label=label, num_dashes=num_dashes, options=choices, **gxparam_extra_kwargs)
17-
elif param.type == int:
18-
gxparam = gxtp.IntegerParam(flag, default, label=label, num_dashes=num_dashes, **gxparam_extra_kwargs)
1925
elif param.type == float:
2026
gxparam = gxtp.FloatParam(flag, default, label=label, num_dashes=num_dashes, **gxparam_extra_kwargs)
2127
elif param.type is None or param.type == str:
@@ -120,7 +126,7 @@ def __args_from_nargs(self, param, repeat_name, repeat_var_name, positional, fla
120126

121127
def __init__(self):
122128
self.repeat_count = 0
123-
self.positional_count = 0
129+
self.positional_count = Counter()
124130

125131
def _VersionAction(self, param, tool=None):
126132
# passing tool is TERRIBLE, I know.
@@ -153,7 +159,7 @@ def _StoreAction(self, param, tool=None):
153159
flag = max(param.option_strings, key=len) # Pick the longest of the options strings
154160
else:
155161
flag = ''
156-
self.positional_count += 1
162+
self.positional_count['param.dest'] += 1
157163

158164
repeat_name = 'repeat_%s' % self.repeat_count
159165
repeat_var_name = 'repeat_var_%s' % self.repeat_count
@@ -164,7 +170,8 @@ def _StoreAction(self, param, tool=None):
164170

165171
# Moved because needed in developing repeat CLI
166172
if positional:
167-
flag_wo_dashes = 'positional_%s' % self.positional_count
173+
v = self.positional_count[param.dest]
174+
flag_wo_dashes = '%s%s' % (param.dest, '_' + str(v) if v > 1 else '')
168175
# SO unclean
169176
gxparam_extra_kwargs['positional'] = True
170177

examples/example-sub.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<tool id="example-sub.py foo" name="example-sub.py foo" version="1.0">
1+
<tool id="example-sub.py_foo" name="example-sub.py foo" version="1.0">
22
<description/>
33
<stdio>
44
<exit_code level="fatal" range="1:"/>
55
</stdio>
6-
<version_command>python examples/example-sub.py --version</version_command>
7-
<command interpreter="python"><![CDATA[example-sub.py foo $positional_1
6+
<version_command>python example-sub.py foo --version</version_command>
7+
<command><![CDATA[python example-sub.py foo $keyword
88
9-
#set repeat_var_2 = '" "'.join([ str($var.positional_2) for $var in $repeat_2 ])
9+
#set repeat_var_2 = '" "'.join([ str($var.integers) for $var in $repeat_2 ])
1010
"$repeat_var_2"
1111
1212
$sum
@@ -21,9 +21,9 @@ $sum
2121
$true
2222
> $default]]></command>
2323
<inputs>
24-
<param area="false" label="action keyword" name="positional_1" type="text"/>
24+
<param area="false" label="action keyword" name="keyword" type="text"/>
2525
<repeat min="1" name="repeat_2" title="repeat_title">
26-
<param label="an integer for the accumulator" name="positional_2" type="integer" value="0"/>
26+
<param label="an integer for the accumulator" name="integers" type="integer" value="0"/>
2727
</repeat>
2828
<param argument="--sum" checked="false" label="sum the integers (default: find the max)" name="sum" type="boolean" truevalue="--sum" falsevalue=""/>
2929
<param area="false" argument="--foo" label="foo help" name="foo" optional="true" type="text"/>
@@ -38,13 +38,13 @@ $true
3838
<help><![CDATA[TODO: Write help]]></help>
3939
</tool>
4040

41-
<tool id="example-sub.py bar" name="example-sub.py bar" version="2.0">
41+
<tool id="example-sub.py_bar" name="example-sub.py bar" version="2.0">
4242
<description/>
4343
<stdio>
4444
<exit_code level="fatal" range="1:"/>
4545
</stdio>
46-
<version_command>python examples/example-sub.py --version</version_command>
47-
<command interpreter="python"><![CDATA[example-sub.py bar $false
46+
<version_command>python example-sub.py bar --version</version_command>
47+
<command><![CDATA[python example-sub.py bar $false
4848
#for $i in $repeat_1:
4949
--append $i.append
5050
#end for

examples/example.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<stdio>
44
<exit_code level="fatal" range="1:"/>
55
</stdio>
6-
<version_command>python examples/example.py --version</version_command>
7-
<command interpreter="python"><![CDATA[example.py $positional_1
6+
<version_command>python example.py --version</version_command>
7+
<command><![CDATA[python example.py $keyword
88
9-
#set repeat_var_2 = '" "'.join([ str($var.positional_2) for $var in $repeat_2 ])
9+
#set repeat_var_2 = '" "'.join([ str($var.integers) for $var in $repeat_2 ])
1010
"$repeat_var_2"
1111
1212
$sum
@@ -32,9 +32,9 @@ $false
3232
#end if
3333
> $default]]></command>
3434
<inputs>
35-
<param area="false" label="action keyword" name="positional_1" type="text"/>
35+
<param area="false" label="action keyword" name="keyword" type="text"/>
3636
<repeat min="1" name="repeat_2" title="repeat_title">
37-
<param label="an integer for the accumulator" name="positional_2" type="integer" value="0"/>
37+
<param label="an integer for the accumulator" name="integers" type="integer" value="0"/>
3838
</repeat>
3939
<param argument="--sum" checked="false" label="sum the integers (default: find the max)" name="sum" type="boolean" truevalue="--sum" falsevalue=""/>
4040
<param area="false" argument="--foo" label="foo help" name="foo" optional="true" type="text"/>

0 commit comments

Comments
 (0)