mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
exp run: Add --copy-paths arg.
List of paths to copy inside the temp directory. Only used if `--temp` or `--queue` is specified. Closes #5800
This commit is contained in:
@@ -9,7 +9,7 @@ from configobj import ConfigObj
|
||||
from funcy import first
|
||||
|
||||
from dvc.dvcfile import PROJECT_FILE
|
||||
from dvc.exceptions import ReproductionError
|
||||
from dvc.exceptions import DvcException, ReproductionError
|
||||
from dvc.repo.experiments.exceptions import ExperimentExistsError
|
||||
from dvc.repo.experiments.queue.base import BaseStashQueue
|
||||
from dvc.repo.experiments.refs import CELERY_STASH
|
||||
@@ -704,3 +704,43 @@ def test_untracked_top_level_files_are_included_in_exp(tmp_dir, scm, dvc, tmp):
|
||||
fs = scm.get_fs(exp)
|
||||
for file in ["metrics.json", "params.yaml", "plots.csv"]:
|
||||
assert fs.exists(file)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("tmp", [True, False])
|
||||
def test_copy_paths(tmp_dir, scm, dvc, tmp):
|
||||
stage = dvc.stage.add(
|
||||
cmd="cat file && ls dir",
|
||||
name="foo",
|
||||
)
|
||||
scm.add_commit(["dvc.yaml"], message="add dvc.yaml")
|
||||
|
||||
(tmp_dir / "dir").mkdir()
|
||||
(tmp_dir / "dir" / "file").write_text("dir/file")
|
||||
scm.ignore(tmp_dir / "dir")
|
||||
(tmp_dir / "file").write_text("file")
|
||||
scm.ignore(tmp_dir / "file")
|
||||
|
||||
results = dvc.experiments.run(
|
||||
stage.addressing, tmp_dir=tmp, copy_paths=["dir", "file"]
|
||||
)
|
||||
exp = first(results)
|
||||
fs = scm.get_fs(exp)
|
||||
assert not fs.exists("dir")
|
||||
assert not fs.exists("file")
|
||||
|
||||
|
||||
def test_copy_paths_errors(tmp_dir, scm, dvc, mocker):
|
||||
stage = dvc.stage.add(
|
||||
cmd="echo foo",
|
||||
name="foo",
|
||||
)
|
||||
scm.add_commit(["dvc.yaml"], message="add dvc.yaml")
|
||||
|
||||
with pytest.raises(DvcException, match="Unable to copy"):
|
||||
dvc.experiments.run(stage.addressing, tmp_dir=True, copy_paths=["foo"])
|
||||
|
||||
(tmp_dir / "foo").write_text("foo")
|
||||
mocker.patch("shutil.copy", side_effect=OSError)
|
||||
|
||||
with pytest.raises(DvcException, match="Unable to copy"):
|
||||
dvc.experiments.run(stage.addressing, tmp_dir=True, copy_paths=["foo"])
|
||||
|
||||
@@ -108,3 +108,25 @@ def test_queue_doesnt_remove_untracked_params_file(tmp_dir, dvc, scm):
|
||||
scm.commit("init")
|
||||
dvc.experiments.run(stage.addressing, params=["foo=2"], queue=True)
|
||||
assert (tmp_dir / "params.yaml").exists()
|
||||
|
||||
|
||||
def test_copy_paths_queue(tmp_dir, scm, dvc):
|
||||
stage = dvc.stage.add(
|
||||
cmd="cat file && ls dir",
|
||||
name="foo",
|
||||
)
|
||||
scm.add_commit(["dvc.yaml"], message="add dvc.yaml")
|
||||
|
||||
(tmp_dir / "dir").mkdir()
|
||||
(tmp_dir / "dir" / "file").write_text("dir/file")
|
||||
scm.ignore(tmp_dir / "dir")
|
||||
(tmp_dir / "file").write_text("file")
|
||||
scm.ignore(tmp_dir / "file")
|
||||
|
||||
dvc.experiments.run(stage.addressing, queue=True)
|
||||
results = dvc.experiments.run(run_all=True)
|
||||
|
||||
exp = first(results)
|
||||
fs = scm.get_fs(exp)
|
||||
assert not fs.exists("dir")
|
||||
assert not fs.exists("file")
|
||||
|
||||
@@ -116,10 +116,7 @@ def test_hydra_sweep(
|
||||
assert patched.call_count == len(expected)
|
||||
for e in expected:
|
||||
patched.assert_any_call(
|
||||
mocker.ANY,
|
||||
params=e,
|
||||
reset=True,
|
||||
targets=None,
|
||||
mocker.ANY, params=e, reset=True, targets=None, copy_paths=None
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -138,6 +138,7 @@ def test_experiments_run(dvc, scm, mocker):
|
||||
"checkpoint_resume": None,
|
||||
"reset": False,
|
||||
"machine": None,
|
||||
"copy_paths": [],
|
||||
}
|
||||
default_arguments.update(repro_arguments)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user