Add qutebrowser config directory to python path

This is done so config.py can import other python files in the config
directory. For example, config.py can 'import theme' which would load
a theme.py.

The previous path is restored at the end of this function, to avoid
tainting qutebrowser's path
This commit is contained in:
Jay Kamat 2017-09-15 20:43:17 -04:00
parent c652b0f96c
commit a2952e13a8
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5

View File

@ -21,6 +21,7 @@
import types
import os.path
import sys
import textwrap
import traceback
import configparser
@ -222,6 +223,12 @@ def read_config_py(filename=None):
if not os.path.exists(filename):
return api
# Add config directory to python path, so config.py can import other files
# in logical places
old_path = sys.path.copy()
if standarddir.config() not in sys.path:
sys.path.insert(0, standarddir.config())
container = config.ConfigContainer(config.instance, configapi=api)
basename = os.path.basename(filename)
@ -256,6 +263,9 @@ def read_config_py(filename=None):
"Unhandled exception",
exception=e, traceback=traceback.format_exc()))
# Restore previous path, to protect qutebrowser's imports
sys.path = old_path
api.finalize()
return api