don't allow loading stages without cmd (#5373)

* don't allow loading stages without `cmd`

This was loosened when introducing parametrization.
But, `foreach`..`do` should be considered first
before stage's regular structure. And, cmd is made
required (as it should have been)

Related: #5371, #5370, #5312

* fix schema
This commit is contained in:
Saugat Pachhai
2021-02-01 13:23:40 +05:45
committed by GitHub
parent b771b06b25
commit 131eb7b3a1
4 changed files with 11 additions and 4 deletions
+2 -2
View File
@@ -79,7 +79,7 @@ PARAM_PSTAGE_NON_DEFAULT_SCHEMA = {str: [str]}
VARS_SCHEMA = [str, dict]
STAGE_DEFINITION = {
StageParams.PARAM_CMD: Any(str, list),
Required(StageParams.PARAM_CMD): Any(str, list),
Optional(StageParams.PARAM_WDIR): str,
Optional(StageParams.PARAM_DEPS): [str],
Optional(StageParams.PARAM_PARAMS): [Any(str, dict)],
@@ -100,7 +100,7 @@ FOREACH_IN = {
Required(FOREACH_KWD): Any(dict, list, str),
Required(DO_KWD): STAGE_DEFINITION,
}
SINGLE_PIPELINE_STAGE_SCHEMA = {str: Any(STAGE_DEFINITION, FOREACH_IN)}
SINGLE_PIPELINE_STAGE_SCHEMA = {str: Any(FOREACH_IN, STAGE_DEFINITION)}
MULTI_STAGE_SCHEMA = {
STAGES: SINGLE_PIPELINE_STAGE_SCHEMA,
VARS_KWD: VARS_SCHEMA,
+6
View File
@@ -129,6 +129,12 @@ def to_pipeline_file(stage: "PipelineStage"):
params = _serialize_params_keys(params)
outs, metrics, plots, live = _serialize_outs(stage.outs)
cmd = stage.cmd
assert cmd, (
f"'{stage.PARAM_CMD}' cannot be empty for stage '{stage.name}', "
f"got: '{cmd}'(type: '{type(cmd).__name__}')"
)
res = [
(stage.PARAM_DESC, stage.desc),
(stage.PARAM_CMD, stage.cmd),
+2 -1
View File
@@ -145,8 +145,9 @@ def dummy_stage(tmp_dir, dvc):
def make(path="dvc.yaml", name="dummy_stage", **kwargs):
from dvc.stage import PipelineStage, create_stage
cmd = kwargs.get("cmd", "command")
stage = create_stage(
PipelineStage, dvc, path, name=name, cmd="", **kwargs
PipelineStage, dvc, path, name=name, cmd=cmd, **kwargs
)
stage.dump()
return stage
+1 -1
View File
@@ -6,7 +6,7 @@ from dvc.cli import parse_args
from dvc.command.status import CmdDataStatus
def test_cloud_status(mocker):
def test_cloud_status(tmp_dir, dvc, mocker):
cli_args = parse_args(
[
"status",