mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
centralized clean up code in one place
This commit is contained in:
parent
da1870b2aa
commit
aaccedf26a
|
@ -24,12 +24,8 @@ class BundleCommand(InstallCommand):
|
|||
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()
|
||||
|
|
|
@ -172,6 +172,11 @@ class InstallCommand(Command):
|
|||
requirement_set.successfully_downloaded])
|
||||
if downloaded:
|
||||
logger.notify('Successfully downloaded %s' % downloaded)
|
||||
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
|
||||
|
||||
|
|
32
pip/req.py
32
pip/req.py
|
@ -943,16 +943,20 @@ class RequirementSet(object):
|
|||
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:
|
||||
|
||||
# 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):
|
||||
|
@ -1295,14 +1299,6 @@ class RequirementSet(object):
|
|||
|
||||
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
|
||||
|
|
|
@ -253,14 +253,3 @@ 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
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
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():
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue