From 8a608e0a0fd4b6a987e5eedeb953b44de3ca5157 Mon Sep 17 00:00:00 2001 From: John Chilton Date: Thu, 22 Jun 2017 14:06:11 -0400 Subject: [PATCH] Normalize special handling for galaxy_root in ~/.planemo.yml. --- planemo/config.py | 16 ++++++++++------ planemo/galaxy/config.py | 2 -- planemo/options.py | 3 +++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/planemo/config.py b/planemo/config.py index a39376708..85b588eee 100644 --- a/planemo/config.py +++ b/planemo/config.py @@ -19,7 +19,7 @@ def _default_callback( - default, use_global_config=False, resolve_path=False, + default, use_global_config=False, resolve_path=False, extra_global_config_vars=[], ): def callback(ctx, param, value): @@ -33,6 +33,7 @@ def callback(ctx, param, value): planemo_ctx, param, use_global_config=use_global_config, + extra_global_config_vars=extra_global_config_vars, ) if result is VALUE_UNSET: @@ -51,13 +52,14 @@ def callback(ctx, param, value): return callback -def _find_default(ctx, param, use_global_config): +def _find_default(ctx, param, use_global_config, extra_global_config_vars): if use_global_config: global_config = ctx.global_config - global_config_key = "default_%s" % param.name - if global_config_key in global_config: - default_value = global_config[global_config_key] - return default_value, OptionSource.global_config + global_config_keys = ["default_%s" % param.name] + extra_global_config_vars + for global_config_key in global_config_keys: + if global_config_key in global_config: + default_value = global_config[global_config_key] + return default_value, OptionSource.global_config return VALUE_UNSET, None @@ -73,6 +75,7 @@ def planemo_option(*args, **kwargs): option_type = kwargs.get("type", None) use_global_config = kwargs.pop("use_global_config", False) use_env_var = kwargs.pop("use_env_var", False) + extra_global_config_vars = kwargs.pop("extra_global_config_vars", []) default_specified = "default" in kwargs default = None @@ -87,6 +90,7 @@ def callback(ctx, param, value): result = _default_callback( default, use_global_config=use_global_config, + extra_global_config_vars=extra_global_config_vars, resolve_path=resolve_path, )(ctx, param, value) diff --git a/planemo/galaxy/config.py b/planemo/galaxy/config.py index 530127a71..6e41eebee 100644 --- a/planemo/galaxy/config.py +++ b/planemo/galaxy/config.py @@ -977,8 +977,6 @@ def _find_galaxy_root(ctx, **kwds): galaxy_root = kwds.get(root_prop, None) if galaxy_root: return galaxy_root - elif ctx.global_config.get(root_prop, None): - return ctx.global_config[root_prop] else: par_dir = os.getcwd() while True: diff --git a/planemo/options.py b/planemo/options.py index e95dfe318..1afd9a107 100644 --- a/planemo/options.py +++ b/planemo/options.py @@ -122,6 +122,7 @@ def galaxy_root_option(): return planemo_option( "--galaxy_root", use_global_config=True, + extra_global_config_vars=["galaxy_root"], 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.", @@ -143,6 +144,8 @@ def galaxy_cwl_root_option(): return planemo_option( "--cwl_galaxy_root", use_global_config=True, + extra_global_config_vars=["cwl_galaxy_root"], + 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" " (must be branch of Galaxy with CWL support, this option"