From 0ec68604ddd7ed7f1c0f64fb4e40048bad37fed3 Mon Sep 17 00:00:00 2001 From: Dave Berenbaum Date: Sat, 22 Apr 2023 04:04:27 -0400 Subject: [PATCH] revert get_dvc_stage_template (#540) --- src/dvclive/dvc.py | 24 +------------------- src/dvclive/live.py | 11 --------- tests/test_dvc.py | 55 +-------------------------------------------- tests/test_main.py | 26 +-------------------- 4 files changed, 3 insertions(+), 113 deletions(-) diff --git a/src/dvclive/dvc.py b/src/dvclive/dvc.py index b9c65e78..76d67725 100644 --- a/src/dvclive/dvc.py +++ b/src/dvclive/dvc.py @@ -2,12 +2,11 @@ import logging import os import random -from io import StringIO from pathlib import Path from dvclive import env from dvclive.plots import Image, Metric -from dvclive.serialize import dump_yaml, get_yaml +from dvclive.serialize import dump_yaml logging.basicConfig() logger = logging.getLogger("dvclive") @@ -165,24 +164,3 @@ def get_random_exp_name(scm, baseline_rev): exp_ref = ExpRefInfo(baseline_sha=baseline_rev, name=name) if not scm.get_ref(str(exp_ref)): return name - - -def get_dvc_stage_template(live): - stage = { - "cmd": "", - "deps": [""], - } - if live._artifacts: - stage["outs"] = [] - for artifact in live._artifacts.values(): - o = artifact["path"] - artifact_path = Path(os.getcwd()) / o - artifact_path = artifact_path.relative_to(live._dvc_repo.root_dir).as_posix() - stage["outs"].append(artifact_path) - dvcyaml_dict = {"stages": {"dvclive": stage}} - - output = StringIO() - get_yaml().dump(dvcyaml_dict, output) - dvcyaml = output.getvalue() - output.close() - return dvcyaml diff --git a/src/dvclive/live.py b/src/dvclive/live.py index 65afd825..42c1f3b6 100644 --- a/src/dvclive/live.py +++ b/src/dvclive/live.py @@ -14,7 +14,6 @@ from . import env from .dvc import ( get_dvc_repo, - get_dvc_stage_template, get_random_exp_name, make_checkpoint, make_dvcyaml, @@ -433,16 +432,6 @@ def end(self): else: self.make_report() - if self._dvc_repo and not self._inside_dvc_exp: - from dvc.exceptions import DvcException - - try: - path = os.path.join(self._dvc_repo.root_dir, "dvc.yaml") - yaml = get_dvc_stage_template(self) - logger.info(f"To run with DVC, add this to {path}:\n{yaml}") - except DvcException as e: - logger.warning(f"Failed to print DVC stage template:\n{e}") - def make_checkpoint(self): if env2bool(env.DVC_CHECKPOINT): make_checkpoint() diff --git a/tests/test_dvc.py b/tests/test_dvc.py index c96b1886..89390e3f 100644 --- a/tests/test_dvc.py +++ b/tests/test_dvc.py @@ -7,7 +7,7 @@ from scmrepo.git import Git from dvclive import Live -from dvclive.dvc import get_dvc_repo, get_dvc_stage_template, make_dvcyaml +from dvclive.dvc import get_dvc_repo, make_dvcyaml from dvclive.env import DVC_EXP_BASELINE_REV, DVC_EXP_NAME from dvclive.serialize import load_yaml @@ -217,59 +217,6 @@ def test_exp_save_dvcexception_is_ignored(tmp_dir, mocker): pass -def test_get_dvc_stage_template_empty(tmp_dir, mocked_dvc_repo): - live = Live() - template = get_dvc_stage_template(live) - - assert YAML_LOADER.load(template) == { - "stages": { - "dvclive": { - "cmd": "", - "deps": [""], - } - } - } - - -def test_get_dvc_stage_template_artifacts(tmp_dir, mocked_dvc_repo): - live = Live() - live.log_artifact("artifact.txt") - template = get_dvc_stage_template(live) - - assert YAML_LOADER.load(template) == { - "stages": { - "dvclive": { - "cmd": "", - "deps": [""], - "outs": ["artifact.txt"], - } - } - } - - -def test_get_dvc_stage_template_chdir(tmp_dir, mocked_dvc_repo, monkeypatch): - d = tmp_dir / "sub" / "dir" - d.mkdir(parents=True) - monkeypatch.chdir(d) - live = Live("live") - live.log_param("foo", 1) - live.log_metric("bar", 1) - live.log_image("img.png", Image.new("RGB", (10, 10), (250, 250, 250))) - live.log_sklearn_plot("confusion_matrix", [0, 0, 1, 1], [0, 1, 1, 0]) - live.log_artifact("artifact.txt") - template = get_dvc_stage_template(live) - - assert YAML_LOADER.load(template) == { - "stages": { - "dvclive": { - "cmd": "", - "deps": [""], - "outs": ["sub/dir/artifact.txt"], - } - } - } - - def test_untracked_dvclive_files_inside_dvc_exp_run_are_added( tmp_dir, mocked_dvc_repo, monkeypatch ): diff --git a/tests/test_main.py b/tests/test_main.py index 3342dc2a..adeec46a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,13 +1,12 @@ import json import os -from io import StringIO import pytest from dvclive import Live, env from dvclive.error import InvalidDataTypeError, InvalidParameterTypeError from dvclive.plots import Metric -from dvclive.serialize import get_yaml, load_yaml +from dvclive.serialize import load_yaml from dvclive.utils import parse_metrics, parse_tsv @@ -483,26 +482,3 @@ def test_make_dvcyaml(tmp_dir, dvcyaml): dvcyaml_path = tmp_dir / dvclive.dir / "dvc.yaml" assert dvcyaml_path.is_file() - - -def test_get_dvc_stage_template(tmp_dir, mocker, mocked_dvc_repo): - logger = mocker.patch("dvclive.live.logger") - dvclive = Live() - dvclive.end() - - template = { - "stages": { - "dvclive": { - "cmd": "", - "deps": [""], - } - } - } - - output = StringIO() - get_yaml().dump(template, output) - yaml_str = output.getvalue() - output.close() - path_str = os.path.join(tmp_dir, "dvc.yaml") - log_str = f"To run with DVC, add this to {path_str}:\n{yaml_str}" - logger.info.assert_called_with(log_str)