Skip to content

Commit

Permalink
exp save: Track top level files
Browse files Browse the repository at this point in the history
  • Loading branch information
daavoo committed Mar 31, 2023
1 parent 7c8e6e3 commit 24e10e0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions dvc/repo/experiments/executor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
ExpRefInfo,
)
from dvc.repo.experiments.utils import to_studio_params
from dvc.repo.metrics.show import _collect_top_level_metrics
from dvc.repo.params.show import _collect_top_level_params
from dvc.stage.serialize import to_lockfile
from dvc.ui import ui
from dvc.utils import dict_sha256, env2bool, relpath
Expand Down Expand Up @@ -275,6 +277,13 @@ def save(
else:
os.chdir(dvc.root_dir)

include_untracked = include_untracked or []
include_untracked.extend(_collect_top_level_metrics(dvc))
include_untracked.extend(_collect_top_level_params(dvc))
include_untracked.extend(
dvc.index._plot_sources # pylint: disable=protected-access
)

try:
stages = dvc.commit([], force=True, relink=False)
exp_hash = cls.hash_exp(stages)
Expand Down
20 changes: 20 additions & 0 deletions tests/func/experiments/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,23 @@ def test_exp_save_include_untracked_warning(tmp_dir, dvc, scm, mocker):

dvc.experiments.save(name="exp", include_untracked=["new_dir"])
assert not logger.warning.called


def test_untracked_top_level_files_are_included_in_exp(tmp_dir, scm, dvc):
(tmp_dir / "dvc.yaml").dump(
{
"metrics": ["metrics.json"],
"params": ["params.yaml"],
"plots": ["plots.csv"],
}
)
stage = dvc.stage.add(
cmd="touch metrics.json && touch params.yaml && touch plots.csv",
name="top-level",
)
scm.add_commit(["dvc.yaml"], message="add dvc.yaml")
dvc.reproduce(stage.addressing)
exp = dvc.experiments.save()
fs = scm.get_fs(exp)
for file in ["metrics.json", "params.yaml", "plots.csv"]:
assert fs.exists(file)

0 comments on commit 24e10e0

Please sign in to comment.