fs: make constructor closer to fsspec (#5911)

* fs: don't use repo for jobs/hash_jobs

* fs: local: exists: use fsspec's LocalFileSystem

* fs: make constructor comply with fsspec
This commit is contained in:
Ruslan Kuprieiev
2021-05-12 22:03:09 +03:00
committed by GitHub
parent 0ca08d2fea
commit 89b40afee7
62 changed files with 321 additions and 276 deletions
+7 -7
View File
@@ -3,22 +3,22 @@ from collections import defaultdict
from dvc.scheme import Schemes
def get_odb(fs):
def get_odb(fs, **config):
from .base import ObjectDB
from .gdrive import GDriveObjectDB
from .local import LocalObjectDB
from .ssh import SSHObjectDB
if fs.scheme == Schemes.LOCAL:
return LocalObjectDB(fs)
return LocalObjectDB(fs, **config)
if fs.scheme == Schemes.SSH:
return SSHObjectDB(fs)
return SSHObjectDB(fs, **config)
if fs.scheme == Schemes.GDRIVE:
return GDriveObjectDB(fs)
return GDriveObjectDB(fs, **config)
return ObjectDB(fs)
return ObjectDB(fs, **config)
def _get_odb(repo, settings):
@@ -27,8 +27,8 @@ def _get_odb(repo, settings):
if not settings:
return None
fs = get_cloud_fs(repo, **settings)
return get_odb(fs)
cls, config = get_cloud_fs(repo, **settings)
return get_odb(cls(**config), state=repo.state, **config)
class ODBManager:
+8 -8
View File
@@ -18,15 +18,15 @@ class ObjectDB:
DEFAULT_CACHE_TYPES = ["copy"]
CACHE_MODE: Optional[int] = None
def __init__(self, fs):
self.fs = fs
self.repo = fs.repo
def __init__(self, fs, **config):
from dvc.state import StateNoop
self.verify = fs.config.get("verify", self.DEFAULT_VERIFY)
self.cache_types = fs.config.get("type") or copy(
self.DEFAULT_CACHE_TYPES
)
self.fs = fs
self.state = config.get("state", StateNoop())
self.verify = config.get("verify", self.DEFAULT_VERIFY)
self.cache_types = config.get("type") or copy(self.DEFAULT_CACHE_TYPES)
self.cache_type_confirmed = False
self.slow_link_warning = config.get("slow_link_warning", True)
def move(self, from_info, to_info):
self.fs.move(from_info, to_info)
@@ -80,7 +80,7 @@ class ObjectDB:
raise
self.protect(cache_info)
self.fs.repo.state.save(cache_info, self.fs, hash_info)
self.state.save(cache_info, self.fs, hash_info)
callback = kwargs.get("download_callback")
if callback:
+4 -4
View File
@@ -22,11 +22,11 @@ class LocalObjectDB(ObjectDB):
CACHE_MODE = 0o444
UNPACKED_DIR_SUFFIX = ".unpacked"
def __init__(self, fs):
super().__init__(fs)
self.cache_dir = fs.config.get("url")
def __init__(self, fs, **config):
super().__init__(fs, **config)
self.cache_dir = config.get("url")
shared = fs.config.get("shared")
shared = config.get("shared")
if shared:
self._file_mode = 0o664
self._dir_mode = 0o2775
+1 -1
View File
@@ -49,7 +49,7 @@ class HashFile:
return None
actual = get_file_hash(
self.path_info, self.fs, self.hash_info.name, odb.repo.state
self.path_info, self.fs, self.hash_info.name, odb.state
)
logger.trace(
+1 -1
View File
@@ -186,7 +186,7 @@ def stage(odb, path_info, fs, name, upload=False, **kwargs):
errno.ENOENT, os.strerror(errno.ENOENT), path_info
)
state = odb.repo.state
state = odb.state
# pylint: disable=assignment-from-none
hash_info = state.get(path_info, fs)
+1 -1
View File
@@ -40,7 +40,7 @@ class Tree(HashFile):
from dvc.path_info import PathInfo
from dvc.utils import tmp_fname
memfs = MemoryFileSystem(None, {})
memfs = MemoryFileSystem()
path_info = PathInfo(tmp_fname(""))
with memfs.open(path_info, "wb") as fobj:
fobj.write(self.as_bytes())