mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
@@ -4,6 +4,7 @@ from contextlib import ExitStack
|
||||
from tempfile import mkdtemp
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
|
||||
from configobj import ConfigObj
|
||||
from funcy import retry
|
||||
from shortuuid import uuid
|
||||
|
||||
@@ -134,22 +135,29 @@ class TempDirExecutor(BaseLocalExecutor):
|
||||
merge_rev = self.scm.get_ref(EXEC_MERGE)
|
||||
|
||||
self.scm.stash.apply(merge_rev)
|
||||
self._update_config(repo.config.read("local"))
|
||||
|
||||
def _config(self, cache_dir):
|
||||
def _update_config(self, update):
|
||||
local_config = os.path.join(
|
||||
self.root_dir,
|
||||
self.dvc_dir,
|
||||
"config.local",
|
||||
)
|
||||
logger.debug("Writing experiments local config '%s'", local_config)
|
||||
with open(local_config, "w", encoding="utf-8") as fobj:
|
||||
fobj.write(f"[cache]\n dir = {cache_dir}")
|
||||
if os.path.exists(local_config):
|
||||
conf_obj = ConfigObj(local_config)
|
||||
conf_obj.merge(update)
|
||||
else:
|
||||
conf_obj = ConfigObj(update)
|
||||
if conf_obj:
|
||||
with open(local_config, "wb") as fobj:
|
||||
conf_obj.write(fobj)
|
||||
|
||||
def init_cache(
|
||||
self, repo: "Repo", rev: str, run_cache: bool = True # noqa: ARG002
|
||||
):
|
||||
"""Initialize DVC cache."""
|
||||
self._config(repo.cache.repo.path)
|
||||
self._update_config({"cache": {"dir": repo.cache.repo.path}})
|
||||
|
||||
def cleanup(self, infofile: Optional[str] = None):
|
||||
super().cleanup(infofile)
|
||||
|
||||
@@ -5,6 +5,7 @@ import stat
|
||||
from textwrap import dedent
|
||||
|
||||
import pytest
|
||||
from configobj import ConfigObj
|
||||
from funcy import first
|
||||
|
||||
from dvc.dvcfile import PROJECT_FILE
|
||||
@@ -664,3 +665,21 @@ def test_experiment_no_commit(tmp_dir):
|
||||
repo.experiments.ls()
|
||||
finally:
|
||||
repo.close()
|
||||
|
||||
|
||||
def test_local_config_is_propagated_to_tmp(tmp_dir, scm, dvc):
|
||||
with dvc.config.edit("local") as conf:
|
||||
conf["cache"]["type"] = "hardlink"
|
||||
|
||||
stage = dvc.stage.add(
|
||||
cmd="cat .dvc/config.local > file", name="foo", outs_no_cache=["file"]
|
||||
)
|
||||
scm.add_commit(["dvc.yaml"], message="add dvc.yaml")
|
||||
|
||||
results = dvc.experiments.run(stage.addressing, tmp_dir=True)
|
||||
exp = first(results)
|
||||
fs = scm.get_fs(exp)
|
||||
|
||||
with fs.open("file") as fobj:
|
||||
conf_obj = ConfigObj(fobj)
|
||||
assert conf_obj["cache"]["type"] == "hardlink"
|
||||
|
||||
Reference in New Issue
Block a user