Skip to content

Commit

Permalink
Merge pull request pypa#2386 from dstufft/distutils-uninstall
Browse files Browse the repository at this point in the history
  fix uninstall for distutils installed packages
  • Loading branch information
dstufft committed Jan 31, 2015
2 parents 311622b + 80fedf7 commit a0b151c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pip/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import shutil
import sys
import tempfile
import warnings
import zipfile

from distutils.util import change_root
Expand All @@ -32,6 +33,7 @@
dist_in_usersite, dist_in_site_packages, egg_link_path, make_path_relative,
call_subprocess, read_text_file, FakeFile, _make_build_dir,
)
from pip.utils.deprecation import RemovedInPip8Warning
from pip.utils.logging import indent_log
from pip.req.req_uninstall import UninstallPathSet
from pip.vcs import vcs
Expand Down Expand Up @@ -559,6 +561,8 @@ def uninstall(self, auto_confirm=False):
paths_to_remove = UninstallPathSet(dist)
develop_egg_link = egg_link_path(dist)
egg_info_exists = dist.egg_info and os.path.exists(dist.egg_info)
# Special case for distutils installed package
distutils_egg_info = getattr(dist._provider, 'path', None)
if develop_egg_link:
# develop egg
with open(develop_egg_link, 'r') as fh:
Expand Down Expand Up @@ -597,6 +601,16 @@ def uninstall(self, auto_confirm=False):
paths_to_remove.add(path + '.py')
paths_to_remove.add(path + '.pyc')

elif distutils_egg_info:
warnings.warn(
"Uninstalling a distutils installed project ({0}) has been "
"deprecated and will be removed in a future version. This is "
"due to the fact that uninstalling a distutils project will "
"only partially uninstall the project.".format(self.name),
RemovedInPip8Warning,
)
paths_to_remove.add(distutils_egg_info)

elif dist.location.endswith('.egg'):
# package installed by easy_install
# We cannot match on dist.egg_name because it can slightly vary
Expand Down
22 changes: 22 additions & 0 deletions tests/functional/test_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ def test_simple_uninstall(script):
assert_all_changes(result, result2, [script.venv / 'build', 'cache'])


def test_simple_uninstall_distutils(script):
"""
Test simple install and uninstall.
"""
script.scratch_path.join("distutils_install").mkdir()
pkg_path = script.scratch_path / 'distutils_install'
pkg_path.join("setup.py").write(textwrap.dedent("""
from distutils.core import setup
setup(
name='distutils-install',
version='0.1',
)
"""))
result = script.run('python', pkg_path / 'setup.py', 'install')
result = script.pip('list')
assert "distutils-install (0.1)" in result.stdout
script.pip('uninstall', 'distutils_install', '-y')
result2 = script.pip('list')
assert "distutils-install (0.1)" not in result2.stdout


@pytest.mark.network
def test_uninstall_with_scripts(script):
"""
Expand Down

0 comments on commit a0b151c

Please sign in to comment.