From ad7d39da202fcc9c3a216b2fe8d6c66ef3013648 Mon Sep 17 00:00:00 2001 From: Ronan Lamy Date: Thu, 25 Aug 2022 13:16:56 +0100 Subject: [PATCH] fs: chop up ._get_fs_pair() --- dvc/fs/dvc.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/dvc/fs/dvc.py b/dvc/fs/dvc.py index 097b3368d..9eb80a81d 100644 --- a/dvc/fs/dvc.py +++ b/dvc/fs/dvc.py @@ -79,6 +79,11 @@ def _merge_info(repo, fs_info, dvc_info): return ret +def _get_dvc_path(dvc_fs, dvc_parts): + if dvc_fs: + return dvc_fs.path.join(*dvc_parts) if dvc_parts else "" + + class _DvcFileSystem(AbstractFileSystem): # pylint:disable=abstract-method """DVC + git-tracked files fs. @@ -292,7 +297,22 @@ class _DvcFileSystem(AbstractFileSystem): # pylint:disable=abstract-method Returns a pair of fss based on repo the path falls in, using prefix. """ key = self._get_key_from_relative(path) + repo, fs, fs_path, dvc_fs, dvc_parts = self._get_fs_pair_2(key) + dvc_path = _get_dvc_path(dvc_fs, dvc_parts) + return repo, fs, fs_path, dvc_fs, dvc_path + def _get_fs_pair_2( + self, key: Key + ) -> Tuple[ + Optional["Repo"], + Optional[FileSystem], + Optional[str], + Optional[DataFileSystem], + Key, + ]: + """ + Returns a pair of fss based on repo the path falls in, using prefix. + """ fs_path = self._from_key(key) repo = self._get_repo(key) fs = repo.fs @@ -305,12 +325,7 @@ class _DvcFileSystem(AbstractFileSystem): # pylint:disable=abstract-method key = self._get_key(repo.root_dir) dvc_fs = self._datafss.get(key) - if dvc_fs: - dvc_path = dvc_fs.path.join(*dvc_parts) if dvc_parts else "" - else: - dvc_path = None - - return repo, fs, fs_path, dvc_fs, dvc_path + return repo, fs, fs_path, dvc_fs, dvc_parts def open( self, path, mode="r", encoding="utf-8", **kwargs