Permalink
Browse files

don't allow --user installs in no-global virtualenvs

  • Loading branch information...
1 parent 39bbf2d commit 2e1959abfb97e161cf0d8b3a373a91e7c0cb358c @qwcode committed Jun 6, 2012
Showing with 25 additions and 1 deletion.
  1. +3 −1 pip/commands/install.py
  2. +11 −0 pip/locations.py
  3. +11 −0 tests/test_user_site.py
View
@@ -5,7 +5,7 @@
from pip.req import InstallRequirement, RequirementSet
from pip.req import parse_requirements
from pip.log import logger
-from pip.locations import build_prefix, src_prefix
+from pip.locations import build_prefix, src_prefix, virtualenv_no_global
from pip.basecommand import Command
from pip.index import PackageFinder
from pip.exceptions import InstallationError, CommandError
@@ -190,6 +190,8 @@ def run(self, options, args):
options.src_dir = os.path.abspath(options.src_dir)
install_options = options.install_options or []
if options.use_user_site:
+ if virtualenv_no_global():
+ raise InstallationError("Can not perform a '--user' install. User site-packages are not visible in this virtualenv.")
install_options.append('--user')
if options.target_dir:
options.ignore_installed = True
View
@@ -1,6 +1,7 @@
"""Locations where we look for configs, install stuff, etc"""
import sys
+import site
import os
import tempfile
from pip.backwardcompat import get_python_lib
@@ -13,6 +14,16 @@ def running_under_virtualenv():
"""
return hasattr(sys, 'real_prefix')
+def virtualenv_no_global():
+ """
+ Return True if in a venv and no system site packages.
+ """
+ #this mirrors the logic in virtualenv.py for locating the no-global-site-packages.txt file
+ site_mod_dir = os.path.dirname(os.path.abspath(site.__file__))
+ no_global_file = os.path.join(site_mod_dir,'no-global-site-packages.txt')
+ if running_under_virtualenv() and os.path.isfile(no_global_file):
+ return True
+
if running_under_virtualenv():
## FIXME: is build/ a good name?
View
@@ -83,3 +83,14 @@ def test_install_curdir_usersite(self):
assert fspkg_folder in result.files_created, str(result.stdout)
assert egg_info_folder in result.files_created, str(result)
+
+
+ def test_install_user_venv_nositepkgs_fails(self):
+ """
+ user install in virtualenv (with no system packages) fails with message
+ """
+ env = reset_env()
+ run_from = abspath(join(here, 'packages', 'FSPkg'))
+ result = run_pip('install', '--user', curdir, cwd=run_from, expect_error=True)
+ assert "Can not perform a '--user' install. User site-packages are not visible in this virtualenv." in result.stdout
+

0 comments on commit 2e1959a

Please sign in to comment.