From a2952e13a896fffbb16bc31549d8919bbd4f40e8 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Fri, 15 Sep 2017 20:43:17 -0400 Subject: [PATCH] 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 --- qutebrowser/config/configfiles.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index a155726a8..155a2c99f 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -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