Skip to content

Commit

Permalink
revert get_dvc_stage_template (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Berenbaum authored Apr 22, 2023
1 parent bca4682 commit 0ec6860
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 113 deletions.
24 changes: 1 addition & 23 deletions src/dvclive/dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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": "<python my_code_file.py my_args>",
"deps": ["<my_code_file.py>"],
}
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
11 changes: 0 additions & 11 deletions src/dvclive/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
55 changes: 1 addition & 54 deletions tests/test_dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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": "<python my_code_file.py my_args>",
"deps": ["<my_code_file.py>"],
}
}
}


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": "<python my_code_file.py my_args>",
"deps": ["<my_code_file.py>"],
"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": "<python my_code_file.py my_args>",
"deps": ["<my_code_file.py>"],
"outs": ["sub/dir/artifact.txt"],
}
}
}


def test_untracked_dvclive_files_inside_dvc_exp_run_are_added(
tmp_dir, mocked_dvc_repo, monkeypatch
):
Expand Down
26 changes: 1 addition & 25 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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": "<python my_code_file.py my_args>",
"deps": ["<my_code_file.py>"],
}
}
}

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)

0 comments on commit 0ec6860

Please sign in to comment.