Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions dvc/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ def _make_remote_property(name):
"""

def getter(self):
from dvc.remote import Cache as CloudCache
from dvc.remote import get_cloud_tree
from dvc.remote.base import CloudCache

remote = self.config.get(name)
if not remote:
return None

return CloudCache(self.repo, name=remote)
tree = get_cloud_tree(self.repo, name=remote)
return CloudCache(tree)

getter.__name__ = name
return cached_property(getter)
Expand All @@ -50,7 +52,8 @@ class Cache:
CACHE_DIR = "cache"

def __init__(self, repo):
from dvc.remote import Cache as CloudCache
from dvc.remote import get_cloud_tree
from dvc.remote.local import LocalCache

self.repo = repo
self.config = config = repo.config["cache"]
Expand All @@ -62,7 +65,8 @@ def __init__(self, repo):
else:
settings = {**config, "url": config["dir"]}

self.local = CloudCache(repo, **settings)
tree = get_cloud_tree(repo, **settings)
self.local = LocalCache(tree)

s3 = _make_remote_property("s3")
gs = _make_remote_property("gs")
Expand Down
8 changes: 4 additions & 4 deletions dvc/command/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ def get_linktype_support_info(repo):

@staticmethod
def get_supported_remotes():
from dvc.remote import REMOTES
from dvc.remote import TREES

supported_remotes = []
for remote in REMOTES:
if not remote.get_missing_deps():
supported_remotes.append(remote.scheme)
for tree_cls in TREES:
if not tree_cls.get_missing_deps():
supported_remotes.append(tree_cls.scheme)

return ", ".join(supported_remotes)

Expand Down
6 changes: 3 additions & 3 deletions dvc/data_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging

from dvc.config import NoRemoteError
from dvc.remote import Remote
from dvc.remote import get_remote

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -45,7 +45,7 @@ def get_remote(self, name=None, command="<command>"):
raise NoRemoteError(error_msg)

def _init_remote(self, name):
return Remote(self.repo, name=name)
return get_remote(self.repo, name=name)

def push(
self, cache, jobs=None, remote=None, show_checksums=False,
Expand Down Expand Up @@ -85,7 +85,7 @@ def pull(
cache, jobs=jobs, remote=remote, show_checksums=show_checksums
)

if not remote.verify:
if not remote.tree.verify:
self._save_pulled_checksums(cache)

return downloaded_items_num
Expand Down
4 changes: 2 additions & 2 deletions dvc/dependency/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dvc.dependency.s3 import S3Dependency
from dvc.dependency.ssh import SSHDependency
from dvc.output.base import BaseOutput
from dvc.remote import Remote
from dvc.remote import get_remote
from dvc.scheme import Schemes

from .repo import RepoDependency
Expand Down Expand Up @@ -54,7 +54,7 @@
def _get(stage, p, info):
parsed = urlparse(p) if p else None
if parsed and parsed.scheme == "remote":
remote = Remote(stage.repo, name=parsed.netloc)
remote = get_remote(stage.repo, name=parsed.netloc)
return DEP_MAP[remote.scheme](stage, p, info, remote=remote)

if info and info.get(RepoDependency.PARAM_REPO):
Expand Down
4 changes: 2 additions & 2 deletions dvc/dependency/azure.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dvc.dependency.base import BaseDependency
from dvc.output.base import BaseOutput
from dvc.remote.azure import AzureRemote
from dvc.remote.azure import AzureRemoteTree


class AzureDependency(BaseDependency, BaseOutput):
REMOTE = AzureRemote
TREE_CLS = AzureRemoteTree
4 changes: 2 additions & 2 deletions dvc/dependency/http.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dvc.dependency.base import BaseDependency
from dvc.output.base import BaseOutput
from dvc.remote.http import HTTPRemote
from dvc.remote.http import HTTPRemoteTree


class HTTPDependency(BaseDependency, BaseOutput):
REMOTE = HTTPRemote
TREE_CLS = HTTPRemoteTree
4 changes: 2 additions & 2 deletions dvc/dependency/https.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dvc.remote.https import HTTPSRemote
from dvc.remote.https import HTTPSRemoteTree

from .http import HTTPDependency


class HTTPSDependency(HTTPDependency):
REMOTE = HTTPSRemote
TREE_CLS = HTTPSRemoteTree
16 changes: 8 additions & 8 deletions dvc/output/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from dvc.output.local import LocalOutput
from dvc.output.s3 import S3Output
from dvc.output.ssh import SSHOutput
from dvc.remote import Remote
from dvc.remote.hdfs import HDFSRemote
from dvc.remote.local import LocalRemote
from dvc.remote.s3 import S3Remote
from dvc.remote import get_remote
from dvc.remote.hdfs import HDFSRemoteTree
from dvc.remote.local import LocalRemoteTree
from dvc.remote.s3 import S3RemoteTree
from dvc.scheme import Schemes

OUTS = [
Expand Down Expand Up @@ -47,9 +47,9 @@
# so when a few types of outputs share the same name, we only need
# specify it once.
CHECKSUMS_SCHEMA = {
LocalRemote.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
S3Remote.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
HDFSRemote.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
LocalRemoteTree.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
S3RemoteTree.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
HDFSRemoteTree.PARAM_CHECKSUM: CHECKSUM_SCHEMA,
}

SCHEMA = CHECKSUMS_SCHEMA.copy()
Expand All @@ -66,7 +66,7 @@ def _get(
parsed = urlparse(p)

if parsed.scheme == "remote":
remote = Remote(stage.repo, name=parsed.netloc)
remote = get_remote(stage.repo, name=parsed.netloc)
return OUTS_MAP[remote.scheme](
stage,
p,
Expand Down
29 changes: 17 additions & 12 deletions dvc/output/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
DvcException,
RemoteCacheRequiredError,
)
from dvc.remote.base import BaseRemote
from dvc.remote.base import BaseRemoteTree, Remote

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -47,7 +47,8 @@ def __init__(self, path):
class BaseOutput:
IS_DEPENDENCY = False

REMOTE = BaseRemote
REMOTE_CLS = Remote
TREE_CLS = BaseRemoteTree

PARAM_PATH = "path"
PARAM_CACHE = "cache"
Expand Down Expand Up @@ -105,7 +106,11 @@ def __init__(
self.repo = stage.repo if stage else None
self.def_path = path
self.info = info
self.remote = remote or self.REMOTE(self.repo, {})
if remote:
self.remote = remote
else:
tree = self.TREE_CLS(self.repo, {})
self.remote = self.REMOTE_CLS(tree)
self.use_cache = False if self.IS_DEPENDENCY else cache
self.metric = False if self.IS_DEPENDENCY else metric
self.plot = False if self.IS_DEPENDENCY else plot
Expand All @@ -119,7 +124,7 @@ def _parse_path(self, remote, path):
if remote:
parsed = urlparse(path)
return remote.path_info / parsed.path.lstrip("/")
return self.REMOTE.TREE_CLS.PATH_CLS(path)
return self.TREE_CLS.PATH_CLS(path)

def __repr__(self):
return "{class_name}: '{def_path}'".format(
Expand All @@ -131,7 +136,7 @@ def __str__(self):

@property
def scheme(self):
return self.REMOTE.scheme
return self.TREE_CLS.scheme

@property
def is_in_repo(self):
Expand All @@ -154,23 +159,23 @@ def dir_cache(self):

@classmethod
def supported(cls, url):
return cls.REMOTE.supported(url)
return cls.TREE_CLS.supported(url)

@property
def cache_path(self):
return self.cache.checksum_to_path_info(self.checksum).url

@property
def checksum_type(self):
return self.remote.PARAM_CHECKSUM
return self.remote.tree.PARAM_CHECKSUM

@property
def checksum(self):
return self.info.get(self.remote.PARAM_CHECKSUM)
return self.info.get(self.remote.tree.PARAM_CHECKSUM)

@checksum.setter
def checksum(self, checksum):
self.info[self.remote.PARAM_CHECKSUM] = checksum
self.info[self.remote.tree.PARAM_CHECKSUM] = checksum

def get_checksum(self):
return self.remote.get_checksum(self.path_info)
Expand Down Expand Up @@ -357,7 +362,7 @@ def get_files_number(self, filter_info=None):

def unprotect(self):
if self.exists:
self.remote.unprotect(self.path_info)
self.remote.tree.unprotect(self.path_info)

def get_dir_cache(self, **kwargs):
if not self.is_dir_checksum:
Expand Down Expand Up @@ -417,8 +422,8 @@ def collect_used_dir_cache(
filter_path = str(filter_info) if filter_info else None
is_win = os.name == "nt"
for entry in self.dir_cache:
checksum = entry[self.remote.PARAM_CHECKSUM]
entry_relpath = entry[self.remote.PARAM_RELPATH]
checksum = entry[self.remote.tree.PARAM_CHECKSUM]
entry_relpath = entry[self.remote.tree.PARAM_RELPATH]
if is_win:
entry_relpath = entry_relpath.replace("/", os.sep)
entry_path = os.path.join(path, entry_relpath)
Expand Down
4 changes: 2 additions & 2 deletions dvc/output/gs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dvc.output.s3 import S3Output
from dvc.remote.gs import GSRemote
from dvc.remote.gs import GSRemoteTree


class GSOutput(S3Output):
REMOTE = GSRemote
TREE_CLS = GSRemoteTree
4 changes: 2 additions & 2 deletions dvc/output/hdfs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dvc.output.base import BaseOutput
from dvc.remote.hdfs import HDFSRemote
from dvc.remote.hdfs import HDFSRemoteTree


class HDFSOutput(BaseOutput):
REMOTE = HDFSRemote
TREE_CLS = HDFSRemoteTree
9 changes: 5 additions & 4 deletions dvc/output/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
from dvc.exceptions import DvcException
from dvc.istextfile import istextfile
from dvc.output.base import BaseOutput
from dvc.remote.local import LocalRemote
from dvc.remote.local import LocalRemote, LocalRemoteTree
from dvc.utils import relpath
from dvc.utils.fs import path_isin

logger = logging.getLogger(__name__)


class LocalOutput(BaseOutput):
REMOTE = LocalRemote
REMOTE_CLS = LocalRemote
TREE_CLS = LocalRemoteTree
sep = os.sep

def __init__(self, stage, path, *args, **kwargs):
Expand All @@ -33,12 +34,12 @@ def _parse_path(self, remote, path):
#
# FIXME: if we have Windows path containing / or posix one with \
# then we have #2059 bug and can't really handle that.
p = self.REMOTE.TREE_CLS.PATH_CLS(path)
p = self.TREE_CLS.PATH_CLS(path)
if not p.is_absolute():
p = self.stage.wdir / p

abs_p = os.path.abspath(os.path.normpath(p))
return self.REMOTE.TREE_CLS.PATH_CLS(abs_p)
return self.TREE_CLS.PATH_CLS(abs_p)

def __str__(self):
if not self.is_in_repo:
Expand Down
4 changes: 2 additions & 2 deletions dvc/output/s3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dvc.output.base import BaseOutput
from dvc.remote.s3 import S3Remote
from dvc.remote.s3 import S3RemoteTree


class S3Output(BaseOutput):
REMOTE = S3Remote
TREE_CLS = S3RemoteTree
5 changes: 3 additions & 2 deletions dvc/output/ssh.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dvc.output.base import BaseOutput
from dvc.remote.ssh import SSHRemote
from dvc.remote.ssh import SSHRemote, SSHRemoteTree


class SSHOutput(BaseOutput):
REMOTE = SSHRemote
REMOTE_CLS = SSHRemote
TREE_CLS = SSHRemoteTree
Loading