提交 dafaabe8 编写于 作者: P Paul Nasrat

Merge pull request #567 from qwcode/userscheme_pt3

--user fixes pt 3  Issue #493
......@@ -5,7 +5,7 @@ import shutil
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 @@ class InstallCommand(Command):
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
......
"""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?
......
......@@ -83,3 +83,14 @@ class Tests_UserSite:
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册