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

ENH: variadic inputs #171

Merged
merged 2 commits into from Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions q2cli/cache.py
Expand Up @@ -277,13 +277,13 @@ def _get_action_state(self, action):
sig = action.signature
for name, spec in itertools.chain(sig.signature_order.items(),
sig.outputs.items()):
data = {'name': name, 'repr': repr(spec.qiime_type)}
data = {'name': name, 'repr': repr(spec.qiime_type),
'ast': spec.qiime_type.to_ast()}

if name in sig.inputs:
type = 'input'
elif name in sig.parameters:
type = 'parameter'
data['ast'] = spec.qiime_type.to_ast()
else:
type = 'output'
data['type'] = type
Expand Down
18 changes: 12 additions & 6 deletions q2cli/commands.py
Expand Up @@ -147,19 +147,25 @@ def __init__(self, name, plugin, action):
def build_generated_handlers(self):
import q2cli.handlers

handler_map = {
'input': q2cli.handlers.ArtifactHandler,
'parameter': q2cli.handlers.parameter_handler_factory,
'output': q2cli.handlers.ResultHandler
}

handlers = collections.OrderedDict()
for item in self.action['signature']:
item = item.copy()
type = item.pop('type')

if type == 'input':
handler = q2cli.handlers.ArtifactHandler
elif type == 'parameter':
handler = q2cli.handlers.parameter_handler_factory
if item['ast']['type'] == 'collection':
inner_handler = handler_map[type](**item)
handler = q2cli.handlers.CollectionHandler(inner_handler,
**item)
else:
handler = q2cli.handlers.ResultHandler
handler = handler_map[type](**item)

handlers[item['name']] = handler(**item)
handlers[item['name']] = handler

return handlers

Expand Down
37 changes: 37 additions & 0 deletions q2cli/core.py
Expand Up @@ -106,3 +106,40 @@ def decorator(f):
return click.option(*param_decls, **attrs)(f)

return decorator


class MultipleType(click.ParamType):
"""This is just a wrapper, it doesn't do anything on its own"""
def __init__(self, param_type):
self.param_type = param_type

@property
def name(self):
return "MULTIPLE " + self.param_type.name

def convert(self, value, param, ctx):
# Don't convert anything yet.
return value

def fail(self, *args, **kwargs):
return self.param_type.fail(*args, **kwargs)

def get_missing_message(self, *args, **kwargs):
return self.param_type.get_missing_message(*args, **kwargs)

def get_metavar(self, *args, **kwargs):
metavar = self.param_type.get_metavar(*args, **kwargs)
if metavar is None:
return None
return "MULTIPLE " + metavar


class ResultPath(click.Path):
def __init__(self, repr, *args, **kwargs):
super().__init__(*args, **kwargs)
self.repr = repr

def get_metavar(self, param):
if self.repr != 'Visualization':
return "ARTIFACT PATH " + self.repr
return "VISUALIZATION PATH"