mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
experimental uninstall support
This commit is contained in:
parent
5524a263e5
commit
721fcac534
36
pip.py
36
pip.py
|
@ -427,6 +427,25 @@ class InstallCommand(Command):
|
|||
|
||||
InstallCommand()
|
||||
|
||||
class UninstallCommand(Command):
|
||||
name = 'uninstall'
|
||||
usage = '%prog [OPTIONS] PACKAGE_NAMES ...'
|
||||
summary = 'Uninstall packages'
|
||||
|
||||
def __init__(self):
|
||||
super(UninstallCommand, self).__init__()
|
||||
|
||||
def run(self, options, args):
|
||||
requirement_set = RequirementSet(
|
||||
build_dir=base_prefix,
|
||||
src_dir=base_src_prefix)
|
||||
for name in args:
|
||||
requirement_set.add_requirement(
|
||||
InstallRequirement.from_line(name))
|
||||
requirement_set.uninstall()
|
||||
|
||||
UninstallCommand()
|
||||
|
||||
class BundleCommand(InstallCommand):
|
||||
name = 'bundle'
|
||||
usage = '%prog [OPTIONS] BUNDLE_NAME.pybundle PACKAGE_NAMES...'
|
||||
|
@ -1512,6 +1531,19 @@ execfile(__file__)
|
|||
'Unexpected version control type (in %s): %s'
|
||||
% (self.url, vc_type))
|
||||
|
||||
def uninstall(self):
|
||||
assert self.check_if_exists(), "Cannot uninstall requirement %s, not installed" % (self.name,)
|
||||
dist = self.satisfied_by
|
||||
egg_info_path = os.path.join(dist.location, dist.egg_name()) + '.egg-info'
|
||||
remove_paths = [egg_info_path]
|
||||
if dist.has_metadata('top_level.txt'):
|
||||
for top_level_pkg in dist.get_metadata('top_level.txt').splitlines():
|
||||
path = os.path.join(dist.location, top_level_pkg)
|
||||
if os.path.exists(path):
|
||||
remove_paths.append(path)
|
||||
for path in remove_paths:
|
||||
shutil.rmtree(path)
|
||||
|
||||
def install(self, install_options):
|
||||
if self.editable:
|
||||
self.install_editable()
|
||||
|
@ -1731,6 +1763,10 @@ class RequirementSet(object):
|
|||
return self.requirements[self.requirement_aliases[name]]
|
||||
raise KeyError("No project with the name %r" % project_name)
|
||||
|
||||
def uninstall(self):
|
||||
for req in self.requirements.values():
|
||||
req.uninstall()
|
||||
|
||||
def install_files(self, finder, force_root_egg_info=False):
|
||||
unnamed = list(self.unnamed_requirements)
|
||||
reqs = self.requirements.values()
|
||||
|
|
|
@ -56,7 +56,7 @@ def main():
|
|||
options, args = parser.parse_args()
|
||||
reset_env()
|
||||
if not args:
|
||||
args = ['test_basic.txt', 'test_requirements.txt', 'test_freeze.txt', 'test_proxy.txt']
|
||||
args = ['test_basic.txt', 'test_requirements.txt', 'test_freeze.txt', 'test_proxy.txt', 'test_uninstall.txt']
|
||||
optionflags = doctest.ELLIPSIS
|
||||
if options.first:
|
||||
optionflags |= doctest.REPORT_ONLY_FIRST_FAILURE
|
||||
|
|
17
tests/test_uninstall.txt
Normal file
17
tests/test_uninstall.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
Basic setup::
|
||||
|
||||
>>> from __main__ import here, reset_env, run_pip, pyversion, lib_py
|
||||
>>> try:
|
||||
... s = set()
|
||||
... except NameError:
|
||||
... from sets import Set as set
|
||||
>>> reset_env()
|
||||
|
||||
Simple install and uninstall::
|
||||
|
||||
>>> result = run_pip('install', 'INITools==0.2', expect_error=True)
|
||||
>>> assert (lib_py + 'site-packages/initools') in result.files_created, sorted(result.files_created.keys())
|
||||
>>> result2 = run_pip('uninstall', 'INITools', expect_error=True)
|
||||
>>> diff = set(result.files_before.keys() + ['build']).symmetric_difference(set(result2.files_after.keys()))
|
||||
>>> assert(not len(diff)), diff
|
||||
|
Loading…
Reference in a new issue