Skip to content

Commit f60783e

Browse files
authored
fix(cli): allow renku run with many inputs
Note: This commit fixes only the case where a renku run command implicitly relies on many arguments which are NOT already expanded in the command line. Closes #552.
1 parent 0542fcc commit f60783e

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

renku/api/storage.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
HAS_LFS = call(['git', 'lfs'], stdout=PIPE, stderr=STDOUT) == 0
3333

34+
# Batch size for when renku is expanding a large list
35+
# of files into an argument string.
36+
ARGUMENT_BATCH_SIZE = 100
37+
3438

3539
@attr.s
3640
class StorageApiMixin(RepositoryApiMixin):
@@ -105,6 +109,7 @@ def untrack_paths_from_storage(self, *paths):
105109

106110
def pull_paths_from_storage(self, *paths):
107111
"""Pull paths from LFS."""
112+
import math
108113
if self.use_external_storage and self.external_storage_installed:
109114
client_dict = defaultdict(list)
110115

@@ -115,12 +120,22 @@ def pull_paths_from_storage(self, *paths):
115120
client_dict[client.path].append(str(path))
116121

117122
for client_path, paths in client_dict.items():
118-
run(
119-
self._CMD_STORAGE_PULL + [shlex.quote(','.join(paths))],
120-
cwd=str(client_path.absolute()),
121-
stdout=PIPE,
122-
stderr=STDOUT,
123-
)
123+
for ibatch in range(
124+
math.ceil(len(paths) / ARGUMENT_BATCH_SIZE)
125+
):
126+
run(
127+
self._CMD_STORAGE_PULL + [
128+
shlex.quote(
129+
','.join(
130+
paths[ibatch * ARGUMENT_BATCH_SIZE:
131+
(ibatch + 1) * ARGUMENT_BATCH_SIZE]
132+
)
133+
)
134+
],
135+
cwd=str(client_path.absolute()),
136+
stdout=PIPE,
137+
stderr=STDOUT,
138+
)
124139
elif self.use_external_storage:
125140
raise errors.ExternalStorageNotInstalled(self.repo)
126141

tests/test_cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ def test_run_simple(runner, project):
103103
assert '.renku/workflow/' in result.output
104104

105105

106+
def test_run_many_args(client, run):
107+
"""Test a renku run command which implicitly relies on many inputs."""
108+
109+
os.mkdir('files')
110+
output = 'output.txt'
111+
for i in range(5003):
112+
os.system('touch files/{}.txt'.format(i))
113+
client.repo.index.add(['files/'])
114+
client.repo.index.commit('add many files')
115+
116+
exit_code = run(args=('run', 'ls', 'files/'), stdout=output)
117+
assert 0 == exit_code
118+
119+
106120
_CMD_EXIT_2 = ['bash', '-c', 'exit 2']
107121

108122

0 commit comments

Comments
 (0)