Commits

Alexandre Conrad  committed 130cd56

centralized clean up code in one place

  • Participants
  • Parent commits ff365ac

Comments (0)

Files changed (5)

File pip/commands/bundle.py

         options.ignore_installed = True
         logger.notify('Putting temporary build files in %s and source/develop files in %s'
                       % (display_path(options.build_dir), display_path(options.src_dir)))
-        bundle_filename = args[0]
-        args = args[1:]
+        self.bundle_filename = args.pop(0)
         requirement_set = super(BundleCommand, self).run(options, args)
-        # FIXME: here it has to do something
-        requirement_set.create_bundle(bundle_filename)
-        logger.notify('Created bundle in %s' % bundle_filename)
         return requirement_set
 
 BundleCommand()

File pip/commands/install.py

                                    requirement_set.successfully_downloaded])
             if downloaded:
                 logger.notify('Successfully downloaded %s' % downloaded)
-        requirement_set.cleanup_files(bundle=self.bundle)
+        elif self.bundle:
+            requirement_set.create_bundle(self.bundle_filename)
+            logger.notify('Created bundle in %s' % self.bundle_filename)
+        # Clean up
+        if not options.no_install:
+            requirement_set.cleanup_files(bundle=self.bundle)
         return requirement_set
 
 InstallCommand()
         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
+
+        # The build dir can always be removed.
+        remove_dir = [self.build_dir]
+
+        # The source dir of a bundle can always be removed.
+        if bundle:
+            remove_dir.append(self.src_dir)
+
+        for dir in remove_dir:
+            if os.path.exists(dir):
+                logger.info('Removing temporary dir %s...' % dir)
+                ## FIXME: should this use pip.util.rmtree?
+                shutil.rmtree(dir)
+
+        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
 
         zip.writestr('pip-manifest.txt', self.bundle_requirements())
         zip.close()
-        # Unlike installation, this will always delete the build directories
-        logger.info('Removing temporary build dir %s and source dir %s'
-                    % (self.build_dir, self.src_dir))
-        for dir in self.build_dir, self.src_dir:
-            if os.path.exists(dir):
-                ## FIXME: should this use pip.util.rmtree?
-                shutil.rmtree(dir)
-
 
     BUNDLE_HEADER = '''\
 # This is a pip bundle file, that contains many source packages

File tests/test_basic.py

     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

File tests/test_bundle.py

 import zipfile
 import textwrap
 from os.path import abspath, join, dirname, pardir
-from test_pip import here, reset_env, run_pip, pyversion, lib_py
-from test_pip import write_file
+from test_pip import here, reset_env, run_pip, pyversion, lib_py, write_file
 
 def test_create_bundle():
     """