make changed dirty and save on duplicate write
This commit is contained in:
parent
8e14d1b7e6
commit
285b534384
@ -84,7 +84,7 @@ class YamlConfig:
|
|||||||
self._filename = os.path.join(standarddir.config(auto=True),
|
self._filename = os.path.join(standarddir.config(auto=True),
|
||||||
'autoconfig.yml')
|
'autoconfig.yml')
|
||||||
self._values = {}
|
self._values = {}
|
||||||
self._changed = None
|
self._dirty = None
|
||||||
|
|
||||||
def init_save_manager(self, save_manager):
|
def init_save_manager(self, save_manager):
|
||||||
"""Make sure the config gets saved properly.
|
"""Make sure the config gets saved properly.
|
||||||
@ -98,8 +98,7 @@ class YamlConfig:
|
|||||||
return self._values[name]
|
return self._values[name]
|
||||||
|
|
||||||
def __setitem__(self, name, value):
|
def __setitem__(self, name, value):
|
||||||
if self._values.get(name) != value:
|
self._dirty = True
|
||||||
self._changed = True
|
|
||||||
self._values[name] = value
|
self._values[name] = value
|
||||||
|
|
||||||
def __contains__(self, name):
|
def __contains__(self, name):
|
||||||
@ -110,7 +109,7 @@ class YamlConfig:
|
|||||||
|
|
||||||
def _save(self):
|
def _save(self):
|
||||||
"""Save the settings to the YAML file if they've changed."""
|
"""Save the settings to the YAML file if they've changed."""
|
||||||
if not self._changed:
|
if not self._dirty:
|
||||||
return
|
return
|
||||||
|
|
||||||
data = {'config_version': self.VERSION, 'global': self._values}
|
data = {'config_version': self.VERSION, 'global': self._values}
|
||||||
@ -155,7 +154,7 @@ class YamlConfig:
|
|||||||
raise configexc.ConfigFileErrors('autoconfig.yml', [desc])
|
raise configexc.ConfigFileErrors('autoconfig.yml', [desc])
|
||||||
|
|
||||||
self._values = global_obj
|
self._values = global_obj
|
||||||
self._changed = False
|
self._dirty = False
|
||||||
|
|
||||||
|
|
||||||
class ConfigAPI:
|
class ConfigAPI:
|
||||||
|
@ -77,7 +77,6 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
|
|||||||
else:
|
else:
|
||||||
text = autoconfig.read_text('utf-8')
|
text = autoconfig.read_text('utf-8')
|
||||||
lines = text.splitlines()
|
lines = text.splitlines()
|
||||||
print(lines)
|
|
||||||
|
|
||||||
if insert:
|
if insert:
|
||||||
assert lines[0].startswith('# DO NOT edit this file by hand,')
|
assert lines[0].startswith('# DO NOT edit this file by hand,')
|
||||||
@ -85,6 +84,8 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
|
|||||||
|
|
||||||
assert 'global:' in lines
|
assert 'global:' in lines
|
||||||
|
|
||||||
|
print(lines)
|
||||||
|
|
||||||
# WORKAROUND for https://github.com/PyCQA/pylint/issues/574
|
# WORKAROUND for https://github.com/PyCQA/pylint/issues/574
|
||||||
if 'magenta' in (old_config or ''): # pylint: disable=superfluous-parens
|
if 'magenta' in (old_config or ''): # pylint: disable=superfluous-parens
|
||||||
assert ' colors.hints.fg: magenta' in lines
|
assert ' colors.hints.fg: magenta' in lines
|
||||||
|
Loading…
Reference in New Issue
Block a user