Skip to content

Commit

Permalink
Merge pull request #1025 from rkingsbury/monty
Browse files Browse the repository at this point in the history
Add explicit text mode to zopen calls (monty warning)
  • Loading branch information
rkingsbury authored Jan 21, 2025
2 parents 9bc96da + 9da353e commit a7a17c2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/maggma/stores/file_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def query( # type: ignore
# TODO - could add more logic for detecting different file types
# and more nuanced exception handling
try:
with zopen(d["path"], "r", encoding=self.encoding) as f:
with zopen(d["path"], "rt", encoding=self.encoding) as f:
data = f.read()
except Exception as e:
data = f"Unable to read: {e}"
Expand Down
6 changes: 3 additions & 3 deletions src/maggma/stores/mongolike.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ def connect(self, force_reset: bool = False):

# create the .json file if it does not exist
if not self.read_only and not Path(self.paths[0]).exists():
with zopen(self.paths[0], "w", encoding=self.encoding) as f:
with zopen(self.paths[0], "wt", encoding=self.encoding) as f:
data: list[dict] = []
bytesdata = orjson.dumps(data)
f.write(bytesdata.decode("utf-8"))
Expand All @@ -711,7 +711,7 @@ def read_json_file(self, path) -> list:
Args:
path: Path to the JSON file to be read
"""
with zopen(path, "r") as f:
with zopen(path, "rt") as f:
data = f.read()
data = data.decode() if isinstance(data, bytes) else data
objects = bson.json_util.loads(data) if "$oid" in data else orjson.loads(data)
Expand Down Expand Up @@ -761,7 +761,7 @@ def update_json_file(self):
"""
Updates the json file when a write-like operation is performed.
"""
with zopen(self.paths[0], "w", encoding=self.encoding) as f:
with zopen(self.paths[0], "wt", encoding=self.encoding) as f:
data = list(self.query())
for d in data:
d.pop("_id")
Expand Down

0 comments on commit a7a17c2

Please sign in to comment.