mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
repo: brancher: reset parsed fields
Related #9754 and fixes `dvc fetch`.
This commit is contained in:
@@ -146,7 +146,6 @@ class Repo:
|
||||
scm: Optional[Union["Git", "NoSCM"]] = None,
|
||||
):
|
||||
from dvc.cachemgr import CacheManager
|
||||
from dvc.config import Config
|
||||
from dvc.data_cloud import DataCloud
|
||||
from dvc.fs import GitFileSystem, LocalFileSystem, localfs
|
||||
from dvc.lock import LockNoop, make_lock
|
||||
@@ -163,6 +162,7 @@ class Repo:
|
||||
self._fs_conf = {"repo_factory": repo_factory}
|
||||
self._fs = fs or localfs
|
||||
self._scm = scm
|
||||
self._config = config
|
||||
self._data_index = None
|
||||
|
||||
if rev and not fs:
|
||||
@@ -182,7 +182,6 @@ class Repo:
|
||||
scm=scm,
|
||||
)
|
||||
|
||||
self.config: Config = Config(self.dvc_dir, fs=self.fs, config=config)
|
||||
self._uninitialized = uninitialized
|
||||
|
||||
# used by DVCFileSystem to determine if it should traverse subrepos
|
||||
@@ -234,6 +233,12 @@ class Repo:
|
||||
def __str__(self):
|
||||
return self.url or self.root_dir
|
||||
|
||||
@cached_property
|
||||
def config(self):
|
||||
from dvc.config import Config
|
||||
|
||||
return Config(self.dvc_dir, fs=self.fs, config=self._config)
|
||||
|
||||
@cached_property
|
||||
def local_dvc_dir(self):
|
||||
from dvc.fs import GitFileSystem, LocalFileSystem
|
||||
@@ -629,6 +634,7 @@ class Repo:
|
||||
self.__dict__.pop("dvcignore", None)
|
||||
self.__dict__.pop("dvcfs", None)
|
||||
self.__dict__.pop("datafs", None)
|
||||
self.__dict__.pop("config", None)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
@@ -67,6 +67,7 @@ def brancher( # noqa: E302
|
||||
|
||||
saved_fs = self.fs
|
||||
saved_root = self.root_dir
|
||||
saved_dvc_dir = self.dvc_dir
|
||||
|
||||
scm = self.scm
|
||||
|
||||
@@ -101,6 +102,8 @@ def brancher( # noqa: E302
|
||||
finally:
|
||||
self.fs = saved_fs
|
||||
self.root_dir = saved_root
|
||||
self.dvc_dir = saved_dvc_dir
|
||||
self._reset() # pylint: disable=protected-access
|
||||
|
||||
|
||||
def _switch_fs(
|
||||
@@ -125,6 +128,8 @@ def _switch_fs(
|
||||
|
||||
repo.fs = fs
|
||||
repo.root_dir = root_dir
|
||||
repo.dvc_dir = fs.path.join(root_dir, repo.DVC_DIR)
|
||||
repo._reset() # pylint: disable=protected-access
|
||||
|
||||
if cwd_parts:
|
||||
cwd = repo.fs.path.join("/", *cwd_parts)
|
||||
@@ -149,9 +154,12 @@ def switch(repo: "Repo", rev: str) -> Iterator[str]:
|
||||
|
||||
saved_fs = repo.fs
|
||||
saved_root = repo.root_dir
|
||||
saved_dvc_dir = repo.dvc_dir
|
||||
try:
|
||||
_switch_fs(repo, rev, repo_root_parts, cwd_parts)
|
||||
yield rev
|
||||
finally:
|
||||
repo.fs = saved_fs
|
||||
repo.root_dir = saved_root
|
||||
repo.dvc_dir = saved_dvc_dir
|
||||
repo._reset() # pylint: disable=protected-access
|
||||
|
||||
@@ -203,7 +203,8 @@ def test_verify_hashes(tmp_dir, scm, dvc, mocker, tmp_path_factory, local_remote
|
||||
# Removing cache will invalidate existing state entries
|
||||
dvc.cache.local.clear()
|
||||
|
||||
dvc.config["remote"]["upstream"]["verify"] = True
|
||||
with dvc.config.edit() as conf:
|
||||
conf["remote"]["upstream"]["verify"] = True
|
||||
|
||||
dvc.pull()
|
||||
assert hash_spy.call_count == 10
|
||||
|
||||
+11
-31
@@ -196,11 +196,7 @@ def test_gc_cloud_positive(tmp_dir, dvc, tmp_path_factory, local_remote):
|
||||
assert main(["gc", "-vf", flag]) == 0
|
||||
|
||||
|
||||
def test_gc_cloud_remove_order(tmp_dir, scm, dvc, tmp_path_factory, mocker):
|
||||
storage = os.fspath(tmp_path_factory.mktemp("test_remote_base"))
|
||||
dvc.config["remote"]["local_remote"] = {"url": storage}
|
||||
dvc.config["core"]["remote"] = "local_remote"
|
||||
|
||||
def test_gc_cloud_remove_order(tmp_dir, scm, dvc, mocker, local_remote):
|
||||
(standalone, dir1, dir2) = tmp_dir.dvc_gen(
|
||||
{
|
||||
"file1": "standalone",
|
||||
@@ -321,11 +317,7 @@ def test_date(tmp_dir, scm, dvc):
|
||||
) # "modified, again"
|
||||
|
||||
|
||||
def test_gc_not_in_remote(tmp_dir, scm, dvc, tmp_path_factory, mocker):
|
||||
storage = os.fspath(tmp_path_factory.mktemp("test_remote_base"))
|
||||
dvc.config["remote"]["local_remote"] = {"url": storage}
|
||||
dvc.config["core"]["remote"] = "local_remote"
|
||||
|
||||
def test_gc_not_in_remote(tmp_dir, scm, dvc, mocker, local_remote):
|
||||
(standalone, dir1, dir2) = tmp_dir.dvc_gen(
|
||||
{
|
||||
"file1": "standalone",
|
||||
@@ -358,12 +350,9 @@ def test_gc_not_in_remote(tmp_dir, scm, dvc, tmp_path_factory, mocker):
|
||||
)
|
||||
|
||||
|
||||
def test_gc_not_in_remote_remote_arg(tmp_dir, scm, dvc, tmp_path_factory, mocker):
|
||||
storage = os.fspath(tmp_path_factory.mktemp("test_remote_base"))
|
||||
dvc.config["remote"]["local_remote"] = {"url": storage}
|
||||
dvc.config["core"]["remote"] = "local_remote"
|
||||
other_storage = os.fspath(tmp_path_factory.mktemp("test_remote_other"))
|
||||
dvc.config["remote"]["other_remote"] = {"url": other_storage}
|
||||
def test_gc_not_in_remote_remote_arg(tmp_dir, scm, dvc, mocker, make_remote):
|
||||
make_remote("local_remote", typ="local")
|
||||
make_remote("other_remote", typ="local", default=False)
|
||||
|
||||
tmp_dir.dvc_gen(
|
||||
{
|
||||
@@ -385,15 +374,9 @@ def test_gc_not_in_remote_remote_arg(tmp_dir, scm, dvc, tmp_path_factory, mocker
|
||||
assert len(mocked_remove.mock_calls) == 3
|
||||
|
||||
|
||||
def test_gc_not_in_remote_with_remote_field(
|
||||
tmp_dir, scm, dvc, tmp_path_factory, mocker
|
||||
):
|
||||
storage = os.fspath(tmp_path_factory.mktemp("test_remote_base"))
|
||||
dvc.config["remote"]["local_remote"] = {"url": storage}
|
||||
dvc.config["core"]["remote"] = "local_remote"
|
||||
|
||||
other_storage = os.fspath(tmp_path_factory.mktemp("test_remote_other"))
|
||||
dvc.config["remote"]["other_remote"] = {"url": other_storage}
|
||||
def test_gc_not_in_remote_with_remote_field(tmp_dir, scm, dvc, mocker, make_remote):
|
||||
make_remote("local_remote", typ="local")
|
||||
make_remote("other_remote", typ="local", default=False)
|
||||
|
||||
text = textwrap.dedent(
|
||||
"""\
|
||||
@@ -420,12 +403,9 @@ def test_gc_not_in_remote_cloud(tmp_dir, scm, dvc):
|
||||
dvc.gc(workspace=True, not_in_remote=True, cloud=True)
|
||||
|
||||
|
||||
def test_gc_cloud_remote_field(tmp_dir, scm, dvc, tmp_path_factory, mocker):
|
||||
storage = os.fspath(tmp_path_factory.mktemp("test_remote_base"))
|
||||
dvc.config["remote"]["local_remote"] = {"url": storage}
|
||||
dvc.config["core"]["remote"] = "local_remote"
|
||||
other_storage = os.fspath(tmp_path_factory.mktemp("test_remote_other"))
|
||||
dvc.config["remote"]["other_remote"] = {"url": other_storage}
|
||||
def test_gc_cloud_remote_field(tmp_dir, scm, dvc, mocker, make_remote):
|
||||
make_remote("local_remote", typ="local")
|
||||
make_remote("other_remote", typ="local", default=False)
|
||||
|
||||
text = textwrap.dedent(
|
||||
"""\
|
||||
|
||||
Reference in New Issue
Block a user