Skip to content

Commit

Permalink
Merge pull request #705 from qwcode/user_upgrade
Browse files Browse the repository at this point in the history
--user installs work properly with --upgrade
  • Loading branch information
qwcode committed Oct 18, 2012
2 parents 40ec94f + 403f8d5 commit 74a4e65
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Beta and final releases planned for the end of 2012.
develop (unreleased)
--------------------

* --user/--upgrade install options now work together; thanks eevee.

* Added check in ``install --download`` to prevent re-downloading if the target
file already exists. Thanks Andrey Bulgakov.

Expand Down
12 changes: 9 additions & 3 deletions pip/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,9 @@ def locate_files(self):
req_to_install.check_if_exists()
if req_to_install.satisfied_by:
if self.upgrade:
req_to_install.conflicts_with = req_to_install.satisfied_by
#don't uninstall conflict if user install and and conflict is not user install
if not (self.use_user_site and not dist_in_usersite(req_to_install.satisfied_by)):
req_to_install.conflicts_with = req_to_install.satisfied_by
req_to_install.satisfied_by = None
else:
install_needed = False
Expand Down Expand Up @@ -955,7 +957,9 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
req_to_install.url = url.url

if not best_installed:
req_to_install.conflicts_with = req_to_install.satisfied_by
#don't uninstall conflict if user install and conflict is not user install
if not (self.use_user_site and not dist_in_usersite(req_to_install.satisfied_by)):
req_to_install.conflicts_with = req_to_install.satisfied_by
req_to_install.satisfied_by = None
else:
install = False
Expand Down Expand Up @@ -1054,7 +1058,9 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
req_to_install.check_if_exists()
if req_to_install.satisfied_by:
if self.upgrade or self.ignore_installed:
req_to_install.conflicts_with = req_to_install.satisfied_by
#don't uninstall conflict if user install and and conflict is not user install
if not (self.use_user_site and not dist_in_usersite(req_to_install.satisfied_by)):
req_to_install.conflicts_with = req_to_install.satisfied_by
req_to_install.satisfied_by = None
else:
install = False
Expand Down
31 changes: 31 additions & 0 deletions tests/test_user_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,37 @@ def test_install_user_conflict_in_globalsite(self):
assert isdir(initools_folder)


def test_upgrade_user_conflict_in_globalsite(self):
"""
Test user install/upgrade with conflict in global site ignores site and installs to usersite
"""

# the test framework only supports testing using virtualenvs
# the sys.path ordering for virtualenvs with --system-site-packages is this: virtualenv-site, user-site, global-site
# this test will use 2 modifications to simulate the user-site/global-site relationship
# 1) a monkey patch which will make it appear INITools==0.2 is not in in the virtualenv site
# if we don't patch this, pip will return an installation error: "Will not install to the usersite because it will lack sys.path precedence..."
# 2) adding usersite to PYTHONPATH, so usersite as sys.path precedence over the virtualenv site

env = reset_env(system_site_packages=True, sitecustomize=patch_dist_in_site_packages)
env.environ["PYTHONPATH"] = env.root_path / env.user_site

result1 = run_pip('install', 'INITools==0.2')
result2 = run_pip('install', '--user', '--upgrade', 'INITools')

#usersite has 0.3.1
egg_info_folder = env.user_site / 'INITools-0.3.1-py%s.egg-info' % pyversion
initools_folder = env.user_site / 'initools'
assert egg_info_folder in result2.files_created, str(result2)
assert initools_folder in result2.files_created, str(result2)

#site still has 0.2 (can't look in result1; have to check)
egg_info_folder = env.root_path / env.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion
initools_folder = env.root_path / env.site_packages / 'initools'
assert isdir(egg_info_folder), result2.stdout
assert isdir(initools_folder)


def test_install_user_conflict_in_globalsite_and_usersite(self):
"""
Test user install with conflict in globalsite and usersite ignores global site and updates usersite.
Expand Down

0 comments on commit 74a4e65

Please sign in to comment.