Skip to content
This repository

--user installs work properly with --upgrade #705

Merged
merged 1 commit into from over 1 year ago

2 participants

Marcus Smith Florian Rathgeber
Marcus Smith
Owner

this in in response to pull #704.
this fixes the same problem, but also provides a test.
#704 fixes the issue via the "_permitted" check during uninstallation.
This pull is more direct, in that it doesn't allow the global install to be a conflict in the first place, which it shouldn't be during any --user install.

Marcus Smith qwcode merged commit 74a4e65 into from October 18, 2012
Marcus Smith qwcode closed this October 18, 2012
Florian Rathgeber

Does this patch also fix #354?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 17, 2012
Marcus Smith --user installs work properly with --upgrade 403f8d5
This page is out of date. Refresh to see the latest.
2  docs/news.txt
@@ -14,6 +14,8 @@ Beta and final releases planned for the end of 2012.
14 14
 develop (unreleased)
15 15
 --------------------
16 16
 
  17
+* --user/--upgrade install options now work together; thanks eevee.
  18
+
17 19
 * Added check in ``install --download`` to prevent re-downloading if the target
18 20
   file already exists. Thanks Andrey Bulgakov.
19 21
 
12  pip/req.py
@@ -903,7 +903,9 @@ def locate_files(self):
903 903
                 req_to_install.check_if_exists()
904 904
                 if req_to_install.satisfied_by:
905 905
                     if self.upgrade:
906  
-                        req_to_install.conflicts_with = req_to_install.satisfied_by
  906
+                        #don't uninstall conflict if user install and and conflict is not user install
  907
+                        if not (self.use_user_site and not dist_in_usersite(req_to_install.satisfied_by)):
  908
+                            req_to_install.conflicts_with = req_to_install.satisfied_by
907 909
                         req_to_install.satisfied_by = None
908 910
                     else:
909 911
                         install_needed = False
@@ -955,7 +957,9 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
955 957
                                 req_to_install.url = url.url
956 958
 
957 959
                         if not best_installed:
958  
-                            req_to_install.conflicts_with = req_to_install.satisfied_by
  960
+                            #don't uninstall conflict if user install and conflict is not user install
  961
+                            if not (self.use_user_site and not dist_in_usersite(req_to_install.satisfied_by)):
  962
+                                req_to_install.conflicts_with = req_to_install.satisfied_by
959 963
                             req_to_install.satisfied_by = None
960 964
                     else:
961 965
                         install = False
@@ -1054,7 +1058,9 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
1054 1058
                         req_to_install.check_if_exists()
1055 1059
                         if req_to_install.satisfied_by:
1056 1060
                             if self.upgrade or self.ignore_installed:
1057  
-                                req_to_install.conflicts_with = req_to_install.satisfied_by
  1061
+                                #don't uninstall conflict if user install and and conflict is not user install
  1062
+                                if not (self.use_user_site and not dist_in_usersite(req_to_install.satisfied_by)):
  1063
+                                    req_to_install.conflicts_with = req_to_install.satisfied_by
1058 1064
                                 req_to_install.satisfied_by = None
1059 1065
                             else:
1060 1066
                                 install = False
31  tests/test_user_site.py
@@ -148,6 +148,37 @@ def test_install_user_conflict_in_globalsite(self):
148 148
         assert isdir(initools_folder)
149 149
 
150 150
 
  151
+    def test_upgrade_user_conflict_in_globalsite(self):
  152
+        """
  153
+        Test user install/upgrade with conflict in global site ignores site and installs to usersite
  154
+        """
  155
+
  156
+        # the test framework only supports testing using virtualenvs
  157
+        # the sys.path ordering for virtualenvs with --system-site-packages is this: virtualenv-site, user-site, global-site
  158
+        # this test will use 2 modifications to simulate the user-site/global-site relationship
  159
+        # 1) a monkey patch which will make it appear INITools==0.2 is not in in the virtualenv site
  160
+        #    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..."
  161
+        # 2) adding usersite to PYTHONPATH, so usersite as sys.path precedence over the virtualenv site
  162
+
  163
+        env = reset_env(system_site_packages=True, sitecustomize=patch_dist_in_site_packages)
  164
+        env.environ["PYTHONPATH"] = env.root_path / env.user_site
  165
+
  166
+        result1 = run_pip('install', 'INITools==0.2')
  167
+        result2 = run_pip('install', '--user', '--upgrade', 'INITools')
  168
+
  169
+        #usersite has 0.3.1
  170
+        egg_info_folder = env.user_site / 'INITools-0.3.1-py%s.egg-info' % pyversion
  171
+        initools_folder = env.user_site / 'initools'
  172
+        assert egg_info_folder in result2.files_created, str(result2)
  173
+        assert initools_folder in result2.files_created, str(result2)
  174
+
  175
+        #site still has 0.2 (can't look in result1; have to check)
  176
+        egg_info_folder = env.root_path / env.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion
  177
+        initools_folder = env.root_path / env.site_packages / 'initools'
  178
+        assert isdir(egg_info_folder), result2.stdout
  179
+        assert isdir(initools_folder)
  180
+
  181
+
151 182
     def test_install_user_conflict_in_globalsite_and_usersite(self):
152 183
         """
153 184
         Test user install with conflict in globalsite and usersite ignores global site and updates usersite.
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.