exp: use explicit scm.add(force=True) when necessary

- add test for dir dep containing gitignored files
This commit is contained in:
Peter Rowlands
2023-04-10 13:17:47 +03:00
committed by Ruslan Kuprieiev
parent 61d0893d7c
commit ce269ffa58
3 changed files with 29 additions and 2 deletions
+1 -1
View File
@@ -681,7 +681,7 @@ class BaseExecutor(ABC):
args, kwargs = cls.unpack_repro_args(args_path)
remove(args_path)
# explicitly git rm/unstage the args file
dvc.scm.add([args_path])
dvc.scm.add([args_path], force=True)
else:
args = []
kwargs = {}
+1 -1
View File
@@ -520,7 +520,7 @@ class BaseStashQueue(ABC):
else:
extra = None
BaseExecutor.pack_repro_args(self.args_file, *args, extra=extra, **kwargs)
self.scm.add(self.args_file)
self.scm.add(self.args_file, force=True)
@staticmethod
def _format_new_params_msg(new_params, config_path):
@@ -335,6 +335,7 @@ def test_packed_args_exists(tmp_dir, scm, dvc, exp_stage, caplog):
with caplog.at_level(logging.WARNING):
dvc.experiments.run(exp_stage.addressing)
assert "Temporary DVC file" in caplog.text
assert not (tmp_dir / ".dvc" / "tmp" / BaseExecutor.PACKED_ARGS_FILE).exists()
def test_list(tmp_dir, scm, dvc, exp_stage):
@@ -744,3 +745,29 @@ def test_copy_paths_errors(tmp_dir, scm, dvc, mocker):
with pytest.raises(DvcException, match="Unable to copy"):
dvc.experiments.run(stage.addressing, tmp_dir=True, copy_paths=["foo"])
def test_mixed_git_dvc_out(tmp_dir, scm, dvc, exp_stage):
(tmp_dir / "dir").mkdir()
dir_metrics = os.path.join("dir", "metrics.yaml")
dvc.stage.add(
cmd=f"python copy.py params.yaml {dir_metrics}",
metrics=[dir_metrics],
params=["foo"],
name="copy-file",
deps=["copy.py"],
force=True,
)
dvc.stage.add(
cmd=f"python copy.py {dir_metrics} metrics.yaml",
metrics_no_cache=["metrics.yaml"],
name="copy-dir-file",
deps=["dir"],
)
scm.add(["dvc.yaml", "dvc.lock"])
scm.commit("add dir stage")
exp = first(dvc.experiments.run())
assert (tmp_dir / "dir" / "metrics.yaml").exists()
git_fs = scm.get_fs(exp)
assert not git_fs.exists("dir/metrics.yaml")