Blame SOURCES/remove-existing-dist-only-if-path-conflicts.patch

372d73
diff --git a/pip/req/req_install.py b/pip/req/req_install.py
372d73
index 6911fba..8524932 100644
372d73
--- a/pip/req/req_install.py
372d73
+++ b/pip/req/req_install.py
372d73
@@ -34,7 +34,7 @@ from pip.locations import (
372d73
 )
372d73
 from pip.utils import (
372d73
     display_path, rmtree, ask_path_exists, backup_dir, is_installable_dir,
372d73
-    dist_in_usersite, dist_in_site_packages, egg_link_path,
372d73
+    dist_in_usersite, dist_in_site_packages, dist_in_install_path, egg_link_path,
372d73
     call_subprocess, read_text_file, FakeFile, _make_build_dir, ensure_dir,
372d73
     get_installed_version, normalize_path, dist_is_local,
372d73
 )
372d73
@@ -1049,7 +1049,7 @@ class InstallRequirement(object):
372d73
                         "lack sys.path precedence to %s in %s" %
372d73
                         (existing_dist.project_name, existing_dist.location)
372d73
                     )
372d73
-            else:
372d73
+            elif dist_in_install_path(existing_dist):
372d73
                 self.conflicts_with = existing_dist
372d73
         return True
372d73
 
372d73
diff --git a/pip/req/req_set.py b/pip/req/req_set.py
372d73
index 76aec06..b93304a 100644
372d73
--- a/pip/req/req_set.py
372d73
+++ b/pip/req/req_set.py
372d73
@@ -18,7 +18,8 @@ from pip.exceptions import (InstallationError, BestVersionAlreadyInstalled,
372d73
                             UnsupportedPythonVersion)
372d73
 from pip.req.req_install import InstallRequirement
372d73
 from pip.utils import (
372d73
-    display_path, dist_in_usersite, ensure_dir, normalize_path)
372d73
+    display_path, dist_in_usersite, dist_in_install_path, ensure_dir,
372d73
+    normalize_path)
372d73
 from pip.utils.hashes import MissingHashes
372d73
 from pip.utils.logging import indent_log
372d73
 from pip.utils.packaging import check_dist_requires_python
372d73
@@ -437,10 +438,12 @@ class RequirementSet(object):
372d73
 
372d73
                 if not best_installed:
372d73
                     # don't uninstall conflict if user install and
372d73
-                    # conflict is not user install
372d73
+                    # conflict is not user install or conflict lives
372d73
+                    # in a different path (/usr/lib vs /usr/local/lib/)
372d73
                     if not (self.use_user_site and not
372d73
-                            dist_in_usersite(req_to_install.satisfied_by)):
372d73
-                        req_to_install.conflicts_with = \
372d73
+                            dist_in_usersite(req_to_install.satisfied_by) or not
372d73
+                            dist_in_install_path(req_to_install.satisfied_by)):
372d73
+                        req_to_install.conflicts_with = \
372d73
                             req_to_install.satisfied_by
372d73
                     req_to_install.satisfied_by = None
372d73
 
372d73
@@ -644,10 +647,12 @@ class RequirementSet(object):
372d73
                 if req_to_install.satisfied_by:
372d73
                     if self.upgrade or self.ignore_installed:
372d73
                         # don't uninstall conflict if user install and
372d73
-                        # conflict is not user install
372d73
+                        # conflict is not user install or conflict lives
372d73
+                        # in a different path (/usr/lib vs /usr/local/lib/)
372d73
                         if not (self.use_user_site and not
372d73
                                 dist_in_usersite(
372d73
-                                    req_to_install.satisfied_by)):
372d73
+                                    req_to_install.satisfied_by) or not
372d73
+                                dist_in_install_path(req_to_install.satisfied_by)):
372d73
                             req_to_install.conflicts_with = \
372d73
                                 req_to_install.satisfied_by
372d73
                         req_to_install.satisfied_by = None
372d73
diff --git a/pip/utils/__init__.py b/pip/utils/__init__.py
372d73
index 815bd33..0ed59f7 100644
372d73
--- a/pip/utils/__init__.py
372d73
+++ b/pip/utils/__init__.py
372d73
@@ -22,7 +22,7 @@ from pip.exceptions import InstallationError
372d73
 from pip.compat import console_to_str, expanduser, stdlib_pkgs
372d73
 from pip.locations import (
372d73
     site_packages, user_site, running_under_virtualenv, virtualenv_no_global,
372d73
-    write_delete_marker_file,
372d73
+    write_delete_marker_file, distutils_scheme,
372d73
 )
372d73
 from pip._vendor import pkg_resources
372d73
 from pip._vendor.six.moves import input
372d73
@@ -315,6 +315,16 @@ def dist_in_site_packages(dist):
372d73
     ).startswith(normalize_path(site_packages))
372d73
 
372d73
 
372d73
+def dist_in_install_path(dist):
372d73
+    """
372d73
+    Return True if given Distribution is installed in
372d73
+    path matching distutils_scheme layout.
372d73
+    """
372d73
+    norm_path = normalize_path(dist_location(dist))
372d73
+    return norm_path.startswith(normalize_path(
372d73
+        distutils_scheme("")['purelib'].split('python')[0]))
372d73
+
372d73
+
372d73
 def dist_is_editable(dist):
372d73
     """Is distribution an editable install?"""
372d73
     for path_item in sys.path: