Skip to content

Commit c21fd06

Browse files
committed
To v0.6.7; improve file closure
1 parent 1296b5c commit c21fd06

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lems/model/model.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ def include_file(self, path, include_dirs=[]):
272272
parser = LEMSFileParser(self, inc_dirs, self.include_includes)
273273
if os.access(path, os.F_OK):
274274
if not path in self.included_files:
275-
parser.parse(open(path).read())
275+
with open(path) as f:
276+
parser.parse(f.read())
276277
self.included_files.append(path)
277278
return
278279
else:
@@ -284,7 +285,8 @@ def include_file(self, path, include_dirs=[]):
284285
new_path = inc_dir + "/" + path
285286
if os.access(new_path, os.F_OK):
286287
if not new_path in self.included_files:
287-
parser.parse(open(new_path).read())
288+
with open(new_path) as f:
289+
parser.parse(f.read())
288290
self.included_files.append(new_path)
289291
return
290292
else:
@@ -374,9 +376,11 @@ def export_to_file(self, filepath, level_prefix=" "):
374376
"\n",
375377
)
376378

377-
f = open(filepath, "w")
378-
f.write(xmlstr)
379-
f.close()
379+
with open(filepath, "w") as f:
380+
f.write(xmlstr)
381+
f.flush()
382+
os.fsync(f.fileno())
383+
380384

381385
def resolve(self) -> lems.model.Model:
382386
"""

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = PyLEMS
3-
version = 0.6.5
3+
version = 0.6.7
44
author = PyLEMS authors and contributors
55
66
maintainer_email = [email protected]

0 commit comments

Comments
 (0)