mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
support for uninstalling easy_installed packages
This commit is contained in:
parent
721fcac534
commit
7a229bf541
45
pip.py
Normal file → Executable file
45
pip.py
Normal file → Executable file
|
@ -1534,15 +1534,44 @@ execfile(__file__)
|
|||
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)
|
||||
remove_paths = []
|
||||
|
||||
pip_egg_info_path = os.path.join(dist.location, dist.egg_name()) + '.egg-info'
|
||||
easy_install_egg = dist.egg_name() + '.egg'
|
||||
|
||||
if os.path.exists(pip_egg_info_path):
|
||||
# package installed by pip
|
||||
remove_paths.append(pip_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)
|
||||
|
||||
elif dist.location.endswith(easy_install_egg):
|
||||
# package installed by easy_install
|
||||
remove_paths.append(dist.location)
|
||||
easy_install_pth = os.path.join(os.path.dirname(dist.location), 'easy-install.pth')
|
||||
if os.path.isfile(easy_install_pth):
|
||||
logger.notify('Removing %s from %s' % (easy_install_egg, easy_install_pth))
|
||||
fh = open(easy_install_pth, 'r')
|
||||
easy_install_lines = fh.readlines()
|
||||
fh.close()
|
||||
try:
|
||||
easy_install_lines.remove('./' + easy_install_egg + '\n')
|
||||
except ValueError:
|
||||
pass
|
||||
fh = open(easy_install_pth, 'w')
|
||||
fh.writelines(easy_install_lines)
|
||||
fh.close()
|
||||
|
||||
for path in remove_paths:
|
||||
shutil.rmtree(path)
|
||||
logger.notify('Deleting path %s' % path)
|
||||
# FIXME maybe we should ask for confirmation here?
|
||||
if os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
elif os.path.isfile(path):
|
||||
os.remove(path)
|
||||
|
||||
def install(self, install_options):
|
||||
if self.editable:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Basic setup::
|
||||
|
||||
>>> from __main__ import here, reset_env, run_pip, pyversion, lib_py
|
||||
>>> from __main__ import here, reset_env, run_pip, pyversion, lib_py, get_env
|
||||
>>> try:
|
||||
... s = set()
|
||||
... except NameError:
|
||||
|
@ -12,6 +12,20 @@ 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()))
|
||||
>>> diff = set(result.files_before.keys()).symmetric_difference(set(result2.files_after.keys()))
|
||||
>>> try: diff.remove('build')
|
||||
... except KeyError: pass
|
||||
>>> assert(not len(diff)), diff
|
||||
|
||||
Uninstall an easy_installed package::
|
||||
|
||||
>>> reset_env()
|
||||
>>> env = get_env()
|
||||
>>> result = env.run('%s/bin/easy_install' % env.base_path, 'INITools')
|
||||
>>> easy_install_pth = lib_py + 'site-packages/easy-install.pth'
|
||||
>>> assert('INITools' in result.files_updated[easy_install_pth].bytes), result.files_after[easy-install_pth].bytes
|
||||
>>> result2 = run_pip('uninstall', 'INITools', expect_error=True)
|
||||
>>> diff = set(result.files_before.keys()).symmetric_difference(set(result2.files_after.keys()))
|
||||
>>> try: diff.remove('build')
|
||||
... except KeyError: pass
|
||||
>>> assert(not len(diff)), diff
|
||||
|
|
Loading…
Reference in a new issue