Skip to content

Commit

Permalink
exp run: Propagate .dvc/config.local in TempDirExecutor.
Browse files Browse the repository at this point in the history
Closes #7254
  • Loading branch information
daavoo committed Mar 31, 2023
1 parent 894f530 commit 1d8b2e5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
16 changes: 12 additions & 4 deletions dvc/repo/experiments/executor/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tempfile import mkdtemp
from typing import TYPE_CHECKING, Optional, Union

from configobj import ConfigObj
from funcy import retry
from shortuuid import uuid

Expand Down Expand Up @@ -134,22 +135,29 @@ def init_git(
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)
Expand Down
19 changes: 19 additions & 0 deletions tests/func/experiments/test_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from textwrap import dedent

import pytest
from configobj import ConfigObj
from funcy import first

from dvc.dvcfile import PROJECT_FILE
Expand Down Expand Up @@ -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"

0 comments on commit 1d8b2e5

Please sign in to comment.