Commit 41112f5a authored by Jason R. Coombs's avatar Jason R. Coombs

Use io.open for future compatibility and consistency

parent 1c7e97f9
...@@ -163,7 +163,7 @@ class build_py(orig.build_py, Mixin2to3): ...@@ -163,7 +163,7 @@ class build_py(orig.build_py, Mixin2to3):
with io.open(init_py, 'rb') as f: with io.open(init_py, 'rb') as f:
contents = f.read() contents = f.read()
if b'declare_namespace' not in f.read(): if b'declare_namespace' not in contents:
raise distutils.errors.DistutilsError( raise distutils.errors.DistutilsError(
"Namespace package problem: %s is a namespace package, but " "Namespace package problem: %s is a namespace package, but "
"its\n__init__.py does not call declare_namespace()! Please " "its\n__init__.py does not call declare_namespace()! Please "
......
...@@ -3,6 +3,7 @@ from distutils import log ...@@ -3,6 +3,7 @@ from distutils import log
from distutils.errors import DistutilsError, DistutilsOptionError from distutils.errors import DistutilsError, DistutilsOptionError
import os import os
import glob import glob
import io
from pkg_resources import Distribution, PathMetadata, normalize_path from pkg_resources import Distribution, PathMetadata, normalize_path
from setuptools.command.easy_install import easy_install from setuptools.command.easy_install import easy_install
...@@ -163,9 +164,8 @@ class develop(easy_install): ...@@ -163,9 +164,8 @@ class develop(easy_install):
for script_name in self.distribution.scripts or []: for script_name in self.distribution.scripts or []:
script_path = os.path.abspath(convert_path(script_name)) script_path = os.path.abspath(convert_path(script_name))
script_name = os.path.basename(script_path) script_name = os.path.basename(script_path)
f = open(script_path, 'rU') with io.open(script_path) as strm:
script_text = f.read() script_text = strm.read()
f.close()
self.install_script(dist, script_name, script_text, script_path) self.install_script(dist, script_name, script_text, script_path)
def install_wrapper_scripts(self, dist): def install_wrapper_scripts(self, dist):
......
...@@ -10,6 +10,7 @@ import distutils.filelist ...@@ -10,6 +10,7 @@ import distutils.filelist
import os import os
import re import re
import sys import sys
import io
try: try:
from setuptools_svn import svn_utils from setuptools_svn import svn_utils
...@@ -471,10 +472,9 @@ def get_pkg_info_revision(): ...@@ -471,10 +472,9 @@ def get_pkg_info_revision():
# a subversion revision # a subversion revision
# #
if os.path.exists('PKG-INFO'): if os.path.exists('PKG-INFO'):
f = open('PKG-INFO', 'rU') with io.open('PKG-INFO') as f:
for line in f: for line in f:
match = re.match(r"Version:.*-r(\d+)\s*$", line) match = re.match(r"Version:.*-r(\d+)\s*$", line)
if match: if match:
return int(match.group(1)) return int(match.group(1))
f.close()
return 0 return 0
...@@ -3,6 +3,7 @@ from distutils import log ...@@ -3,6 +3,7 @@ from distutils import log
import distutils.command.sdist as orig import distutils.command.sdist as orig
import os import os
import sys import sys
import io
from setuptools.compat import PY3 from setuptools.compat import PY3
from setuptools.utils import cs_path_exists from setuptools.utils import cs_path_exists
...@@ -166,11 +167,8 @@ class sdist(orig.sdist): ...@@ -166,11 +167,8 @@ class sdist(orig.sdist):
if not os.path.isfile(self.manifest): if not os.path.isfile(self.manifest):
return False return False
fp = open(self.manifest, 'rbU') with io.open(self.manifest, 'rb') as fp:
try:
first_line = fp.readline() first_line = fp.readline()
finally:
fp.close()
return (first_line != return (first_line !=
'# file GENERATED by distutils, do NOT edit\n'.encode()) '# file GENERATED by distutils, do NOT edit\n'.encode())
......
...@@ -7,6 +7,7 @@ import sys ...@@ -7,6 +7,7 @@ import sys
import tempfile import tempfile
import unicodedata import unicodedata
import contextlib import contextlib
import io
import pytest import pytest
...@@ -81,6 +82,11 @@ def decompose(path): ...@@ -81,6 +82,11 @@ def decompose(path):
return path return path
def read_all_bytes(filename):
with io.open(filename, 'rb') as fp:
return fp.read()
class TestSdistTest: class TestSdistTest:
def setup_method(self, method): def setup_method(self, method):
...@@ -172,9 +178,7 @@ class TestSdistTest: ...@@ -172,9 +178,7 @@ class TestSdistTest:
mm.filelist.append(filename) mm.filelist.append(filename)
mm.write_manifest() mm.write_manifest()
manifest = open(mm.manifest, 'rbU') contents = read_all_bytes(mm.manifest)
contents = manifest.read()
manifest.close()
# The manifest should be UTF-8 encoded # The manifest should be UTF-8 encoded
u_contents = contents.decode('UTF-8') u_contents = contents.decode('UTF-8')
...@@ -210,9 +214,7 @@ class TestSdistTest: ...@@ -210,9 +214,7 @@ class TestSdistTest:
# Re-write manifest # Re-write manifest
mm.write_manifest() mm.write_manifest()
manifest = open(mm.manifest, 'rbU') contents = read_all_bytes(mm.manifest)
contents = manifest.read()
manifest.close()
# The manifest should be UTF-8 encoded # The manifest should be UTF-8 encoded
contents.decode('UTF-8') contents.decode('UTF-8')
...@@ -248,9 +250,7 @@ class TestSdistTest: ...@@ -248,9 +250,7 @@ class TestSdistTest:
# Re-write manifest # Re-write manifest
mm.write_manifest() mm.write_manifest()
manifest = open(mm.manifest, 'rbU') contents = read_all_bytes(mm.manifest)
contents = manifest.read()
manifest.close()
# The manifest should be UTF-8 encoded # The manifest should be UTF-8 encoded
contents.decode('UTF-8') contents.decode('UTF-8')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment