Skip to content
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
19 changes: 18 additions & 1 deletion dvc/repo/live.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import logging
import webbrowser
from pathlib import Path
from platform import uname
from typing import TYPE_CHECKING, List, Optional

from funcy import once_per_args

from dvc.render.utils import render

logger = logging.getLogger(__name__)
Expand All @@ -10,15 +15,27 @@
from dvc.path_info import PathInfo
from dvc.repo import Repo

webbrowser_open = once_per_args(webbrowser.open)


def create_summary(out):

assert out.live and out.live["html"]

metrics, plots = out.repo.live.show(str(out.path_info))

html_path = out.path_info.fspath + "_dvc_plots"

render(out.repo, plots, metrics=metrics, path=html_path, refresh_seconds=5)
index_path = render(
out.repo, plots, metrics=metrics, path=html_path, refresh_seconds=5
)

url = index_path.as_uri()

if "Microsoft" in uname().release:
url = Path(index_path) / "index.html"

webbrowser_open(url)
Comment on lines +33 to +38
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this piece to ui? Maybe as ui.launch (similar to click.launch) or ui.open_browser? We can handle all relpath, uri and WSL stuff inside it. What do you think?

Copy link
Contributor Author

@daavoo daavoo Nov 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Will do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #6993



def summary_path_info(out: "Output") -> Optional["PathInfo"]:
Expand Down
2 changes: 2 additions & 0 deletions tests/func/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def test_live_checkpoints_resume(

def test_dvc_generates_html_during_run(tmp_dir, dvc, mocker, live_stage):
show_spy = mocker.spy(dvc.live, "show")
webbrowser_open = mocker.patch("dvc.repo.live.webbrowser_open")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daavoo, it seems that the above change affected all of the tests and now opens the browser while running the tests.


# make sure script takes more time to execute than one monitor sleep cycle
monitor_await_time = 0.01
Expand All @@ -258,6 +259,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


def test_dvclive_stage_with_different_wdir(tmp_dir, scm, dvc):
Expand Down