Skip to content

Commit 92d6901

Browse files
authored
Merge pull request #652 from betatim/fix-memory-limit
[MRG] Fix handling of memory limit command line argument
2 parents c56e8b1 + c8cff1b commit 92d6901

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

repo2docker/__main__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,12 @@ def make_r2d(argv=None):
300300
r2d.user_name = args.user_name
301301

302302
if args.build_memory_limit:
303-
r2d.build_memory_limit = args.build_memory_limit
303+
# if the string only contains numerals we assume it should be an int
304+
# and specifies a size in bytes
305+
if args.build_memory_limit.isnumeric():
306+
r2d.build_memory_limit = int(args.build_memory_limit)
307+
else:
308+
r2d.build_memory_limit = args.build_memory_limit
304309

305310
if args.environment and not r2d.run:
306311
print('To specify environment variables, you also need to run '

tests/unit/test_args.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ def test_dry_run():
4040
assert not r2d.run
4141
assert not r2d.push
4242

43+
44+
def test_mem_limit():
45+
"""
46+
Test various ways of passing --build-memory-limit
47+
"""
48+
r2d = make_r2d(['--build-memory-limit', '1024', '.'])
49+
assert int(r2d.build_memory_limit) == 1024
50+
51+
r2d = make_r2d(['--build-memory-limit', '3K', '.'])
52+
assert int(r2d.build_memory_limit) == 1024 * 3
53+
4354
def test_run_required():
4455
"""
4556
Test all the things that should fail if we pass in --no-run

0 commit comments

Comments
 (0)