Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plots: allow top-level strings #8482

Merged
merged 3 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions dvc/repo/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
List,
Optional,
Set,
Union,
)

import dpath.options
Expand Down Expand Up @@ -444,16 +445,22 @@ def _collect_pipeline_files(repo, targets: List[str], props, onerror=None):
if isinstance(dvcfile, PipelineFile):
dvcfile_path = _relpath(repo.dvcfs, dvcfile.path)
dvcfile_defs = dvcfile.load().get("plots", {})
dvcfile_defs_dict: Dict[str, Union[Dict, None]] = {}
if isinstance(dvcfile_defs, list):
dvcfile_defs = {
k: v for elem in dvcfile_defs for k, v in elem.items()
}
for elem in dvcfile_defs:
if isinstance(elem, str):
dvcfile_defs_dict[elem] = None
else:
k, v = list(elem.items())[0]
dvcfile_defs_dict[k] = v
else:
dvcfile_defs_dict = dvcfile_defs
resolved = _resolve_definitions(
repo.dvcfs,
targets,
props,
dvcfile_path,
dvcfile_defs,
dvcfile_defs_dict,
onerror=onerror,
)
dpath.util.merge(
Expand Down
2 changes: 1 addition & 1 deletion dvc/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def validator(data):
str: either_or(STAGE_DEFINITION, FOREACH_IN, [FOREACH_KWD, DO_KWD])
}
MULTI_STAGE_SCHEMA = {
PLOTS: Any(SINGLE_PLOT_SCHEMA, [SINGLE_PLOT_SCHEMA]),
PLOTS: Any(SINGLE_PLOT_SCHEMA, [Any(str, SINGLE_PLOT_SCHEMA)]),
STAGES: SINGLE_PIPELINE_STAGE_SCHEMA,
VARS_KWD: VARS_SCHEMA,
}
Expand Down
3 changes: 3 additions & 0 deletions tests/func/test_dvcfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,16 @@ def test_dvcfile_load_dump_stage_with_desc_meta(tmp_dir, dvc):
"plots": {
"path/to/plot": {"x": "value", "y": "value"},
"path/to/another/plot": {"x": "value", "y": "value"},
"path/to/empty/plot": None,
},
"stages": STAGE_EXAMPLE,
},
{
"plots": [
{"path/to/plot": {"x": "value", "y": "value"}},
{"path/to/another/plot": {"x": "value", "y": "value"}},
{"path/to/empty/plot": None},
"path/to/plot/str",
],
"stages": STAGE_EXAMPLE,
},
Expand Down