diff --git a/dvc/commands/plots.py b/dvc/commands/plots.py index 87735e9c8..8caa782e6 100644 --- a/dvc/commands/plots.py +++ b/dvc/commands/plots.py @@ -69,7 +69,9 @@ class CmdPlots(CmdBase): "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") diff --git a/dvc/config_schema.py b/dvc/config_schema.py index aa495a890..3891660c7 100644 --- a/dvc/config_schema.py +++ b/dvc/config_schema.py @@ -269,6 +269,7 @@ SCHEMA = { "plots": { "html_template": str, Optional("auto_open", default=False): Bool, + "out_dir": str, }, "exp": { "code": str, diff --git a/tests/integration/plots/test_json.py b/tests/integration/plots/test_json.py index 6ba102292..75b7802b1 100644 --- a/tests/integration/plots/test_json.py +++ b/tests/integration/plots/test_json.py @@ -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()