Make sure --user and --prefix install flags conflict

This commit is contained in:
Domen Kožar 2015-11-19 16:32:02 +01:00
parent e14a66f1b9
commit 7270d272f4
3 changed files with 43 additions and 4 deletions

View File

@ -215,6 +215,11 @@ class InstallCommand(RequirementCommand):
options.src_dir = os.path.abspath(options.src_dir)
install_options = options.install_options or []
if options.use_user_site:
if options.prefix_path:
raise CommandError(
"Can not combine '--user' and '--prefix' as they imply "
"different installation locations"
)
if virtualenv_no_global():
raise InstallationError(
"Can not perform a '--user' install. User site-packages "

View File

@ -184,11 +184,9 @@ def distutils_scheme(dist_name, user=False, home=None, root=None,
# NOTE: setting user or home has the side-effect of creating the home dir
# or user base for installations during finalize_options()
# ideally, we'd prefer a scheme class that has no side-effects.
assert not (user and prefix), "Got user and prefix {}".format(user, prefix)
i.user = user or i.user
if user:
i.prefix = ""
else:
i.prefix = prefix or i.prefix
i.prefix = prefix or i.prefix
i.home = home or i.home
i.root = root or i.root
i.finalize_options()

View File

@ -1,5 +1,6 @@
import os
import sys
import textwrap
import glob
@ -486,6 +487,41 @@ def test_install_package_with_root(script, data):
assert root_path in result.files_created, str(result)
def test_install_package_with_prefix(script, data):
"""
Test installing a package using pip install --prefix
"""
prefix_path = script.scratch_path / 'prefix'
result = script.pip(
'install', '--prefix', prefix_path, '-f', data.find_links,
'--no-index', 'simple==1.0',
)
if hasattr(sys, "pypy_version_info"):
path = script.scratch / 'prefix'
else:
path = script.scratch / 'prefix' / 'lib' / 'python{0}'.format(pyversion) # noqa
install_path = (
path / 'site-packages' / 'simple-1.0-py{0}.egg-info'.format(pyversion)
)
assert install_path in result.files_created, str(result)
def test_install_package_conflict_prefix_and_user(script, data):
"""
Test installing a package using pip install --prefix --user errors out
"""
prefix_path = script.scratch_path / 'prefix'
result = script.pip(
'install', '-f', data.find_links, '--no-index', '--user',
'--prefix', prefix_path, 'simple==1.0',
expect_error=True, quiet=True,
)
assert (
"Can not combine '--user' and '--prefix'" in result.stderr
)
# skip on win/py3 for now, see issue #782
@pytest.mark.skipif("sys.platform == 'win32' and sys.version_info >= (3,)")
def test_install_package_that_emits_unicode(script, data):