mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 15:28:28 +01:00
* dvc: refactor config
Advantages:
- read like a dict
- modify as a dict for testing or manipulation purposes
- wrap modifications into context manager to save them:
with config.edit("local") as conf:
conf["core"]["remote"] = "new-default"
Design decisions:
- dropped string constants
- remote sections are parsed into a simple subdict upon load
- remote config schema is now defined by url scheme
- relative paths are handled transparently upon load/save
- user config and remote manipulations are moved to commands
- same dev manipulations are done by simply modifying a config dict
* test: do not set cache.type for remotes that doesn't support it
* dvc: fix windows absolute paths validation in config
* test: fix windows separate drive test
* dvc: stylistic fixes in config
76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
import posixpath
|
|
from urllib.parse import urlparse
|
|
|
|
from dvc.remote.azure import RemoteAZURE
|
|
from dvc.remote.gdrive import RemoteGDrive
|
|
from dvc.remote.gs import RemoteGS
|
|
from dvc.remote.hdfs import RemoteHDFS
|
|
from dvc.remote.http import RemoteHTTP
|
|
from dvc.remote.https import RemoteHTTPS
|
|
from dvc.remote.local import RemoteLOCAL
|
|
from dvc.remote.oss import RemoteOSS
|
|
from dvc.remote.s3 import RemoteS3
|
|
from dvc.remote.ssh import RemoteSSH
|
|
|
|
|
|
REMOTES = [
|
|
RemoteAZURE,
|
|
RemoteGDrive,
|
|
RemoteGS,
|
|
RemoteHDFS,
|
|
RemoteHTTP,
|
|
RemoteHTTPS,
|
|
RemoteS3,
|
|
RemoteSSH,
|
|
RemoteOSS,
|
|
# NOTE: RemoteLOCAL is the default
|
|
]
|
|
|
|
|
|
def _get(remote_conf):
|
|
for remote in REMOTES:
|
|
if remote.supported(remote_conf):
|
|
return remote
|
|
return RemoteLOCAL
|
|
|
|
|
|
def Remote(repo, **kwargs):
|
|
name = kwargs.get("name")
|
|
if name:
|
|
remote_conf = repo.config["remote"][name.lower()]
|
|
else:
|
|
remote_conf = kwargs
|
|
remote_conf = _resolve_remote_refs(repo.config, remote_conf)
|
|
return _get(remote_conf)(repo, 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 = config["remote"][parsed.netloc]
|
|
url = posixpath.join(base["url"], parsed.path.lstrip("/"))
|
|
return {**base, **remote_conf, "url": url}
|