dvc.yaml: preserve meta (#4008)

This commit is contained in:
Saugat Pachhai
2020-06-10 14:37:21 +03:00
committed by GitHub
parent 1d6c80001d
commit 64be262d18
2 changed files with 36 additions and 0 deletions
+2
View File
@@ -208,6 +208,8 @@ class PipelineFile(FileMixin):
if existing_entry:
orig_stage_data = data["stages"][stage.name]
if "meta" in orig_stage_data:
stage_data[stage.name]["meta"] = orig_stage_data["meta"]
apply_diff(stage_data[stage.name], orig_stage_data)
else:
data["stages"].update(stage_data)
+34
View File
@@ -290,3 +290,37 @@ def test_remove_stage_preserves_comment(tmp_dir, dvc, run_copy):
"# This copies 'foo' text to 'foo' file."
in (tmp_dir / PIPELINE_FILE).read_text()
)
def test_dvcfile_dump_preserves_meta(tmp_dir, dvc, run_copy):
tmp_dir.gen("foo", "foo")
stage = run_copy("foo", "bar", name="run_copy")
dvcfile = stage.dvcfile
data = dvcfile._load()[0]
metadata = {"name": "copy-file"}
data["stages"]["run_copy"]["meta"] = metadata
dump_yaml(dvcfile.path, data)
dvcfile.dump(stage, update_pipeline=True)
assert dvcfile._load()[0] == data
assert dvcfile._load()[0]["stages"]["run_copy"]["meta"] == metadata
def test_dvcfile_dump_preserves_comments(tmp_dir, dvc):
text = textwrap.dedent(
"""\
stages:
generate-foo:
cmd: echo foo > foo
# This copies 'foo' text to 'foo' file.
outs:
- foo"""
)
tmp_dir.gen("dvc.yaml", text)
stage = dvc.get_stage(name="generate-foo")
stage.outs[0].use_cache = False
dvcfile = stage.dvcfile
dvcfile.dump(stage, update_pipeline=True)
assert dvcfile._load()[1] == (text + ":\n\tcache: false\n".expandtabs())