Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/dvclive/dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ def update_dvcyaml(live, updates):
from dvc.utils.serialize import modify_yaml

dvcyaml_dir = os.path.abspath(os.path.dirname(live.dvc_file))
dvclive_dir = os.path.relpath(live.dir, dvcyaml_dir) + "/"
# Entries are written with POSIX separators (see `rel_path`), so the prefix
# used to recognize them has to be POSIX too. Using the native separator
# here means no existing entry matches on Windows and stale entries pile up
# instead of being replaced.
dvclive_dir = Path(os.path.relpath(live.dir, dvcyaml_dir)).as_posix() + "/"

def _drop_stale_dvclive_entries(entries):
non_dvclive = []
Expand Down
20 changes: 20 additions & 0 deletions tests/test_make_dvcyaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,23 @@ def test_make_dvcyaml_none(tmp_dir, mocker):
dvclive.end()

assert not os.path.exists("dvc.yaml")


def test_make_dvcyaml_nested_dir_not_duplicated(tmp_dir, mocked_dvc_repo):
"""
Regression test for iterative/dvclive#848.

Entries are written with POSIX separators, so the prefix used to recognize
and replace them must be POSIX as well. On Windows the native separator
made every existing entry look foreign, and rerunning appended a duplicate
instead of replacing it. Only reproducible on Windows; a no-op elsewhere.
"""
for _ in range(2):
live = Live(os.path.join("dvclive", "subdir"), dvcyaml="dvc.yaml")
live.log_metric("metric", 1)
make_dvcyaml(live)

assert load_yaml(live.dvc_file) == {
"metrics": ["dvclive/subdir/metrics.json"],
"plots": [{"dvclive/subdir/plots/metrics": {"x": "step"}}],
}