Skip to content

Commit

Permalink
dvc plots: allow for setting output directory via config
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury committed Jun 20, 2022
1 parent 604e017 commit 1d98b9b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dvc/commands/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def run(self):
"visualization file will not be created."
)

out: str = self.args.out or "dvc_plots"
out: str = self.args.out or self.repo.config.get("plots", {}).get(
"out_dir", "dvc_plots"
)

renderers_out = (
out if self.args.json else os.path.join(out, "static")
Expand Down
1 change: 1 addition & 0 deletions dvc/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class RelPath(str):
"plots": {
"html_template": str,
Optional("auto_open", default=False): Bool,
"out_dir": str,
},
"exp": {
"code": str,
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/plots/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,30 @@ def test_repo_with_removed_plots(tmp_dir, capsys, repo_with_plots):
for p in {"linear.json", "confusion.json", "image.png"}:
assert json_result[p] == []
assert split_json_result[p] == []


def test_config_output_dir(tmp_dir, dvc, capsys):
subdir = tmp_dir / "subdir"
ret = main(["config", "plots.out_dir", os.fspath(subdir)])
assert ret == 0

metric = [{"first_val": 100, "val": 2}, {"first_val": 200, "val": 3}]
(tmp_dir / "metric.json").dump_json(metric, sort_keys=True)

assert main(["plots", "show", "metric.json"]) == 0

out, _ = capsys.readouterr()
assert subdir.as_uri() in out
assert subdir.is_dir()
assert (subdir / "index.html").is_file()

cli_arg_subdir = tmp_dir / "cli_option"
assert (
main(["plots", "show", "-o", os.fspath(cli_arg_subdir), "metric.json"])
== 0
)

out, _ = capsys.readouterr()
assert cli_arg_subdir.as_uri() in out
assert cli_arg_subdir.is_dir()
assert (cli_arg_subdir / "index.html").is_file()

0 comments on commit 1d98b9b

Please sign in to comment.