summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2017-10-17 02:31:14 -0700
committerOmer Katz <omer.drow@gmail.com>2017-10-17 12:31:14 +0300
commit9062ecac1e7666e6218ad18c72fb036edf2ac8fa (patch)
treeda99bc8cb088b1a7f350b6cb70c525439853d446
parentae05e3172b3787c56c122ef619b1074d7ea1ecd5 (diff)
downloadpy-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.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/setup.py b/setup.py
index 2899f1a..94dcece 100644
--- a/setup.py
+++ b/setup.py
@@ -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'