Skip to content

Commit

Permalink
To v0.6.7; improve file closure
Browse files Browse the repository at this point in the history
  • Loading branch information
pgleeson committed Feb 21, 2024
1 parent 1296b5c commit c21fd06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions lems/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def include_file(self, path, include_dirs=[]):
parser = LEMSFileParser(self, inc_dirs, self.include_includes)
if os.access(path, os.F_OK):
if not path in self.included_files:
parser.parse(open(path).read())
with open(path) as f:
parser.parse(f.read())
self.included_files.append(path)
return
else:
Expand All @@ -284,7 +285,8 @@ def include_file(self, path, include_dirs=[]):
new_path = inc_dir + "/" + path
if os.access(new_path, os.F_OK):
if not new_path in self.included_files:
parser.parse(open(new_path).read())
with open(new_path) as f:
parser.parse(f.read())
self.included_files.append(new_path)
return
else:
Expand Down Expand Up @@ -374,9 +376,11 @@ def export_to_file(self, filepath, level_prefix=" "):
"\n",
)

f = open(filepath, "w")
f.write(xmlstr)
f.close()
with open(filepath, "w") as f:
f.write(xmlstr)
f.flush()
os.fsync(f.fileno())


def resolve(self) -> lems.model.Model:
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = PyLEMS
version = 0.6.5
version = 0.6.7
author = PyLEMS authors and contributors
author_email = [email protected], [email protected]
maintainer_email = [email protected]
Expand Down

0 comments on commit c21fd06

Please sign in to comment.