Skip to content

Commit 6854f0d

Browse files
committed
lfs: expose fsspec batch_size for fetch operations
1 parent e9e08f0 commit 6854f0d

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/scmrepo/git/lfs/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import shutil
44
from collections.abc import Iterable, Iterator
55
from contextlib import AbstractContextManager, contextmanager, suppress
6-
from multiprocessing import cpu_count
76
from tempfile import NamedTemporaryFile
87
from typing import TYPE_CHECKING, Any, Optional
98

@@ -32,7 +31,6 @@ class LFSClient(AbstractContextManager):
3231

3332
JSON_CONTENT_TYPE = "application/vnd.git-lfs+json"
3433

35-
_JOBS = 4 * cpu_count()
3634
_REQUEST_TIMEOUT = 60
3735
_SESSION_RETRIES = 5
3836
_SESSION_BACKOFF_FACTOR = 0.1
@@ -154,6 +152,7 @@ async def _download(
154152
storage: "LFSStorage",
155153
objects: Iterable[Pointer],
156154
callback: "Callback" = DEFAULT_CALLBACK,
155+
batch_size: Optional[int] = None,
157156
**kwargs,
158157
):
159158
async def _get_one(from_path: str, to_path: str, **kwargs):
@@ -179,7 +178,7 @@ async def _get_one(from_path: str, to_path: str, **kwargs):
179178
to_path = storage.oid_to_path(obj.oid)
180179
coros.append(_get_one(url, to_path, headers=headers))
181180
for result in await _run_coros_in_chunks(
182-
coros, batch_size=self._JOBS, return_exceptions=True
181+
coros, batch_size=batch_size, return_exceptions=True
183182
):
184183
if isinstance(result, BaseException):
185184
raise result

src/scmrepo/git/lfs/smudge.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111

1212

1313
def smudge(
14-
storage: "LFSStorage", fobj: BinaryIO, url: Optional[str] = None
14+
storage: "LFSStorage",
15+
fobj: BinaryIO,
16+
url: Optional[str] = None,
17+
batch_size: Optional[int] = None,
1518
) -> BinaryIO:
1619
"""Wrap the specified binary IO stream and run LFS smudge if necessary."""
1720
reader = io.BufferedReader(fobj) # type: ignore[arg-type]

src/scmrepo/git/lfs/storage.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ def fetch(
2020
url: str,
2121
objects: Collection[Pointer],
2222
progress: Optional[Callable[["GitProgressEvent"], None]] = None,
23+
batch_size: Optional[int] = None,
2324
):
2425
from .client import LFSClient
2526

2627
with LFSCallback.as_lfs_callback(progress) as cb:
2728
cb.set_size(len(objects))
2829
with LFSClient.from_git_url(url) as client:
29-
client.download(self, objects, callback=cb)
30+
client.download(self, objects, callback=cb, batch_size=batch_size)
3031

3132
def oid_to_path(self, oid: str):
3233
return os.path.join(self.path, "objects", oid[0:2], oid[2:4], oid)
@@ -40,6 +41,7 @@ def open(
4041
self,
4142
obj: Union[Pointer, str],
4243
fetch_url: Optional[str] = None,
44+
batch_size: Optional[int] = None,
4345
**kwargs,
4446
) -> BinaryIO:
4547
oid = obj if isinstance(obj, str) else obj.oid
@@ -50,7 +52,7 @@ def open(
5052
if not fetch_url or not isinstance(obj, Pointer):
5153
raise
5254
try:
53-
self.fetch(fetch_url, [obj])
55+
self.fetch(fetch_url, [obj], batch_size=batch_size)
5456
except BaseException as exc: # noqa: BLE001
5557
raise FileNotFoundError(
5658
errno.ENOENT, os.strerror(errno.ENOENT), path

0 commit comments

Comments
 (0)