google/caliban

KeyError: 'apt_packages' with latest commit

eschnett opened this issue · 4 comments

The latest commit seems to have introduce an error into handling configuration files. I have a project that does not have a .calibanconfig.json file, and caliban shell now reports an error:

(base) MAC0008052:DDF.jl erikschnetter$ caliban shell --nogpu
Traceback (most recent call last):
  File "/Users/erikschnetter/opt/anaconda3/bin/caliban", line 11, in <module>
    load_entry_point('caliban==0.2.6+9.gf59ace0', 'console_scripts', 'caliban')()
  File "/Users/erikschnetter/opt/anaconda3/lib/python3.7/site-packages/caliban-0.2.6+9.gf59ace0-py3.7.egg/caliban/main.py", line 164, in main
  File "/Users/erikschnetter/opt/anaconda3/lib/python3.7/site-packages/absl/app.py", line 299, in run
    _run_main(main, args)
  File "/Users/erikschnetter/opt/anaconda3/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main
    sys.exit(main(argv))
  File "/Users/erikschnetter/opt/anaconda3/lib/python3.7/site-packages/caliban-0.2.6+9.gf59ace0-py3.7.egg/caliban/main.py", line 74, in run_app
  File "/Users/erikschnetter/opt/anaconda3/lib/python3.7/site-packages/caliban-0.2.6+9.gf59ace0-py3.7.egg/caliban/platform/shell.py", line 113, in run_interactive
  File "/Users/erikschnetter/opt/anaconda3/lib/python3.7/site-packages/caliban-0.2.6+9.gf59ace0-py3.7.egg/caliban/platform/run.py", line 295, in run
  File "/Users/erikschnetter/opt/anaconda3/lib/python3.7/site-packages/caliban-0.2.6+9.gf59ace0-py3.7.egg/caliban/docker/build.py", line 628, in build_image
  File "/Users/erikschnetter/opt/anaconda3/lib/python3.7/site-packages/caliban-0.2.6+9.gf59ace0-py3.7.egg/caliban/docker/build.py", line 583, in _dockerfile_template
  File "/Users/erikschnetter/opt/anaconda3/lib/python3.7/site-packages/caliban-0.2.6+9.gf59ace0-py3.7.egg/caliban/config/__init__.py", line 164, in apt_packages
KeyError: 'apt_packages'

I believe the problem is that caliban_config creates an empty dictionary, and apt_packages later tries to access the key "apt_packages" in there.

Looking deeper, the problem might be that the empty dictionary does not contain the default entries that should be present in the CalibanConfig schema.

I pushed a change for this here: #41. I think this should be sufficient if you'd like to give it a shot prior to review/merge. I was able to reproduce what you saw and this fixes things for me.

Hey @eschnett , I believe this is fixed now with #41. Closing, but please re-open if you run into this again! (I've added some tests that check for this so we should be good.)

I'm also working on a patch that change the default mode to cpu so you won't have to add that --nogpu flag all over. The patch is a default_mode setting that will let you choose the mode you prefer, with always the ability to override with a flag.