Skip to content

Commit 1026ae6

Browse files
expose chunk_size and document its significance
This commit addresses reviewer comment <datalad#596 (comment)>. It exposes `chunk_size` in `shell_connection` and documents its significance for the size of the `stderr`-queue that is accessible via the `stderr_deque`-attribute of a `ShellCommandResponseGenerator`-object.
1 parent 6919bc0 commit 1026ae6

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

datalad_next/utils/shell_connection.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from more_itertools import consume
1919

20+
from datalad_next.consts import COPY_BUFSIZE
2021
from datalad_next.itertools import align_pattern
2122
from datalad_next.runners.iter_subproc import (
2223
OutputFrom,
@@ -29,6 +30,8 @@
2930

3031
@contextmanager
3132
def shell_connection(shell_cmd: list[str],
33+
*,
34+
chunk_size: int = COPY_BUFSIZE
3235
) -> Generator[ShellCommandExecutor, None, None]:
3336
"""Context manager that provides an interactive connection to a shell
3437
@@ -64,6 +67,7 @@ def train(queue: Queue):
6467
subprocess_inputs: Queue = Queue()
6568
with iter_subproc(shell_cmd,
6669
input=train(subprocess_inputs),
70+
chunk_size=chunk_size,
6771
bufsize=0) as shell_output:
6872
cmd_executor = ShellCommandExecutor(subprocess_inputs, shell_output)
6973
try:
@@ -170,7 +174,9 @@ def upload(self,
170174
-------
171175
tuple[int, bytes]
172176
A tuple containing the return code of the command that was executed
173-
to upload the content and the last 64k bytes of stderr output
177+
to upload the file and the last ``chunk_size`` (defined by the
178+
``chunk_size`` keyword argument to func:`shell_connection`) bytes
179+
of stderr output.
174180
"""
175181
file_size = local_path.stat().st_size
176182
cmd_line = f'dd bs=1 of="{remote_path.as_posix()}" count={file_size}'
@@ -199,7 +205,9 @@ def download(self,
199205
-------
200206
tuple[int, bytes]
201207
A tuple containing the return code of the command that was executed
202-
to upload the content and the last 64k bytes of stderr output
208+
to download the file and the last ``chunk_size`` (defined by the
209+
``chunk_size`` keyword argument to func:`shell_connection`) bytes
210+
of stderr output.
203211
"""
204212
# We use 7z in gzip-mode to compress the data that is sent over the
205213
# wire. That ensures that the end-marker is not in the downloaded data,
@@ -231,7 +239,9 @@ def delete(self,
231239
-------
232240
tuple[int, bytes]
233241
A tuple containing the return code of the command that was executed
234-
to delete the files and the last 64k bytes of stderr output.
242+
to delete the files and the last ``chunk_size`` (defined by the
243+
``chunk_size`` keyword argument to func:`shell_connection`) bytes
244+
of stderr output.
235245
"""
236246
cmd_line = \
237247
'rm ' \
@@ -261,7 +271,11 @@ class ShellCommandResponseGenerator(ABCGenerator):
261271
:class:`ShellCommandExecutor`. It yields all bytes that the executed
262272
command writes to its ``stdout``. Once the command is finished, the
263273
generator will be exhausted. At this time, the return code of the command
264-
can be retrieved from the ``code``-attribute of the generator.
274+
can be retrieved from the ``code``-attribute of the generator. The last
275+
``chunk_size`` (defined by the ``chunk_size`` keyword argument to
276+
func:`shell_connection`) bytes of the stderr-output of the command are
277+
available in the ``stderr_dequeue``-attribute, which contains a
278+
``deque``-object that holds individual stderr chunks.
265279
"""
266280
def __init__(self,
267281
stdout: OutputFrom,

0 commit comments

Comments
 (0)