summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Conrad <alexandre.conrad@gmail.com>2010-04-17 18:35:22 +0200
committerAlexandre Conrad <alexandre.conrad@gmail.com>2010-04-17 18:35:22 +0200
commitda1870b2aaa6131ce8bf2da013aece3c9da3a233 (patch)
tree1a0845731d65f52069a965d1e2b9fb0a78fc8567
parentd4ab186a8d263ef22225996946529359637c7553 (diff)
parent627c3e7242c0ceaa2ed892d990dbf174e046b5a9 (diff)
downloadpip-da1870b2aaa6131ce8bf2da013aece3c9da3a233.tar.gz
merge
-rw-r--r--docs/news.txt1
-rw-r--r--pip/commands/install.py3
-rw-r--r--pip/req.py26
-rw-r--r--tests/test_basic.py13
4 files changed, 38 insertions, 5 deletions
diff --git a/docs/news.txt b/docs/news.txt
index 6d9ee865a..9ed941f77 100644
--- a/docs/news.txt
+++ b/docs/news.txt
@@ -41,6 +41,7 @@ News for pip
download and installation into two steps. Thanks Simon Cross.
* Fix uninstalling from requirements file containing -f, -i, or
--extra-index-url.
+* Leftover build directories are now removed. Thanks Alexandre Conrad.
0.6.3
-----
diff --git a/pip/commands/install.py b/pip/commands/install.py
index 7e688edcf..56b63e755 100644
--- a/pip/commands/install.py
+++ b/pip/commands/install.py
@@ -158,7 +158,7 @@ class InstallCommand(Command):
for req in parse_requirements(filename, finder=finder, options=options):
requirement_set.add_requirement(req)
if not options.no_download:
- requirement_set.install_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
+ requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
else:
requirement_set.locate_files()
if not options.no_install and not self.bundle:
@@ -172,6 +172,7 @@ class InstallCommand(Command):
requirement_set.successfully_downloaded])
if downloaded:
logger.notify('Successfully downloaded %s' % downloaded)
+ requirement_set.cleanup_files(bundle=self.bundle)
return requirement_set
InstallCommand()
diff --git a/pip/req.py b/pip/req.py
index 47c0a68c4..3970a91ff 100644
--- a/pip/req.py
+++ b/pip/req.py
@@ -716,6 +716,7 @@ class RequirementSet(object):
self.ignore_dependencies = ignore_dependencies
self.successfully_downloaded = []
self.successfully_installed = []
+ self.reqs_to_cleanup = []
def __str__(self):
reqs = [req for req in self.requirements.values()
@@ -806,7 +807,8 @@ class RequirementSet(object):
'an equivalent install with --no-install?)'
% (req_to_install, req_to_install.source_dir))
- def install_files(self, finder, force_root_egg_info=False, bundle=False):
+ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
+ """Prepare process. Create temp directories, download and/or unpack files."""
unnamed = list(self.unnamed_requirements)
reqs = self.requirements.values()
while reqs or unnamed:
@@ -835,8 +837,8 @@ class RequirementSet(object):
else:
logger.notify('Downloading/unpacking %s' % req_to_install)
logger.indent += 2
- is_bundle = False
try:
+ is_bundle = False
if req_to_install.editable:
if req_to_install.source_dir is None:
location = req_to_install.build_location(self.src_dir)
@@ -927,7 +929,7 @@ class RequirementSet(object):
if req_to_install.name not in self.requirements:
self.requirements[req_to_install.name] = req_to_install
else:
- req_to_install.remove_temporary_source()
+ self.reqs_to_cleanup.append(req_to_install)
if install:
self.successfully_downloaded.append(req_to_install)
if bundle and (req_to_install.url and req_to_install.url.startswith('file:///')):
@@ -935,6 +937,24 @@ class RequirementSet(object):
finally:
logger.indent -= 2
+ def cleanup_files(self, bundle=False):
+ """Clean up files, remove builds."""
+ logger.notify('Cleaning up...')
+ logger.indent += 2
+ for req in self.reqs_to_cleanup:
+ req.remove_temporary_source()
+ try:
+ # create_bundle() is responsible for removing build_dir and
+ # src_dir after compression. create_bundle() is ran afterwards.
+ if not bundle:
+ for directory in self.build_dir,:
+ if not os.path.exists(directory):
+ continue
+ logger.info('Removing %s...' % directory)
+ os.rmdir(directory)
+ finally:
+ logger.indent -= 2
+
def copy_to_builddir(self, req_to_install):
target_dir = req_to_install.editable and self.src_dir or self.build_dir
logger.info("Copying %s to %s" %(req_to_install.name, target_dir))
diff --git a/tests/test_basic.py b/tests/test_basic.py
index 8e350a768..291eaec33 100644
--- a/tests/test_basic.py
+++ b/tests/test_basic.py
@@ -1,4 +1,4 @@
-from os.path import abspath, join, dirname, curdir, pardir
+from os.path import abspath, exists, join, dirname, curdir, pardir
from test_pip import here, reset_env, run_pip, pyversion, lib_py, mkdir
def test_correct_pip_version():
@@ -253,3 +253,14 @@ def test_install_pardir():
result = run_pip('install', pardir, cwd=run_from, expect_error=False)
assert (lib_py + 'site-packages/fspkg') in result.files_created, str(result.stdout)
assert (lib_py + 'site-packages/FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)
+
+def test_cleanup():
+ """
+ Test clean up of build directory after an install.
+
+ """
+ reset_env()
+ # FIXME: We may want to test more scenarios
+ result = run_pip('install', 'INITools==dev', expect_error=False)
+ build = join(here, "test-scratch", "build")
+ assert not exists(build), "build dir still exists: %s" % build