From c21fd06c9241bd7f13244d0f3f2d5e7547ee9c16 Mon Sep 17 00:00:00 2001
From: pgleeson
Date: Wed, 21 Feb 2024 11:40:07 +0000
Subject: [PATCH] To v0.6.7; improve file closure
---
lems/model/model.py | 14 +++++++++-----
setup.cfg | 2 +-
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/lems/model/model.py b/lems/model/model.py
index 527bd91..83e022f 100644
--- a/lems/model/model.py
+++ b/lems/model/model.py
@@ -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:
@@ -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:
@@ -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:
"""
diff --git a/setup.cfg b/setup.cfg
index a84acf1..f480844 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = PyLEMS
-version = 0.6.5
+version = 0.6.7
author = PyLEMS authors and contributors
author_email = gautham@lisphacker.org, p.gleeson@gmail.com
maintainer_email = p.gleeson@gmail.com