From afc24647726a93c788a375a0750e1cdd7fe6e883 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sat, 19 Mar 2011 20:57:37 +0100 Subject: [PATCH] Make use of our own rmtree to work around an issue on Windows with readonly files. --- pip/util.py | 4 ++-- tests/path.py | 3 ++- tests/test_all_pip.py | 10 ++++++---- tests/test_pip.py | 9 +++++---- tests/test_uninstall.py | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pip/util.py b/pip/util.py index 2e98fdede..7b5530383 100644 --- a/pip/util.py +++ b/pip/util.py @@ -24,8 +24,8 @@ __all__ = ['rmtree', 'display_path', 'backup_dir', 'cache_download', 'unpack_file'] -def rmtree(dir): - shutil.rmtree(dir, ignore_errors=True, +def rmtree(dir, ignore_errors=True): + shutil.rmtree(dir, ignore_errors=ignore_errors, onerror=rmtree_errorhandler) diff --git a/tests/path.py b/tests/path.py index 7b94de1e9..d564ac607 100644 --- a/tests/path.py +++ b/tests/path.py @@ -13,6 +13,7 @@ else: _base = os.path.supports_unicode_filenames and unicode or str +from pip.util import rmtree class Path(_base): """ Models a path in an object oriented way. """ @@ -180,7 +181,7 @@ class Path(_base): def rmtree(self, noerrors=True): """ Removes a directory tree. Ignores errors by default. """ - return shutil.rmtree(self, ignore_errors=noerrors) + return rmtree(self, ignore_errors=noerrors) def copy(self, to): shutil.copy(self, to) diff --git a/tests/test_all_pip.py b/tests/test_all_pip.py index 1b8f8fc67..f2f1ea16d 100644 --- a/tests/test_all_pip.py +++ b/tests/test_all_pip.py @@ -1,11 +1,13 @@ +import os import re import sys -import os import subprocess import shutil -from pip.backwardcompat import urllib from os.path import dirname, abspath +from pip.backwardcompat import urllib +from pip.util import rmtree + src_folder = dirname(dirname(abspath(__file__))) @@ -76,12 +78,12 @@ def _test_packages(output, pending_fn): print('Installation of %s succeeded' % package) add_package(os.path.join(output, 'success.txt'), package) pop_last_item(pending_fn, package) - shutil.rmtree(dest_dir) + rmtree(dest_dir) def create_venv(dest_dir): if os.path.exists(dest_dir): - shutil.rmtree(dest_dir) + rmtree(dest_dir) print('Creating virtualenv in %s' % dest_dir) code = subprocess.check_call(['virtualenv', '--no-site-packages', dest_dir]) assert not code, "virtualenv failed" diff --git a/tests/test_pip.py b/tests/test_pip.py index 255815d45..7dfd90694 100644 --- a/tests/test_pip.py +++ b/tests/test_pip.py @@ -8,6 +8,7 @@ import atexit import textwrap from scripttest import TestFileEnvironment from tests.path import Path, curdir, u +from pip.util import rmtree pyversion = sys.version[:3] @@ -96,7 +97,7 @@ def install_setuptools(env): shutil.copy2(f, tempdir) return env.run(os.path.join(tempdir, 'easy_install'), version) finally: - shutil.rmtree(tempdir) + rmtree(tempdir) env = None @@ -129,7 +130,7 @@ class TestFailure(AssertionError): def _cleanup(): global env del env - shutil.rmtree(download_cache, ignore_errors=True) + rmtree(download_cache, ignore_errors=True) atexit.register(_cleanup) @@ -354,7 +355,7 @@ class TestPipEnvironment(TestFileEnvironment): return TestPipResult(super(TestPipEnvironment, self).run(cwd=cwd, *args, **kw), verbose=self.verbose) def __del__(self): - shutil.rmtree(str(self.root_path), ignore_errors=True) + rmtree(str(self.root_path), ignore_errors=True) def _use_cached_pypi_server(self): site_packages = self.root_path / self.site_packages @@ -411,7 +412,7 @@ class FastTestPipEnvironment(TestPipEnvironment): self.environ['PATH'] = Path.pathsep.join((self.bin_path, self.environ['PATH'])) if self.root_path.exists: - shutil.rmtree(self.root_path) + rmtree(self.root_path) if self.backup_path.exists: shutil.copytree(self.backup_path, self.root_path, True) else: diff --git a/tests/test_uninstall.py b/tests/test_uninstall.py index 0f995d166..8596368ed 100644 --- a/tests/test_uninstall.py +++ b/tests/test_uninstall.py @@ -99,7 +99,7 @@ def test_uninstall_editable_with_source_outside_venv(): tmpdir = join(temp, 'virtualenv') _test_uninstall_editable_with_source_outside_venv(tmpdir) finally: - shutil.rmtree(temp) + rmtree(temp) def _test_uninstall_editable_with_source_outside_venv(tmpdir):