config: Add plots.auto_open.

Option for enabling automatically open webbrowser with generated html.
Defaults False.

Closes #6091
This commit is contained in:
David de la Iglesia Castro
2022-01-03 16:07:23 +01:00
parent a73accd071
commit d8e2c14927
5 changed files with 29 additions and 12 deletions
+2 -2
View File
@@ -94,8 +94,8 @@ class CmdPlots(CmdBase):
)
ui.write(index_path.as_uri())
if self.args.open:
auto_open = self.repo.config["plots"].get("auto_open", False)
if self.args.open or auto_open:
return ui.open_browser(index_path)
return 0
+4 -1
View File
@@ -265,7 +265,10 @@ SCHEMA = {
# enabled by default. It's of no use, kept for backward compatibility.
Optional("parametrization", default=True): Bool,
},
"plots": {"html_template": str},
"plots": {
"html_template": str,
Optional("auto_open", default=False): Bool,
},
"exp": {
"code": str,
"data": str,
+2 -3
View File
@@ -20,7 +20,6 @@ def webbrowser_open(url: str) -> int:
def create_summary(out):
assert out.live and out.live["html"]
metrics, plots = out.repo.live.show(out.fs_path)
@@ -31,8 +30,8 @@ def create_summary(out):
index_path = render(
out.repo, renderers, metrics=metrics, path=html_path, refresh_seconds=5
)
webbrowser_open(index_path)
if out.repo.config["plots"].get("auto_open", False):
webbrowser_open(index_path)
def summary_fs_path(out: "Output") -> Optional[str]:
+9 -2
View File
@@ -241,7 +241,14 @@ def test_live_checkpoints_resume(
assert checkpoints_metric(results, "logs.json", "metric2") == [8, 6, 4, 2]
def test_dvc_generates_html_during_run(tmp_dir, dvc, mocker, live_stage):
@pytest.mark.parametrize("auto_open", [False, True])
def test_dvc_generates_html_during_run(
tmp_dir, dvc, mocker, live_stage, auto_open
):
if auto_open:
with dvc.config.edit() as conf:
conf["plots"]["auto_open"] = True
show_spy = mocker.spy(dvc.live, "show")
webbrowser_open = mocker.patch("dvc.repo.live.webbrowser_open")
@@ -265,7 +272,7 @@ def test_dvc_generates_html_during_run(tmp_dir, dvc, mocker, live_stage):
live_stage(summary=True, live="logs", code=script)
assert show_spy.call_count == 2
assert webbrowser_open.call_count == 2
assert webbrowser_open.call_count == (2 if auto_open else 0)
def test_dvclive_stage_with_different_wdir(tmp_dir, scm, dvc):
+12 -4
View File
@@ -138,11 +138,19 @@ def test_plots_diff_vega(dvc, mocker, capsys, plots_data):
render_mock.assert_not_called()
def test_plots_diff_open(tmp_dir, dvc, mocker, capsys, plots_data):
@pytest.mark.parametrize("auto_open", [True, False])
def test_plots_diff_open(tmp_dir, dvc, mocker, capsys, plots_data, auto_open):
mocked_open = mocker.patch("webbrowser.open", return_value=True)
cli_args = parse_args(
["plots", "diff", "--targets", "plots.csv", "--open"]
)
args = ["plots", "diff", "--targets", "plots.csv"]
if auto_open:
with dvc.config.edit() as conf:
conf["plots"]["auto_open"] = True
else:
args.append("--open")
cli_args = parse_args(args)
cmd = cli_args.func(cli_args)
mocker.patch("dvc.repo.plots.diff.diff", return_value=plots_data)