Skip to content

Commit

Permalink
fs: get_cloud_fs: accept config instead of repo
Browse files Browse the repository at this point in the history
Config is a more immutable thing and using `repo` is confusing and might be error
prone in the bigger picture.

Related to #9754
  • Loading branch information
efiop committed Jul 24, 2023
1 parent 7806afd commit 1b4fbfb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dvc/cachemgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _get_odb(
if not settings:
return None

cls, config, fs_path = get_cloud_fs(repo, **settings)
cls, config, fs_path = get_cloud_fs(repo.config, **settings)
fs = fs or cls(**config)
if prefix:
fs_path = fs.path.join(fs_path, *prefix)
Expand Down
2 changes: 1 addition & 1 deletion dvc/data_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_remote(
if name:
from dvc.fs import get_cloud_fs

cls, config, fs_path = get_cloud_fs(self.repo, name=name)
cls, config, fs_path = get_cloud_fs(self.repo.config, name=name)

if config.get("worktree"):
version_aware = config.get("version_aware")
Expand Down
9 changes: 2 additions & 7 deletions dvc/fs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,13 @@ def _resolve_remote_refs(config, remote_conf):
return remote_conf

base = get_fs_config(config, name=parsed.netloc)
cls, _, _ = _get_cloud_fs(config, **base)
cls, _, _ = get_cloud_fs(config, **base)
relpath = parsed.path.lstrip("/").replace("/", cls.sep)
url = cls.sep.join((base["url"], relpath))
return {**base, **remote_conf, "url": url}


def get_cloud_fs(repo, **kwargs):
repo_config = repo.config if repo else {}
return _get_cloud_fs(repo_config, **kwargs)


def _get_cloud_fs(repo_config, **kwargs):
def get_cloud_fs(repo_config, **kwargs):
core_config = repo_config.get("core", {})

remote_conf = get_fs_config(repo_config, **kwargs)
Expand Down
10 changes: 8 additions & 2 deletions dvc/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,11 @@ def __init__( # noqa: PLR0913
if fs_config is not None:
fs_kwargs.update(**fs_config)

fs_cls, fs_config, fs_path = get_cloud_fs(self.repo, url=path, **fs_kwargs)
fs_cls, fs_config, fs_path = get_cloud_fs(
self.repo.config if self.repo else {},
url=path,
**fs_kwargs,
)
self.fs = fs_cls(**fs_config)

if (
Expand Down Expand Up @@ -1017,7 +1021,9 @@ def transfer(
if odb is None:
odb = self.cache

cls, config, from_info = get_cloud_fs(self.repo, url=source)
cls, config, from_info = get_cloud_fs(
self.repo.config if self.repo else {}, url=source
)
from_fs = cls(**config)

# When running import-url --to-remote / add --to-remote/-o ... we
Expand Down

0 comments on commit 1b4fbfb

Please sign in to comment.