From 8380b2b09affbff8f1ee5ddc466b755fc36306c6 Mon Sep 17 00:00:00 2001 From: sinscary Date: Mon, 24 Feb 2020 14:28:53 +0530 Subject: [PATCH 1/4] Raise error if --user and --target arguments are used together --- news/7249.feature | 1 + src/pip/_internal/cli/main_parser.py | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 news/7249.feature diff --git a/news/7249.feature b/news/7249.feature new file mode 100644 index 00000000000..4548aa006e2 --- /dev/null +++ b/news/7249.feature @@ -0,0 +1 @@ +Raise error if --user and --target are used together in command diff --git a/src/pip/_internal/cli/main_parser.py b/src/pip/_internal/cli/main_parser.py index 4871956c9de..9fd3af49e9b 100644 --- a/src/pip/_internal/cli/main_parser.py +++ b/src/pip/_internal/cli/main_parser.py @@ -83,6 +83,17 @@ def parse_command(args): # the subcommand name cmd_name = args_else[0] + validate_command_args(cmd_name, args_else) + + # all the args without the subcommand + cmd_args = args[:] + cmd_args.remove(cmd_name) + + return cmd_name, cmd_args + + +def validate_command_args(cmd_name, args_else): + # type: (str, List[str]) -> None if cmd_name not in commands_dict: guess = get_similar_commands(cmd_name) @@ -92,8 +103,6 @@ def parse_command(args): raise CommandError(' - '.join(msg)) - # all the args without the subcommand - cmd_args = args[:] - cmd_args.remove(cmd_name) - - return cmd_name, cmd_args + if set(['--user', '--target']).issubset(set(args_else)): + error_msg = '--user and --target cant not be used together.' + raise CommandError(error_msg) From 268a2dd818ed4a539845609a5c0370101548c4e4 Mon Sep 17 00:00:00 2001 From: sinscary Date: Wed, 26 Feb 2020 14:14:34 +0530 Subject: [PATCH 2/4] Revert "Raise error if --user and --target arguments are used together" This reverts commit b6d775d98837a5eaf2cba73a719821c89a71fc8f. --- news/7249.feature | 1 - src/pip/_internal/cli/main_parser.py | 19 +++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) delete mode 100644 news/7249.feature diff --git a/news/7249.feature b/news/7249.feature deleted file mode 100644 index 4548aa006e2..00000000000 --- a/news/7249.feature +++ /dev/null @@ -1 +0,0 @@ -Raise error if --user and --target are used together in command diff --git a/src/pip/_internal/cli/main_parser.py b/src/pip/_internal/cli/main_parser.py index 9fd3af49e9b..4871956c9de 100644 --- a/src/pip/_internal/cli/main_parser.py +++ b/src/pip/_internal/cli/main_parser.py @@ -83,17 +83,6 @@ def parse_command(args): # the subcommand name cmd_name = args_else[0] - validate_command_args(cmd_name, args_else) - - # all the args without the subcommand - cmd_args = args[:] - cmd_args.remove(cmd_name) - - return cmd_name, cmd_args - - -def validate_command_args(cmd_name, args_else): - # type: (str, List[str]) -> None if cmd_name not in commands_dict: guess = get_similar_commands(cmd_name) @@ -103,6 +92,8 @@ def validate_command_args(cmd_name, args_else): raise CommandError(' - '.join(msg)) - if set(['--user', '--target']).issubset(set(args_else)): - error_msg = '--user and --target cant not be used together.' - raise CommandError(error_msg) + # all the args without the subcommand + cmd_args = args[:] + cmd_args.remove(cmd_name) + + return cmd_name, cmd_args From 716c9202eeecbf4601b39a8ab7bc7085c36e3883 Mon Sep 17 00:00:00 2001 From: sinscary Date: Thu, 27 Feb 2020 12:22:05 +0530 Subject: [PATCH 3/4] Raise error if --user and --target arguments are used together --- news/7249.feature | 1 + src/pip/_internal/commands/install.py | 3 +++ tests/functional/test_install.py | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 news/7249.feature diff --git a/news/7249.feature b/news/7249.feature new file mode 100644 index 00000000000..4548aa006e2 --- /dev/null +++ b/news/7249.feature @@ -0,0 +1 @@ +Raise error if --user and --target are used together in command diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index da652238987..df9681f8c1c 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -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: diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index a95b46741dd..1ea9db26e4b 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -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' From 7e2bab41b9550faf8bc82de170a33fe7f44823d1 Mon Sep 17 00:00:00 2001 From: sinscary Date: Thu, 27 Feb 2020 14:12:01 +0530 Subject: [PATCH 4/4] update newsfile --- news/7249.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/7249.feature b/news/7249.feature index 4548aa006e2..0a791c928df 100644 --- a/news/7249.feature +++ b/news/7249.feature @@ -1 +1 @@ -Raise error if --user and --target are used together in command +Raise error if --user and --target are used together in pip install