def create_stage_from_cli(repo: "Repo", single_stage: bool = False, fname: str = None, **kwargs: Any) -> Union["Stage", "PipelineStage"]: from dvc.dvcfile import PIPELINE_FILE from . import PipelineStage, Stage, create_stage, restore_meta if single_stage: kwargs.pop("name", None) stage_cls = Stage path = fname or _get_file_path(kwargs) else: stage_name = kwargs.get("name", None) path = PIPELINE_FILE stage_cls = PipelineStage if not (stage_name and is_valid_name(stage_name)): raise InvalidStageName params = chunk_dict(parse_params(kwargs.pop("params", []))) stage = create_stage(stage_cls, repo=repo, path=path, params=params, **kwargs) restore_meta(stage) return stage
def run(self): kwargs = vars(self.args) kwargs.update({ "cmd": parse_cmd(kwargs.pop("cmd")), "params": parse_params(self.args.params), }) self.repo.stage.add(**kwargs) return 0
def create_stage_from_cli( repo: "Repo", single_stage: bool = False, fname: str = None, validate: bool = False, force: bool = False, **kwargs: Any, ) -> Union["Stage", "PipelineStage"]: from dvc.dvcfile import PIPELINE_FILE from . import PipelineStage, Stage, create_stage, restore_meta cmd = kwargs.get("cmd") if not cmd: raise InvalidArgumentError("command is not specified") stage_name = kwargs.get("name") if stage_name and single_stage: raise InvalidArgumentError( "`-n|--name` is incompatible with `--single-stage`") if stage_name and fname: raise InvalidArgumentError( "`--file` is currently incompatible with `-n|--name` " "and requires `--single-stage`") if not stage_name and not single_stage: raise InvalidArgumentError("`-n|--name` is required") if single_stage: kwargs.pop("name", None) stage_cls = Stage path = fname or _get_file_path(kwargs) else: path = PIPELINE_FILE stage_cls = PipelineStage if not (stage_name and is_valid_name(stage_name)): raise InvalidStageName kwargs["cmd"] = cmd[0] if isinstance(cmd, list) and len(cmd) == 1 else cmd kwargs["live_summary"] = not kwargs.pop("live_no_summary", False) kwargs["live_html"] = not kwargs.pop("live_no_html", False) params = chunk_dict(parse_params(kwargs.pop("params", []))) stage = create_stage(stage_cls, repo=repo, path=path, params=params, **kwargs) if validate: validate_state(repo, stage, force=force) restore_meta(stage) return stage
def test_parse_params(): assert parse_params([ "param1", "file1:param1,param2", "file2:param2", "file1:param3,param4,", "param2,param10", "param3,", "file3:", ]) == { "params.yaml": ["param1", "param2", "param10", "param3"], "file1": ["param1", "param2", "param3", "param4"], "file2": ["param2"], "file3": [], }
def run(self: "Repo", no_exec: bool = False, no_commit: bool = False, run_cache: bool = True, force: bool = True, **kwargs) -> Union["Stage", "PipelineStage"]: kwargs.update({ "force": force, "params": parse_params(kwargs.get("params", [])) }) stage = self.stage.create(**kwargs) if no_exec: stage.ignore_outs() else: stage.run(no_commit=no_commit, run_cache=run_cache) stage.dump(update_lock=not no_exec) return stage