Files
dvc/dvc/tree/__init__.py
T
Arun MahapatraandRuslan Kuprieiev 6324bd8a69 dvc: include cache urls in info output. (#4848)
* dvc: include cache urls in info output.

Show cache urls for external and remote cache in the info output
to assist in diagnosis of issues.

Fixes #4574.

* Remove unnecessary constant check for generator expression.

* Add remotes and caches in version command for better diagnosis.

* Fix flaky unit test to be runtime independent by using regex search.

* Use Cache.by_scheme() for enumerating supported caches.

* Add get_cloud_schemes routine for retrieval of configured remote schemes.

Add tests for local remote and remote:// scheme for info.

* Cleanup unused code.

* info: refactor remote parsing

Co-authored-by: Ruslan Kuprieiev <[email protected]>
2020-11-19 05:59:33 +02:00

91 lines
2.4 KiB
Python

import posixpath
from urllib.parse import urlparse
from .azure import AzureTree
from .gdrive import GDriveTree
from .gs import GSTree
from .hdfs import HDFSTree
from .http import HTTPTree
from .https import HTTPSTree
from .local import LocalTree
from .oss import OSSTree
from .s3 import S3Tree
from .ssh import SSHTree
from .webdav import WebDAVTree
from .webdavs import WebDAVSTree
from .webhdfs import WebHDFSTree
TREES = [
AzureTree,
GDriveTree,
GSTree,
HDFSTree,
HTTPTree,
HTTPSTree,
S3Tree,
SSHTree,
OSSTree,
WebDAVTree,
WebDAVSTree,
WebHDFSTree
# NOTE: LocalTree is the default
]
def get_tree_cls(remote_conf):
for tree_cls in TREES:
if tree_cls.supported(remote_conf):
return tree_cls
return LocalTree
def get_tree_config(config, **kwargs):
name = kwargs.get("name")
if name:
remote_conf = config["remote"][name.lower()]
else:
remote_conf = kwargs
return _resolve_remote_refs(config, remote_conf)
def _resolve_remote_refs(config, remote_conf):
# Support for cross referenced remotes.
# This will merge the settings, shadowing base ref with remote_conf.
# For example, having:
#
# dvc remote add server ssh://localhost
# dvc remote modify server user root
# dvc remote modify server ask_password true
#
# dvc remote add images remote://server/tmp/pictures
# dvc remote modify images user alice
# dvc remote modify images ask_password false
# dvc remote modify images password asdf1234
#
# Results on a config dictionary like:
#
# {
# "url": "ssh://localhost/tmp/pictures",
# "user": "alice",
# "password": "asdf1234",
# "ask_password": False,
# }
parsed = urlparse(remote_conf["url"])
if parsed.scheme != "remote":
return remote_conf
base = get_tree_config(config, name=parsed.netloc)
url = posixpath.join(base["url"], parsed.path.lstrip("/"))
return {**base, **remote_conf, "url": url}
def get_cloud_tree(repo, **kwargs):
from dvc.config import SCHEMA, ConfigError, Invalid
remote_conf = get_tree_config(repo.config, **kwargs)
try:
remote_conf = SCHEMA["remote"][str](remote_conf)
except Invalid as exc:
raise ConfigError(str(exc)) from None
return get_tree_cls(remote_conf)(repo, remote_conf)