Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To v0.6.7; improve file closure #79

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading