Skip to content

Commit

Permalink
chore: Add context around file opening for autoclose
Browse files Browse the repository at this point in the history
  • Loading branch information
adjavon committed Feb 15, 2024
1 parent 3d762d0 commit 71f47d5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dacapo/store/file_config_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ def __save_insert(self, collection, data, ignore=None):

file_store = collection / f"{name}.toml"
if not file_store.exists():
toml.dump(dict(data), file_store.open("w"))
with file_store.open("w") as f:
toml.dump(dict(data), f)

else:
existing = toml.load(file_store.open("r"))
with file_store.open("r") as f:
existing = toml.load(f)

if not self.__same_doc(existing, data, ignore):
raise DuplicateNameError(
Expand All @@ -113,7 +115,8 @@ def __save_insert(self, collection, data, ignore=None):
def __load(self, collection, name):
file_store = collection / f"{name}.toml"
if file_store.exists():
return toml.load(file_store.open("r"))
with file_store.open("r") as f:
return toml.load(f)
else:
raise ValueError(f"No config with name: {name} in collection: {collection}")

Expand Down

0 comments on commit 71f47d5

Please sign in to comment.