diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 57837084f..77270b765 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -140,9 +140,10 @@ def _init_main_config(parent=None): parent: The parent to pass to ConfigManager. """ args = objreg.get('args') + config_obj = ConfigManager(parent=parent) try: - config_obj = ConfigManager(standarddir.config(), 'qutebrowser.conf', - args.relaxed_config, parent=parent) + config_obj.read(standarddir.config(), 'qutebrowser.conf', + relaxed=args.relaxed_config) except (configexc.Error, configparser.Error, UnicodeDecodeError) as e: log.init.exception(e) errstr = "Error while reading config:" @@ -362,24 +363,16 @@ class ConfigManager(QObject): changed = pyqtSignal(str, str) style_changed = pyqtSignal(str, str) - def __init__(self, configdir, fname, relaxed=False, parent=None): + def __init__(self, parent=None): super().__init__(parent) self._initialized = False + self._configdir = None + self._fname = None self.sections = configdata.data() self._interpolation = configparser.ExtendedInterpolation() self._proxies = {} for sectname in self.sections: self._proxies[sectname] = SectionProxy(self, sectname) - self._fname = fname - if configdir is None: - self._configdir = None - self._initialized = True - else: - self._configdir = configdir - parser = ini.ReadConfigParser(configdir, fname) - self._from_cp(parser, relaxed) - self._initialized = True - self._validate_all() def __getitem__(self, key): """Get a section from the config.""" @@ -571,6 +564,19 @@ class ConfigManager(QObject): option.value()): self._changed(sectname, optname) + def read(self, configdir, fname, relaxed=False): + """Read the config from the given directory/file.""" + self._fname = fname + if configdir is None: + self._configdir = None + self._initialized = True + else: + self._configdir = configdir + parser = ini.ReadConfigParser(configdir, fname) + self._from_cp(parser, relaxed) + self._initialized = True + self._validate_all() + def items(self, sectname, raw=True): """Get a list of (optname, value) tuples for a section. diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index 4f46ade29..8b54988d7 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -47,7 +47,8 @@ class TestConfigParser: cp = configparser.ConfigParser(interpolation=None, comment_prefixes='#') cp.optionxform = lambda opt: opt # be case-insensitive - cfg = config.ConfigManager(None, None) + cfg = config.ConfigManager() + cfg.read(None, None) return self.Objects(cp=cp, cfg=cfg) def test_simple(self, objects): @@ -272,7 +273,7 @@ class TestDefaultConfig: @pytest.mark.usefixtures('qapp') def test_default_config(self): """Test validating of the default config.""" - conf = config.ConfigManager(None, None) + conf = config.ConfigManager() conf._validate_all() def test_default_key_config(self):