Don't make default config a mutable global.
Before, configdata.DATA only existed once - that means when something manipulated it, instantiating a new ConfigManager actually gave us the *modified* rather than the default data. There's still a (now readonly) configdata.DATA for performance reasons - before, the settings completion model called data() many times, which caused initializing of it taking a few (instead of nearly 0) seconds. See https://github.com/hackebrot/qutebrowser/pull/16#discussion-diff-27770433
This commit is contained in:
parent
b2df5a5b47
commit
57158e7191
@ -281,7 +281,7 @@ class ConfigManager(QObject):
|
||||
def __init__(self, configdir, fname, relaxed=False, parent=None):
|
||||
super().__init__(parent)
|
||||
self._initialized = False
|
||||
self.sections = configdata.DATA
|
||||
self.sections = configdata.data()
|
||||
self._interpolation = configparser.ExtendedInterpolation()
|
||||
self._proxies = {}
|
||||
for sectname in self.sections.keys():
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -29,6 +29,7 @@ class Section:
|
||||
"""Base class for KeyValue/ValueList sections.
|
||||
|
||||
Attributes:
|
||||
_readonly: Whether this section is read-only.
|
||||
values: An OrderedDict with key as index and value as value.
|
||||
key: string
|
||||
value: SettingValue
|
||||
@ -38,6 +39,7 @@ class Section:
|
||||
def __init__(self):
|
||||
self.values = None
|
||||
self.descriptions = {}
|
||||
self._readonly = False
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Get the value for key.
|
||||
@ -99,13 +101,15 @@ class KeyValue(Section):
|
||||
set of keys.
|
||||
"""
|
||||
|
||||
def __init__(self, *defaults):
|
||||
def __init__(self, *defaults, readonly=False):
|
||||
"""Constructor.
|
||||
|
||||
Args:
|
||||
*defaults: A (key, value, description) list of defaults.
|
||||
readonly: Whether this config is readonly.
|
||||
"""
|
||||
super().__init__()
|
||||
self._readonly = readonly
|
||||
if not defaults:
|
||||
return
|
||||
self.values = collections.OrderedDict()
|
||||
@ -115,6 +119,8 @@ class KeyValue(Section):
|
||||
self.descriptions[k] = desc
|
||||
|
||||
def setv(self, layer, key, value, interpolated):
|
||||
if self._readonly:
|
||||
raise ValueError("Trying to modify a read-only config!")
|
||||
self.values[key].setv(layer, value, interpolated)
|
||||
|
||||
def dump_userconfig(self):
|
||||
@ -143,17 +149,20 @@ class ValueList(Section):
|
||||
keytype: The type to use for the key (only used for validating)
|
||||
valtype: The type to use for the value.
|
||||
_ordered_value_cache: A ChainMap-like OrderedDict of all values.
|
||||
_readonly: Whether this section is read-only.
|
||||
"""
|
||||
|
||||
def __init__(self, keytype, valtype, *defaults):
|
||||
def __init__(self, keytype, valtype, *defaults, readonly=False):
|
||||
"""Wrap types over default values. Take care when overriding this.
|
||||
|
||||
Args:
|
||||
keytype: The type instance to be used for keys.
|
||||
valtype: The type instance to be used for values.
|
||||
*defaults: A (key, value) list of default values.
|
||||
readonly: Whether this config is readonly.
|
||||
"""
|
||||
super().__init__()
|
||||
self._readonly = readonly
|
||||
self._ordered_value_cache = None
|
||||
self.keytype = keytype
|
||||
self.valtype = valtype
|
||||
@ -182,6 +191,8 @@ class ValueList(Section):
|
||||
return self._ordered_value_cache
|
||||
|
||||
def setv(self, layer, key, value, interpolated):
|
||||
if self._readonly:
|
||||
raise ValueError("Trying to modify a read-only config!")
|
||||
self.keytype.validate(key)
|
||||
if key in self.layers[layer]:
|
||||
self.layers[layer][key].setv(layer, value, interpolated)
|
||||
|
Loading…
Reference in New Issue
Block a user