Skip to content

Commit 7804c8e

Browse files
committed
deps: update dvc-objects to >=3
1 parent a54e67d commit 7804c8e

File tree

2 files changed

+95
-101
lines changed

2 files changed

+95
-101
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies = [
3030
"asyncssh>=2.13.1,<3",
3131
"funcy>=1.14",
3232
"shortuuid>=0.5.0",
33-
"dvc-objects>=1.0.1,<3",
33+
"dvc-objects>=3,<4",
3434
"dvc-http>=2.29.0",
3535
]
3636

src/scmrepo/fs.py

Lines changed: 94 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,79 @@
1414
from scmrepo.git.objects import GitTrie
1515

1616

17-
class Path:
18-
def __init__(self, sep, getcwd=None, realpath=None):
19-
def _getcwd():
20-
return ""
17+
def bytesio_len(obj: "BytesIO") -> Optional[int]:
18+
try:
19+
offset = obj.tell()
20+
length = obj.seek(0, os.SEEK_END)
21+
obj.seek(offset)
22+
except (AttributeError, OSError):
23+
return None
24+
return length
2125

22-
self.getcwd = getcwd or _getcwd
23-
self.realpath = realpath or self.abspath
2426

25-
assert sep == posixpath.sep
26-
self.flavour = posixpath
27+
class GitFileSystem(AbstractFileSystem):
28+
# pylint: disable=abstract-method
29+
cachable = False
30+
root_marker = "/"
2731

28-
def chdir(self, path):
29-
def _getcwd():
30-
return path
32+
def __init__(
33+
self,
34+
path: str = None,
35+
rev: str = None,
36+
scm: "Git" = None,
37+
trie: "GitTrie" = None,
38+
rev_resolver: Callable[["Git", str], str] = None,
39+
**kwargs,
40+
):
41+
from scmrepo.git import Git
42+
from scmrepo.git.objects import GitTrie
43+
44+
super().__init__(**kwargs)
45+
if not trie:
46+
scm = scm or Git(path)
47+
resolver = rev_resolver or Git.resolve_rev
48+
resolved = resolver(scm, rev or "HEAD")
49+
tree_obj = scm.pygit2.get_tree_obj(rev=resolved)
50+
trie = GitTrie(tree_obj, resolved)
51+
52+
self.trie = trie
53+
self.rev = self.trie.rev
3154

32-
self.getcwd = _getcwd
55+
def getcwd(self):
56+
return self.root_marker
3357

34-
def join(self, *parts):
35-
return self.flavour.join(*parts)
58+
def chdir(self, path):
59+
raise NotImplementedError
60+
61+
@classmethod
62+
def join(cls, *parts):
63+
return posixpath.join(*parts)
3664

37-
def split(self, path):
38-
return self.flavour.split(path)
65+
@classmethod
66+
def split(cls, path):
67+
return posixpath.split(path)
3968

4069
def normpath(self, path):
41-
return self.flavour.normpath(path)
70+
return posixpath.normpath(path)
4271

43-
def isabs(self, path):
44-
return self.flavour.isabs(path)
72+
@classmethod
73+
def isabs(cls, path):
74+
return posixpath.isabs(path)
4575

4676
def abspath(self, path):
4777
if not self.isabs(path):
4878
path = self.join(self.getcwd(), path)
4979
return self.normpath(path)
5080

51-
def commonprefix(self, path):
52-
return self.flavour.commonprefix(path)
53-
54-
def parts(self, path):
55-
drive, path = self.flavour.splitdrive(path.rstrip(self.flavour.sep))
81+
@classmethod
82+
def commonprefix(cls, path):
83+
return posixpath.commonprefix(path)
5684

85+
@classmethod
86+
def parts(cls, path):
5787
ret = []
5888
while True:
59-
path, part = self.flavour.split(path)
89+
path, part = cls.split(path)
6090

6191
if part:
6292
ret.append(part)
@@ -69,113 +99,77 @@ def parts(self, path):
6999

70100
ret.reverse()
71101

72-
if drive:
73-
ret = [drive] + ret
74-
75102
return tuple(ret)
76103

77-
def parent(self, path):
78-
return self.flavour.dirname(path)
104+
@classmethod
105+
def parent(cls, path):
106+
return posixpath.dirname(path)
79107

80-
def dirname(self, path):
81-
return self.parent(path)
108+
@classmethod
109+
def dirname(cls, path):
110+
return cls.parent(path)
82111

83-
def parents(self, path):
84-
parts = self.parts(path)
112+
@classmethod
113+
def parents(cls, path):
114+
parts = cls.parts(path)
85115
return tuple(
86-
self.join(*parts[:length]) for length in range(len(parts) - 1, 0, -1)
116+
cls.join(*parts[:length]) for length in range(len(parts) - 1, 0, -1)
87117
)
88118

89-
def name(self, path):
90-
return self.parts(path)[-1]
119+
@classmethod
120+
def name(cls, path):
121+
return cls.parts(path)[-1]
91122

92-
def suffix(self, path):
93-
name = self.name(path)
123+
@classmethod
124+
def suffix(cls, path):
125+
name = cls.name(path)
94126
_, dot, suffix = name.partition(".")
95127
return dot + suffix
96128

97-
def with_name(self, path, name):
98-
parts = list(self.parts(path))
129+
@classmethod
130+
def with_name(cls, path, name):
131+
parts = list(cls.parts(path))
99132
parts[-1] = name
100-
return self.join(*parts)
133+
return cls.join(*parts)
101134

102-
def with_suffix(self, path, suffix):
103-
parts = list(self.parts(path))
135+
@classmethod
136+
def with_suffix(cls, path, suffix):
137+
parts = list(cls.parts(path))
104138
real_path, _, _ = parts[-1].partition(".")
105139
parts[-1] = real_path + suffix
106-
return self.join(*parts)
140+
return cls.join(*parts)
107141

108-
def isin(self, left, right):
109-
left_parts = self.parts(left)
110-
right_parts = self.parts(right)
142+
@classmethod
143+
def isin(cls, left, right):
144+
left_parts = cls.parts(left)
145+
right_parts = cls.parts(right)
111146
left_len = len(left_parts)
112147
right_len = len(right_parts)
113148
return left_len > right_len and left_parts[:right_len] == right_parts
114149

115-
def isin_or_eq(self, left, right):
116-
return left == right or self.isin(left, right)
150+
@classmethod
151+
def isin_or_eq(cls, left, right):
152+
return left == right or cls.isin(left, right)
117153

118-
def overlaps(self, left, right):
154+
@classmethod
155+
def overlaps(cls, left, right):
119156
# pylint: disable=arguments-out-of-order
120-
return self.isin_or_eq(left, right) or self.isin(right, left)
157+
return cls.isin_or_eq(left, right) or cls.isin(right, left)
121158

122159
def relpath(self, path, start=None):
123160
if start is None:
124161
start = "."
125-
return self.flavour.relpath(self.abspath(path), start=self.abspath(start))
162+
return self.relpath(self.abspath(path), start=self.abspath(start))
126163

127164
def relparts(self, path, start=None):
128165
return self.parts(self.relpath(path, start=start))
129166

130-
def as_posix(self, path):
131-
return path.replace(self.flavour.sep, posixpath.sep)
132-
133-
134-
def bytesio_len(obj: "BytesIO") -> Optional[int]:
135-
try:
136-
offset = obj.tell()
137-
length = obj.seek(0, os.SEEK_END)
138-
obj.seek(offset)
139-
except (AttributeError, OSError):
140-
return None
141-
return length
142-
143-
144-
class GitFileSystem(AbstractFileSystem):
145-
# pylint: disable=abstract-method
146-
cachable = False
147-
root_marker = "/"
148-
149-
def __init__(
150-
self,
151-
path: str = None,
152-
rev: str = None,
153-
scm: "Git" = None,
154-
trie: "GitTrie" = None,
155-
rev_resolver: Callable[["Git", str], str] = None,
156-
**kwargs,
157-
):
158-
from scmrepo.git import Git
159-
from scmrepo.git.objects import GitTrie
160-
161-
super().__init__(**kwargs)
162-
if not trie:
163-
scm = scm or Git(path)
164-
resolver = rev_resolver or Git.resolve_rev
165-
resolved = resolver(scm, rev or "HEAD")
166-
tree_obj = scm.pygit2.get_tree_obj(rev=resolved)
167-
trie = GitTrie(tree_obj, resolved)
168-
169-
self.trie = trie
170-
self.rev = self.trie.rev
171-
172-
def _getcwd():
173-
return self.root_marker
174-
175-
self.path = Path(self.sep, getcwd=_getcwd)
167+
@classmethod
168+
def as_posix(cls, path):
169+
return path
176170

177171
def _get_key(self, path: str) -> Tuple[str, ...]:
178-
path = self.path.abspath(path)
172+
path = self.abspath(path)
179173
if path == self.root_marker:
180174
return ()
181175
relparts = path.split(self.sep)

0 commit comments

Comments
 (0)