Ensure files get closed when they go out of scope
This is automatic in CPython but not guaranteed by the language. Be friendly
to other Python implementations.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/scripts/assemble_changelog.py b/scripts/assemble_changelog.py
index b8a63c9..b742cc8 100755
--- a/scripts/assemble_changelog.py
+++ b/scripts/assemble_changelog.py
@@ -407,14 +407,17 @@
is also present in an output file. This is not perfect but good enough
for now.
"""
- generated_output = set(open(generated_output_file, 'r', encoding='utf-8'))
- for line in open(main_input_file, 'r', encoding='utf-8'):
- if line not in generated_output:
- raise LostContent('original file', line)
- for merged_file in merged_files:
- for line in open(merged_file, 'r', encoding='utf-8'):
- if line not in generated_output:
- raise LostContent(merged_file, line)
+ with open(generated_output_file, 'r', encoding='utf-8') as out_fd:
+ generated_output = set(out_fd)
+ with open(main_input_file, 'r', encoding='utf-8') as in_fd:
+ for line in in_fd:
+ if line not in generated_output:
+ raise LostContent('original file', line)
+ for merged_file in merged_files:
+ with open(merged_file, 'r', encoding='utf-8') as in_fd:
+ for line in in_fd:
+ if line not in generated_output:
+ raise LostContent(merged_file, line)
def finish_output(changelog, output_file, input_file, merged_files):
"""Write the changelog to the output file.