Skip to content
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

live: warn when DVC_ROOT is set but DVC_EXP_BASELINE_REV is not #702

Merged
merged 2 commits into from
Sep 20, 2023
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
29 changes: 20 additions & 9 deletions src/dvclive/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,7 @@ def _init_cleanup(self):
def _init_dvc(self):
from dvc.scm import NoSCM

if os.getenv(env.DVC_EXP_BASELINE_REV, None):
# `dvc exp` execution
self._baseline_rev = os.getenv(env.DVC_EXP_BASELINE_REV, "")
self._exp_name = os.getenv(env.DVC_EXP_NAME, "")
self._inside_dvc_exp = True
if self._save_dvc_exp:
logger.info("Ignoring `save_dvc_exp` because `dvc exp run` is running")
self._save_dvc_exp = False

self._init_dvc_pipeline()
self._dvc_repo = get_dvc_repo()

dvc_logger = logging.getLogger("dvc")
Expand Down Expand Up @@ -183,6 +175,25 @@ def _init_dvc(self):
mark_dvclive_only_started(self._exp_name)
self._include_untracked.append(self.dir)

def _init_dvc_pipeline(self):
if os.getenv(env.DVC_EXP_BASELINE_REV, None):
# `dvc exp` execution
self._baseline_rev = os.getenv(env.DVC_EXP_BASELINE_REV, "")
self._exp_name = os.getenv(env.DVC_EXP_NAME, "")
self._inside_dvc_exp = True
if self._save_dvc_exp:
logger.info("Ignoring `save_dvc_exp` because `dvc exp run` is running")
self._save_dvc_exp = False
elif os.getenv(env.DVC_ROOT, None):
# `dvc repro` execution
daavoo marked this conversation as resolved.
Show resolved Hide resolved
if self._save_dvc_exp:
logger.info("Ignoring `save_dvc_exp` because `dvc repro` is running")
self._save_dvc_exp = False
logger.warning(
"Some DVCLive features are unsupported in `dvc repro`."
"\nTo use DVCLive with a DVC Pipeline, run it with `dvc exp run`."
)

def _init_studio(self):
self._dvc_studio_config = get_dvc_studio_config(self)
if not self._dvc_studio_config:
Expand Down
9 changes: 8 additions & 1 deletion tests/test_dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from dvclive import Live
from dvclive.dvc import get_dvc_repo, make_dvcyaml
from dvclive.env import DVC_EXP_BASELINE_REV, DVC_EXP_NAME
from dvclive.env import DVC_EXP_BASELINE_REV, DVC_EXP_NAME, DVC_ROOT
from dvclive.serialize import load_yaml

YAML_LOADER = YAML(typ="safe")
Expand Down Expand Up @@ -322,3 +322,10 @@ def test_no_scm_repo(tmp_dir, mocker):

live = Live(save_dvc_exp=True)
assert live._save_dvc_exp is False


def test_dvc_repro(tmp_dir, monkeypatch, mocker):
monkeypatch.setenv(DVC_ROOT, "root")
mocker.patch("dvclive.live.get_dvc_repo", return_value=None)
live = Live(save_dvc_exp=True)
assert not live._save_dvc_exp