-
Notifications
You must be signed in to change notification settings - Fork 39
live: Handle auto_open via env. #243
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| from pathlib import Path | ||
| from typing import Any, Dict, Optional, Union | ||
|
|
||
| from . import env | ||
| from .data import DATA_TYPES, PLOTS, Image, Scalar | ||
| from .dvc import make_checkpoint | ||
| from .error import ( | ||
|
|
@@ -15,7 +16,7 @@ | |
| InvalidPlotTypeError, | ||
| ) | ||
| from .report import html_report | ||
| from .utils import nested_update, open_file_in_browser | ||
| from .utils import env2bool, nested_update, open_file_in_browser | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -28,14 +29,12 @@ def __init__( | |
| path: Optional[str] = None, | ||
| resume: bool = False, | ||
| report: Optional[str] = "html", | ||
| auto_open: bool = False, | ||
| ): | ||
|
|
||
| self._path: Optional[str] = path | ||
| self._resume: bool = resume | ||
| self._report: str = report | ||
| self._checkpoint: bool = False | ||
| self._auto_open: bool = auto_open | ||
| self.html_path = None | ||
|
|
||
| self.init_from_env() | ||
|
|
@@ -77,23 +76,19 @@ def _init_paths(self): | |
| os.makedirs(self.dir, exist_ok=True) | ||
|
|
||
| def init_from_env(self) -> None: | ||
| from . import env | ||
| if os.getenv(env.DVCLIVE_PATH): | ||
|
|
||
| if env.DVCLIVE_PATH in os.environ: | ||
|
|
||
| if self.dir and self.dir != os.environ[env.DVCLIVE_PATH]: | ||
| if self.dir and self.dir != os.getenv(env.DVCLIVE_PATH): | ||
| raise ConfigMismatchError(self) | ||
|
|
||
| env_config = { | ||
| "_path": os.environ.get(env.DVCLIVE_PATH), | ||
| "_checkpoint": bool( | ||
| int(os.environ.get(env.DVC_CHECKPOINT, "0")) | ||
| ), | ||
| "_resume": bool(int(os.environ.get(env.DVCLIVE_RESUME, "0"))), | ||
| "_path": os.getenv(env.DVCLIVE_PATH), | ||
| "_checkpoint": env2bool(env.DVC_CHECKPOINT), | ||
| "_resume": env2bool(env.DVCLIVE_RESUME), | ||
| } | ||
|
|
||
| # Keeping backward compatibility with `live` section | ||
| if not bool(int(os.environ.get(env.DVCLIVE_HTML, "0"))): | ||
| if not env2bool(env.DVCLIVE_HTML, "0"): | ||
| env_config["_report"] = None | ||
| else: | ||
| path = str(env_config["_path"]) | ||
|
|
@@ -196,9 +191,8 @@ def make_summary(self): | |
| def make_report(self): | ||
| if self._report == "html": | ||
| html_report(self.dir, self.summary_path, self.html_path) | ||
| if self._auto_open: | ||
| if env2bool(env.DVCLIVE_OPEN): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What should the default be? Should we try to detect tty if no environment variable is set? Are there ever cases where the report was auto opened by default before?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's currently False and I guess that's what should be
I'm not sure if it's worth the effort. We provide a way for users to handle the option in different environments, let's be explicit in docs about how to use it.
Only if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My worry is that the point of auto open is to make the simplest use case (showing the live report) as easy as possible, and this creates an additional step. It almost seems pointless to have the environment variable, since it's mostly for people who don't read the docs or can't immediately figure out how to open the report. Maybe it's not really an issue. I think it's fine to merge, but I'm curious about whether auto open is ever needed and if there's some way to make this scenario useful.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good points. If I remember correctly, requests for making it default False were coming from Vscode, not users. Perhaps it makes sense to default to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattseddon Would it be okay for you if we make the default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realized we have had this discussion before (multiple times 😅):
I don't think it's worth revisiting, so let's not open by default. It might be enough to hint about the environment variable like in https://github.com/iterative/dvc/blob/f84f9cf1846554a13f388693220378edb8d17be6/dvc/commands/plots.py#L111. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@daavoo What do you think about this idea? |
||
| open_file_in_browser(self.html_path) | ||
| self._auto_open = False | ||
|
|
||
| def read_step(self): | ||
| if Path(self.summary_path).exists(): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.