Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions planemo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def set_option_source(self, param_name, option_source, force=False):

def get_option_source(self, param_name):
"""Return OptionSource value indicating how the option was set."""
assert param_name in self.option_source
assert param_name in self.option_source, "No option source for [%s]" % param_name
return self.option_source[param_name]

@property
Expand Down Expand Up @@ -163,7 +163,7 @@ def get_command(self, ctx, name):
def command_function(f):
"""Extension point for processing kwds after click callbacks."""
@functools.wraps(f)
def handle_profile_options(*args, **kwds):
def handle_blended_options(*args, **kwds):
profile = kwds.get("profile", None)
if profile:
ctx = args[0]
Expand All @@ -172,12 +172,48 @@ def handle_profile_options(*args, **kwds):
)
_setup_profile_options(ctx, profile_defaults, kwds)

_setup_galaxy_source_options(args[0], kwds)

try:
return f(*args, **kwds)
except ExitCodeException as e:
sys.exit(e.exit_code)

return pass_context(handle_profile_options)
return pass_context(handle_blended_options)


EXCLUSIVE_OPTIONS_LIST = [
("galaxy_root", "galaxy_branch"),
("galaxy_root", "galaxy_source"),
]


def _setup_galaxy_source_options(ctx, kwds):
for exclusive_options in EXCLUSIVE_OPTIONS_LIST:
option_source = {}
for option in exclusive_options:
if option in kwds:
option_source[option] = ctx.get_option_source(option)
else:
option_source[option] = None

most_authoratative_source = None
most_authoratative_source_options = []
for key, value in option_source.items():
if value is None:
continue
if most_authoratative_source is None or value.value < most_authoratative_source.value:
most_authoratative_source = value
most_authoratative_source_options = [key]
elif value == most_authoratative_source:
most_authoratative_source_options.append(key)

if most_authoratative_source != OptionSource.default and len(most_authoratative_source_options) > 1:
raise click.UsageError("Cannot specify multiple of %s" % most_authoratative_source_options)

for option in exclusive_options:
if option in kwds and option not in most_authoratative_source_options:
del kwds[option]


def _setup_profile_options(ctx, profile_defaults, kwds):
Expand Down
3 changes: 3 additions & 0 deletions planemo/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def galaxy_email_option():
def galaxy_root_option():
return planemo_option(
"--galaxy_root",
use_global_config=True,
use_env_var=True,
type=click.Path(exists=True, file_okay=False, resolve_path=True),
help="Root of development galaxy directory to execute command with.",
)
Expand Down Expand Up @@ -386,6 +388,7 @@ def galaxy_branch_option():
"--galaxy_branch",
default=None,
use_global_config=True,
use_env_var=True,
help=("Branch of Galaxy to target (defaults to master) if a Galaxy "
"root isn't specified.")
)
Expand Down