diff options
author | David Ripton <dripton@redhat.com> | 2012-10-17 10:35:59 -0400 |
---|---|---|
committer | David Ripton <dripton@redhat.com> | 2012-10-17 10:39:02 -0400 |
commit | 01de1955dc1467f1792bba2f0c7b35ffa582bb41 (patch) | |
tree | d63240920261b86005df883efcb979b177669556 /setup.py | |
parent | c558e93480736a2e98d80696498c30c8d81af2bf (diff) | |
download | pbr-01de1955dc1467f1792bba2f0c7b35ffa582bb41.tar.gz |
Fix a couple of file handle leaks, using with statements.
In practice unclosed file handle leaks are not a huge deal in CPython code,
because reference counting means they get closed automatically in a timely
manner. But they're bad style, and they can become a real problem if the
code is run with a version of Python that doesn't use reference counting.
Change-Id: Ie54b979e26ffc9dd405871ee07c50b304cb36c67
Diffstat (limited to 'setup.py')
-rw-r--r-- | setup.py | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -31,13 +31,13 @@ from setuptools.command import sdist def parse_mailmap(mailmap='.mailmap'): mapping = {} if os.path.exists(mailmap): - fp = open(mailmap, 'r') - for l in fp: - l = l.strip() - if not l.startswith('#') and ' ' in l: - canonical_email, alias = [x for x in l.split(' ') - if x.startswith('<')] - mapping[alias] = canonical_email + with open(mailmap, 'r') as fp: + for l in fp: + l = l.strip() + if not l.startswith('#') and ' ' in l: + canonical_email, alias = [x for x in l.split(' ') + if x.startswith('<')] + mapping[alias] = canonical_email return mapping @@ -54,7 +54,8 @@ def canonicalize_emails(changelog, mapping): def get_reqs_from_files(requirements_files): for requirements_file in requirements_files: if os.path.exists(requirements_file): - return open(requirements_file, 'r').read().split('\n') + with open(requirements_file, 'r') as fil: + return fil.read().split('\n') return [] @@ -236,7 +237,8 @@ def read_versioninfo(project): def write_versioninfo(project, version): """Write a simple file containing the version of the package.""" - open(os.path.join(project, 'versioninfo'), 'w').write("%s\n" % version) + with open(os.path.join(project, 'versioninfo'), 'w') as fil: + fil.write("%s\n" % version) def get_cmdclass(): |