Use context blocks for open() calls in packaging

Two unclosed file descriptors in packaging are raising
ResourceWarning on termination in newer Python interpreters. Make
sure they're closed as soon as we're done with them.

Change-Id: I07f500e1157da18de799eb0ff9bf82d3bcb46510
This commit is contained in:
Jeremy Stanley 2021-11-19 18:36:32 +00:00
parent 8cd1a06e82
commit b6b204e33e
1 changed files with 6 additions and 8 deletions

View File

@ -581,8 +581,9 @@ class LocalEggInfo(egg_info.egg_info):
else:
log.info("[pbr] Reusing existing SOURCES.txt")
self.filelist = egg_info.FileList()
for entry in open(manifest_filename, 'r').read().split('\n'):
self.filelist.append(entry)
with open(manifest_filename, 'r') as fil:
for entry in fil.read().split('\n'):
self.filelist.append(entry)
def _from_git(distribution):
@ -823,12 +824,9 @@ def _get_version_from_pkg_metadata(package_name):
pkg_metadata = {}
for filename in pkg_metadata_filenames:
try:
pkg_metadata_file = open(filename, 'r')
except (IOError, OSError):
continue
try:
pkg_metadata = email.message_from_file(pkg_metadata_file)
except email.errors.MessageError:
with open(filename, 'r') as pkg_metadata_file:
pkg_metadata = email.message_from_file(pkg_metadata_file)
except (IOError, OSError, email.errors.MessageError):
continue
# Check to make sure we're in our own dir