Skip to content

Commit

Permalink
config: use validate() more explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Jan 27, 2020
1 parent 566cc6c commit 230e5c8
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def load(self):
if not self.should_validate:
return

d = self.validate()
d = self.validate(self.config)
self.config = configobj.ConfigObj(d, write_empty_values=True)

def save(self, config=None):
Expand Down Expand Up @@ -423,14 +423,9 @@ def _save(config):
raise
config.write()

def validate(self, config=None):
ret = copy.deepcopy(self.config)

if config:
ret.merge(config)

def validate(self, config):
try:
return self.COMPILED_SCHEMA(ret.dict())
return self.COMPILED_SCHEMA(config.dict())
except Invalid as exc:
raise ConfigError(str(exc)) from exc

Expand Down Expand Up @@ -499,7 +494,10 @@ def set(self, section, opt, value, level=None, force=True):

config[section][opt] = value

self.validate(config)
result = copy.deepcopy(self.config)
result.merge(config)
self.validate(result)

self.save(config)

def get(self, section, opt=None, level=None):
Expand Down

0 comments on commit 230e5c8

Please sign in to comment.