Repository: learningequality/kolibri

Issue:
`kolibri --version` can fail based on value of `KOLIBRI_HOME`
## Observed behavior

My `KOLIBRI_HOME` env var was set to a directory that no longer existed:

```bash
echo $KOLIBRI_HOME                                
~/kolibri/014x
```

Running `kolibri --version` caused an unhandled exception:

```bash
kolibri --version
INFO: No C extensions are available for this platform
Traceback (most recent call last):
  File "/Users/d/Projects/le/kolibri/.venv/bin/kolibri", line 33, in <module>
    sys.exit(load_entry_point('kolibri', 'console_scripts', 'kolibri')())
  File "/Users/d/Projects/le/kolibri/.venv/bin/kolibri", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/d/Projects/le/kolibri/kolibri/utils/cli.py", line 15, in <module>
    from kolibri.plugins import config
  File "/Users/d/Projects/le/kolibri/kolibri/plugins/__init__.py", line 16, in <module>
    from kolibri.utils.conf import KOLIBRI_HOME
  File "/Users/d/Projects/le/kolibri/kolibri/utils/conf.py", line 39, in <module>
    raise RuntimeError(
RuntimeError: The parent of your KOLIBRI_HOME does not exist: /Users/d/kolibri
```



## Expected behavior

At a minimum, this should be a handled error with a cleaner message, and no stack trace.

Nice-to-have: outputting the version should not depend on loading `KOLIBRI_HOME`.



## User-facing consequences

Unpleasant command-line experience




## Context

0.15


Discussion:

Resolving patch:
diff --git a/kolibri/utils/cli.py b/kolibri/utils/cli.py
--- a/kolibri/utils/cli.py
+++ b/kolibri/utils/cli.py
@@ -12,7 +12,12 @@
 from django.core.management import execute_from_command_line
 
 import kolibri
-from kolibri.plugins import config
+
+try:
+    from kolibri.plugins import config
+except RuntimeError as e:
+    logging.error("Loading plugin configuration failed with error '{}'".format(e))
+    sys.exit(1)
 from kolibri.plugins import DEFAULT_PLUGINS
 from kolibri.plugins.utils import disable_plugin
 from kolibri.plugins.utils import enable_plugin
@@ -335,7 +340,7 @@ def services(port, background):
 
     logger.info("Starting Kolibri background services")
 
-    server.start(port=port, zip_port=None, serve_http=False, background=background)
+    server.start(port=port, zip_port=0, serve_http=False, background=background)
 
 
 @main.command(cls=KolibriCommand, help="Restart the Kolibri process")


Test patch: