mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-09 23:10:24 +01:00
The code are wrapped due to us using line-length=79 before, but now some of the code can easily fit in 88 chars. The formatter did not change this automatically when we changed line-length, because of magic trailing commas that gets added when they turn into multiple lines. Black/ruff wrapping them in parens and splitting them into multiple lines was making it difficult to read.
59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
import functools
|
|
from typing import TYPE_CHECKING, Any, Optional
|
|
|
|
from . import FileSystem
|
|
|
|
if TYPE_CHECKING:
|
|
from scmrepo.fs import GitFileSystem as FsspecGitFileSystem
|
|
from scmrepo.git.objects import GitTrie
|
|
|
|
from dvc.scm import Git
|
|
|
|
|
|
class GitFileSystem(FileSystem):
|
|
"""Proxies the repo file access methods to Git objects"""
|
|
|
|
protocol = "local"
|
|
PARAM_CHECKSUM = "md5"
|
|
|
|
def __init__(
|
|
self,
|
|
path: Optional[str] = None,
|
|
rev: Optional[str] = None,
|
|
scm: Optional["Git"] = None,
|
|
trie: Optional["GitTrie"] = None,
|
|
**kwargs: Any,
|
|
) -> None:
|
|
from dvc.scm import resolve_rev
|
|
|
|
super().__init__()
|
|
self.fs_args.update(
|
|
{
|
|
"path": path,
|
|
"rev": rev,
|
|
"scm": scm,
|
|
"trie": trie,
|
|
"rev_resolver": resolve_rev,
|
|
**kwargs,
|
|
}
|
|
)
|
|
|
|
@functools.cached_property
|
|
def fs(self) -> "FsspecGitFileSystem":
|
|
from scmrepo.fs import GitFileSystem as FsspecGitFileSystem
|
|
|
|
return FsspecGitFileSystem(**self.fs_args)
|
|
|
|
def getcwd(self):
|
|
return self.fs.getcwd()
|
|
|
|
def chdir(self, path):
|
|
self.fs.chdir(path)
|
|
|
|
@property
|
|
def rev(self) -> str:
|
|
return self.fs.rev
|
|
|
|
def ls(self, path, detail=True, **kwargs):
|
|
return self.fs.ls(path, detail=detail, **kwargs) or []
|