summaryrefslogtreecommitdiff
path: root/pip/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'pip/util.py')
-rw-r--r--pip/util.py47
1 files changed, 37 insertions, 10 deletions
diff --git a/pip/util.py b/pip/util.py
index 619f06531..833a7adcc 100644
--- a/pip/util.py
+++ b/pip/util.py
@@ -10,7 +10,7 @@ import tarfile
import subprocess
from pip.exceptions import InstallationError, BadCommand
from pip.backwardcompat import WindowsError, string_types, raw_input, console_to_str, user_site
-from pip.locations import site_packages, running_under_virtualenv
+from pip.locations import site_packages, running_under_virtualenv, virtualenv_no_global
from pip.log import logger
__all__ = ['rmtree', 'display_path', 'backup_dir',
@@ -303,6 +303,12 @@ def dist_in_usersite(dist):
else:
return False
+def dist_in_site_packages(dist):
+ """
+ Return True if given Distribution is installed in distutils.sysconfig.get_python_lib().
+ """
+ return normalize_path(dist_location(dist)).startswith(normalize_path(site_packages))
+
def get_installed_distributions(local_only=True, skip=('setuptools', 'pip', 'python')):
"""
@@ -325,16 +331,37 @@ def get_installed_distributions(local_only=True, skip=('setuptools', 'pip', 'pyt
def egg_link_path(dist):
"""
- Return the path where we'd expect to find a .egg-link file for
- this distribution. (There doesn't seem to be any metadata in the
- Distribution object for a develop egg that points back to its
- .egg-link and easy-install.pth files).
+ Return the path for the .egg-link file if it exists, otherwise, None.
+
+ There's 3 scenarios:
+ 1) not in a virtualenv
+ try to find in site.USER_SITE, then site_packages
+ 2) in a no-global virtualenv
+ try to find in site_packages
+ 3) in a yes-global virtualenv
+ try to find in site_packages, then site.USER_SITE (don't look in global location)
+
+ For #1 and #3, there could be odd cases, where there's an egg-link in 2 locations.
+ This method will just return the first one found.
+ """
- This won't find a globally-installed develop egg if we're in a
- virtualenv.
+ sites=[]
+ if running_under_virtualenv():
+ if virtualenv_no_global():
+ sites.append(site_packages)
+ else:
+ sites.append(site_packages)
+ if user_site:
+ sites.append(user_site)
+ else:
+ if user_site:
+ sites.append(user_site)
+ sites.append(site_packages)
- """
- return os.path.join(site_packages, dist.project_name) + '.egg-link'
+ for site in sites:
+ egglink = os.path.join(site, dist.project_name) + '.egg-link'
+ if os.path.isfile(egglink):
+ return egglink
def dist_location(dist):
@@ -346,7 +373,7 @@ def dist_location(dist):
"""
egg_link = egg_link_path(dist)
- if os.path.exists(egg_link):
+ if egg_link:
return egg_link
return dist.location