mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
Merge pull request #3225 from pared/2647_no_cache_external_dir
remote: verify cache exists on dir checksum
This commit is contained in:
@@ -311,3 +311,18 @@ class PathMissingError(DvcException):
|
||||
" neither as an output nor a git-handled file."
|
||||
)
|
||||
super().__init__(msg.format(path, repo))
|
||||
|
||||
|
||||
class RemoteCacheRequiredError(DvcException):
|
||||
def __init__(self, path_info):
|
||||
super().__init__(
|
||||
(
|
||||
"Current operation was unsuccessful because '{}' requires "
|
||||
"existing cache on '{}' remote. See {} for information on how "
|
||||
"to set up remote cache."
|
||||
).format(
|
||||
path_info,
|
||||
path_info.scheme,
|
||||
format_link("https://man.dvc.org/config#cache"),
|
||||
)
|
||||
)
|
||||
|
||||
+3
-8
@@ -6,7 +6,7 @@ from voluptuous import Any
|
||||
|
||||
import dvc.prompt as prompt
|
||||
from dvc.cache import NamedCache
|
||||
from dvc.exceptions import CollectCacheError
|
||||
from dvc.exceptions import CollectCacheError, RemoteCacheRequiredError
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.remote.base import RemoteBASE
|
||||
|
||||
@@ -98,14 +98,9 @@ class OutputBase(object):
|
||||
self.persist = persist
|
||||
self.tags = None if self.IS_DEPENDENCY else (tags or {})
|
||||
|
||||
if self.use_cache and self.cache is None:
|
||||
raise DvcException(
|
||||
"no cache location setup for '{}' outputs.".format(
|
||||
self.REMOTE.scheme
|
||||
)
|
||||
)
|
||||
|
||||
self.path_info = self._parse_path(remote, path)
|
||||
if self.use_cache and self.cache is None:
|
||||
raise RemoteCacheRequiredError(self.path_info)
|
||||
|
||||
def _parse_path(self, remote, path):
|
||||
if remote:
|
||||
|
||||
@@ -18,6 +18,7 @@ from dvc.exceptions import (
|
||||
DvcException,
|
||||
ConfirmRemoveError,
|
||||
DvcIgnoreInCollectedDirError,
|
||||
RemoteCacheRequiredError,
|
||||
)
|
||||
from dvc.ignore import DvcIgnore
|
||||
from dvc.path_info import PathInfo, URLInfo
|
||||
@@ -233,6 +234,9 @@ class RemoteBASE(object):
|
||||
return sorted(result, key=itemgetter(self.PARAM_RELPATH))
|
||||
|
||||
def get_dir_checksum(self, path_info):
|
||||
if not self.cache:
|
||||
raise RemoteCacheRequiredError(path_info)
|
||||
|
||||
dir_info = self._collect_dir(path_info)
|
||||
checksum, tmp_info = self._get_dir_info_checksum(dir_info)
|
||||
new_info = self.cache.checksum_to_path_info(checksum)
|
||||
|
||||
@@ -11,7 +11,7 @@ from dvc.exceptions import DownloadError, UploadError
|
||||
from dvc.main import main
|
||||
from dvc.path_info import PathInfo
|
||||
from dvc.remote import RemoteLOCAL, RemoteConfig
|
||||
from dvc.remote.base import RemoteBASE
|
||||
from dvc.remote.base import RemoteBASE, RemoteCacheRequiredError
|
||||
from dvc.compat import fspath
|
||||
from tests.basic_env import TestDvc
|
||||
from tests.remotes import Local
|
||||
@@ -257,3 +257,14 @@ def test_modify_missing_remote(dvc):
|
||||
|
||||
with pytest.raises(ConfigError, match=r"Unable to find remote section"):
|
||||
remote_config.modify("myremote", "gdrive_client_id", "xxx")
|
||||
|
||||
|
||||
def test_external_dir_resource_on_no_cache(tmp_dir, dvc, tmp_path_factory):
|
||||
# https://github.com/iterative/dvc/issues/2647, is some situations
|
||||
# (external dir dependency) cache is required to calculate dir md5
|
||||
external_dir = tmp_path_factory.mktemp("external_dir")
|
||||
(external_dir / "file").write_text("content")
|
||||
|
||||
dvc.cache.local = None
|
||||
with pytest.raises(RemoteCacheRequiredError):
|
||||
dvc.run(deps=[fspath(external_dir)])
|
||||
|
||||
Reference in New Issue
Block a user