diff options
Diffstat (limited to 'setuptools/tests/environment.py')
-rw-r--r-- | setuptools/tests/environment.py | 65 |
1 files changed, 9 insertions, 56 deletions
diff --git a/setuptools/tests/environment.py b/setuptools/tests/environment.py index 476d280a..c8d0e669 100644 --- a/setuptools/tests/environment.py +++ b/setuptools/tests/environment.py @@ -10,57 +10,6 @@ import unicodedata from subprocess import Popen as _Popen, PIPE as _PIPE -def _extract(self, member, path=None, pwd=None): - """for zipfile py2.5 borrowed from cpython""" - if not isinstance(member, zipfile.ZipInfo): - member = self.getinfo(member) - - if path is None: - path = os.getcwd() - - return _extract_member(self, member, path, pwd) - - -def _extract_from_zip(self, name, dest_path): - dest_file = open(dest_path, 'wb') - try: - dest_file.write(self.read(name)) - finally: - dest_file.close() - - -def _extract_member(self, member, targetpath, pwd): - """for zipfile py2.5 borrowed from cpython""" - # build the destination pathname, replacing - # forward slashes to platform specific separators. - # Strip trailing path separator, unless it represents the root. - if (targetpath[-1:] in (os.path.sep, os.path.altsep) - and len(os.path.splitdrive(targetpath)[1]) > 1): - targetpath = targetpath[:-1] - - # don't include leading "/" from file name if present - if member.filename[0] == '/': - targetpath = os.path.join(targetpath, member.filename[1:]) - else: - targetpath = os.path.join(targetpath, member.filename) - - targetpath = os.path.normpath(targetpath) - - # Create all upper directories if necessary. - upperdirs = os.path.dirname(targetpath) - if upperdirs and not os.path.exists(upperdirs): - os.makedirs(upperdirs) - - if member.filename[-1] == '/': - if not os.path.isdir(targetpath): - os.mkdir(targetpath) - return targetpath - - _extract_from_zip(self, member.filename, targetpath) - - return targetpath - - def _remove_dir(target): #on windows this seems to a problem @@ -92,7 +41,7 @@ class ZippedEnvironment(unittest.TestCase): try: zip_file = zipfile.ZipFile(self.datafile) for files in zip_file.namelist(): - _extract(zip_file, files, self.temp_dir) + zip_file.extract(files, self.temp_dir) finally: if zip_file: zip_file.close() @@ -147,10 +96,13 @@ def run_setup_py(cmd, pypath=None, path=None, cmd = [sys.executable, "setup.py"] + list(cmd) - #regarding the shell argument, see: http://bugs.python.org/issue8557 + # http://bugs.python.org/issue8557 + shell = sys.platform == 'win32' + try: - proc = _Popen(cmd, stdout=_PIPE, stderr=_PIPE, - shell=(sys.platform == 'win32'), env=env) + proc = _Popen( + cmd, stdout=_PIPE, stderr=_PIPE, shell=shell, env=env, + ) data = proc.communicate()[data_stream] except OSError: @@ -158,7 +110,8 @@ def run_setup_py(cmd, pypath=None, path=None, #decode the console string if needed if hasattr(data, "decode"): - data = data.decode() # should use the preffered encoding + # use the default encoding + data = data.decode() data = unicodedata.normalize('NFC', data) #communciate calls wait() |