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),
|
||||
'autoconfig.yml')
|
||||
self._values = {}
|
||||
self._changed = None
|
||||
self._dirty = None
|
||||
|
||||
def init_save_manager(self, save_manager):
|
||||
"""Make sure the config gets saved properly.
|
||||
@ -98,8 +98,7 @@ class YamlConfig:
|
||||
return self._values[name]
|
||||
|
||||
def __setitem__(self, name, value):
|
||||
if self._values.get(name) != value:
|
||||
self._changed = True
|
||||
self._dirty = True
|
||||
self._values[name] = value
|
||||
|
||||
def __contains__(self, name):
|
||||
@ -110,7 +109,7 @@ class YamlConfig:
|
||||
|
||||
def _save(self):
|
||||
"""Save the settings to the YAML file if they've changed."""
|
||||
if not self._changed:
|
||||
if not self._dirty:
|
||||
return
|
||||
|
||||
data = {'config_version': self.VERSION, 'global': self._values}
|
||||
@ -155,7 +154,7 @@ class YamlConfig:
|
||||
raise configexc.ConfigFileErrors('autoconfig.yml', [desc])
|
||||
|
||||
self._values = global_obj
|
||||
self._changed = False
|
||||
self._dirty = False
|
||||
|
||||
|
||||
class ConfigAPI:
|
||||
|
@ -77,7 +77,6 @@ def test_yaml_config(fake_save_manager, config_tmpdir, old_config, insert):
|
||||
else:
|
||||
text = autoconfig.read_text('utf-8')
|
||||
lines = text.splitlines()
|
||||
print(lines)
|
||||
|
||||
if insert:
|
||||
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
|
||||
|
||||
print(lines)
|
||||
|
||||
# WORKAROUND for https://github.com/PyCQA/pylint/issues/574
|
||||
if 'magenta' in (old_config or ''): # pylint: disable=superfluous-parens
|
||||
assert ' colors.hints.fg: magenta' in lines
|
||||
|
Loading…
Reference in New Issue
Block a user