Skip to content

Commit

Permalink
Raise error if --user and --target arguments are used together
Browse files Browse the repository at this point in the history
  • Loading branch information
sinscary committed Feb 27, 2020
1 parent 268a2dd commit 716c920
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/7249.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise error if --user and --target are used together in command
3 changes: 3 additions & 0 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ def __init__(self, *args, **kw):
@with_cleanup
def run(self, options, args):
# type: (Values, List[Any]) -> int
if options.use_user_site and options.target_dir is not None:
raise CommandError("Can not combine '--user' and '--target'")

cmdoptions.check_install_build_global(options)
upgrade_strategy = "to-satisfy-only"
if options.upgrade:
Expand Down
21 changes: 21 additions & 0 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,27 @@ def test_install_package_with_target(script):
assert singlemodule_py in result.files_updated, str(result)


def test_install_package_to_usersite_with_target_must_fail(script):
"""
Test that installing package to usersite with target
must raise error
"""
target_dir = script.scratch_path / 'target'
result = script.pip_install_local(
'--user', '-t', target_dir, "simple==1.0", expect_error=True
)
assert "Can not combine '--user' and '--target'" in result.stderr, (
str(result)
)

result = script.pip_install_local(
'--user', '--target', target_dir, "simple==1.0", expect_error=True
)
assert "Can not combine '--user' and '--target'" in result.stderr, (
str(result)
)


def test_install_nonlocal_compatible_wheel(script, data):
target_dir = script.scratch_path / 'target'

Expand Down

0 comments on commit 716c920

Please sign in to comment.