def _resolve_dep_attr_refs(attr_val, flag_vals, resdef): try: return util.resolve_refs(attr_val, flag_vals) except util.UndefinedReferenceError as e: raise OpDependencyError( "invalid flag reference '%s' in dependency '%s'" % (resdef.name, e.reference))
def _render_label_template(label_template, default_label, flag_vals): resolve_vals = { "default_label": default_label, } resolve_vals.update({ name: flag_util.encode_flag_val(val) for name, val in flag_vals.items() if val is not None }) return util.resolve_refs(label_template, resolve_vals, "")
def _gen_args(op_cmd, flag_vals, resolve_params): encoded_resolve_params = _encode_params(resolve_params) args = [] for arg in op_cmd.cmd_args: if arg == "__flag_args__": args.extend(_flag_args(flag_vals, op_cmd.cmd_flags, args)) else: args.append(util.resolve_refs(arg, encoded_resolve_params)) return args
def _resdef_for_dep(depdef, flag_vals): if depdef.inline_resource: return depdef.inline_resource, depdef.opdef.guildfile.dir res_spec = util.resolve_refs(depdef.spec, flag_vals) return util.find_apply([ _model_resource, _guildfile_resource, _package_resource, _invalid_dependency_error, ], res_spec, depdef)
def _apply_flag_arg(flagdef, value, flag_vals, target, flag_map): if flagdef.arg_name: arg_name = flagdef.arg_name flag_map[arg_name] = flagdef.name else: arg_name = flagdef.name arg_val = util.resolve_refs(value, flag_vals) if flagdef.arg_switch is not None: if arg_val == flagdef.arg_switch: target[arg_name] = NO_ARG_VALUE else: target[arg_name] = arg_val
def _apply_choice_args(flagdef, val, flag_vals, target): for choice in flagdef.choices: if choice.value == val: if choice.args: args = { name: util.resolve_refs(val, flag_vals) for name, val in choice.args.items() } # Choice args must not overwrite existing args # (i.e. default values from other flags or values from # user) for name in args: if name not in target: target[name] = args[name] break
def _pre_proc(self): assert self._run is not None if not self.opdef.pre_process: return cmd_unresolved = self.opdef.pre_process.strip() cmd = util.resolve_refs(cmd_unresolved, self.flag_vals) cwd = self._run.path # env init order matters - we want _proc_env() to take # precedence over _cmd_arg_env() env = _cmd_arg_env(self.cmd_args) env.update(self._proc_env()) log.debug("pre-process command: %s", cmd) log.debug("pre-process env: %s", env) log.debug("pre-process cwd: %s", cwd) subprocess.check_call(cmd, shell=True, env=env, cwd=cwd)
def _dependency_resource(dep, flag_vals, ctx): if dep.inline_resource: return _inline_resource(dep.inline_resource, ctx) spec = util.resolve_refs(dep.spec, flag_vals) try: res = util.find_apply( [_model_resource, _guildfile_resource, _packaged_resource], spec, ctx) except DependencyError as e: if spec in ctx.resource_config: log.warning(str(e)) return ResourceProxy(dep, spec, ctx.resource_config[spec], ctx) raise if res: res.dependency = spec return res raise DependencyError("invalid dependency '%s' in operation '%s'" % (spec, ctx.opdef.fullname))
def _resolve_env_flag_refs(flag_vals, env): for env_name, env_val in env.items(): env[env_name] = util.resolve_refs(env_val, flag_vals)
def _is_resource(name, opdef, ref_vars): for dep in opdef.dependencies: resolved_spec = util.resolve_refs(dep.name, ref_vars, undefined=None) if resolved_spec == name: return True return False
def _split_and_resolve_args(cmd, flag_vals): """Splits and resolve args for string or list cmd.""" format_part = lambda part: str(util.resolve_refs(part, flag_vals)) return [format_part(part) for part in op_util.split_cmd(cmd)]
def _apply_env_to_path(path): """Replaces occurrences of ${NAME} with env values.""" return util.resolve_refs(path, os.environ)
def _resolve_param(params, name, flags): resolved = util.resolve_refs(params[name], flags) if resolved is None: return resolved return str(resolved)
def _resolve_flag_vals(flags, parent_flags): return { name: util.resolve_refs(val, parent_flags) for name, val in flags.items() }
def _resource_names(opdef, parsed_run_args): ref_vars = _ref_vars_for_resource_lookup(parsed_run_args, opdef) return { util.resolve_refs(dep.name, ref_vars, undefined=None): dep for dep in opdef.dependencies }
def _resolve_refs(val, flags): resolved = util.resolve_refs(val, flags) if resolved is None: return None return str(resolved)
def _render_label_template(label_template, flag_vals): resolve_vals = { name: flag_util.encode_flag_val(val) for name, val in flag_vals.items() if val is not None } return util.resolve_refs(label_template, resolve_vals, "")