Skip to content

Commit

Permalink
Fix eva config update bug (#393)
Browse files Browse the repository at this point in the history
* Fix eva config update bug

Updating the yaml file was appending to instead of rewriting file

* Fix configuration test bug

Mode field was being reset to the value of datasets_dir instead of the
old value of mode.
  • Loading branch information
LordDarkula committed Sep 23, 2022
1 parent 473de9d commit 366ecdb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions eva/configuration/bootstrap_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def bootstrap_environment(eva_config_dir: Path, eva_installation_dir: Path):
config_obj["core"]["catalog_database_uri"] = DB_DEFAULT_URI
config_obj["storage"]["upload_dir"] = str(upload_dir.resolve())

yml_file.seek(0)
yml_file.write(yaml.dump(config_obj))
yml_file.truncate()

# set logger to appropriate level (debug or release)
level = logging.WARN if mode == "release" else logging.DEBUG
Expand Down
2 changes: 2 additions & 0 deletions eva/configuration/configuration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def _update(cls, category: str, key: str, value: str):
raise ValueError(f"Invalid yml file at {cls._yml_path}")

config_obj[category][key] = value
yml_file.seek(0)
yml_file.write(yaml.dump(config_obj))
yml_file.truncate()

@classmethod
def get_value(cls, category: str, key: str) -> Any:
Expand Down
2 changes: 1 addition & 1 deletion test/configuration/test_configuration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_configuration_manager_read_invalid_key(self):
_ = self.config.get_value("core", "invalid")

def test_configuration_manager_update_valid_key(self):
value = self.config.get_value("core", "datasets_dir")
value = self.config.get_value("core", "mode")

updated = "debug2"
self.config.update_value("core", "mode", updated)
Expand Down

0 comments on commit 366ecdb

Please sign in to comment.