diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2017-10-17 02:31:14 -0700 |
---|---|---|
committer | Omer Katz <omer.drow@gmail.com> | 2017-10-17 12:31:14 +0300 |
commit | 9062ecac1e7666e6218ad18c72fb036edf2ac8fa (patch) | |
tree | da99bc8cb088b1a7f350b6cb70c525439853d446 | |
parent | ae05e3172b3787c56c122ef619b1074d7ea1ecd5 (diff) | |
download | py-amqp-9062ecac1e7666e6218ad18c72fb036edf2ac8fa.tar.gz |
Fix ResourceWarning in setup.py (#170)
When Python is executed with warnings enabled (e.g. python3 -Wall
setup.py ...), ResourceWarnings appear on stderr. This occurs because
files are not explicitly closed. Always use a context manager to close
files when finished.
-rw-r--r-- | setup.py | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -1,10 +1,10 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import io import os import re import sys -import codecs import setuptools import setuptools.command.test @@ -71,8 +71,8 @@ def strip_comments(l): def reqs(f): - req = filter(None, [strip_comments(l) for l in open( - os.path.join(os.getcwd(), 'requirements', f)).readlines()]) + with open(os.path.join(os.getcwd(), 'requirements', f)) as fp: + req = filter(None, [strip_comments(l) for l in fp.readlines()]) # filter returns filter object(iterator) in Python 3, # but a list in Python 2.7, so make sure it returns a list. return list(req) @@ -81,7 +81,8 @@ def reqs(f): # -*- Long Description -*- if os.path.exists('README.rst'): - long_description = codecs.open('README.rst', 'r', 'utf-8').read() + with io.open('README.rst', encoding='utf-8') as fp: + long_description = fp.read() else: long_description = 'See http://pypi.python.org/pypi/amqp' |