From d631a9355c3469d43e5fcf8d8093276906abca7f Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 24 Oct 2019 11:59:22 +0100 Subject: [PATCH 1/4] Allow for use_user_site being set to an integer This can come from tox config, see: https://github.com/pypa/pip/pull/7002#issuecomment-545108292 --- src/pip/_internal/commands/install.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index e50155c2709..9bc9f1e9b37 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -616,11 +616,13 @@ def decide_user_install( If use_user_site is None, the default behaviour depends on the environment, which is provided by the other arguments. """ - if use_user_site is False: + # In some cases (config from tox), use_user_site can be set to an integer + # rather than a bool. Comparing == True/False instead of 'is' allows this. + if use_user_site == False: # noqa: E712 logger.debug("Non-user install by explicit request") return False - if use_user_site is True: + if use_user_site == True: # noqa: E712 if prefix_path: raise CommandError( "Can not combine '--user' and '--prefix' as they imply " From 17e9f4c4a36c29f8ce4cd984fd3689e8bc75a092 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 24 Oct 2019 12:01:36 +0100 Subject: [PATCH 2/4] Mark as trivial change --- news/284c23de-df0b-4aaa-8454-4569829768fc.trivial | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 news/284c23de-df0b-4aaa-8454-4569829768fc.trivial diff --git a/news/284c23de-df0b-4aaa-8454-4569829768fc.trivial b/news/284c23de-df0b-4aaa-8454-4569829768fc.trivial new file mode 100644 index 00000000000..e69de29bb2d From 1310fc276a6a22eac7d2ffd8251065a9daac9375 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Fri, 25 Oct 2019 08:26:11 +0100 Subject: [PATCH 3/4] Use truthiness of everything but None for use_user_site --- src/pip/_internal/commands/install.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index 9bc9f1e9b37..bf4fbe3c777 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -617,12 +617,12 @@ def decide_user_install( which is provided by the other arguments. """ # In some cases (config from tox), use_user_site can be set to an integer - # rather than a bool. Comparing == True/False instead of 'is' allows this. - if use_user_site == False: # noqa: E712 + # rather than a bool, which 'use_user_site is False' wouldn't catch. + if (use_user_site is not None) and (not use_user_site): logger.debug("Non-user install by explicit request") return False - if use_user_site == True: # noqa: E712 + if use_user_site: if prefix_path: raise CommandError( "Can not combine '--user' and '--prefix' as they imply " From f92efc022b38806b1dda7ed6c7ad0c7fcc44e2e3 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Sun, 27 Oct 2019 10:09:15 +0000 Subject: [PATCH 4/4] Test that setting user in the config file works --- tests/functional/test_install.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 00a972f9652..f203ea43ce5 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -1586,6 +1586,20 @@ def test_target_install_ignores_distutils_config_install_prefix(script): assert relative_script_base not in result.files_created +def test_user_config_accepted(script): + # user set in the config file is parsed as 0/1 instead of True/False. + # Check that this doesn't cause a problem. + config_file = script.scratch_path / 'pip.conf' + script.environ['PIP_CONFIG_FILE'] = str(config_file) + config_file.write_text("[install]\nuser = true") + result = script.pip_install_local('simplewheel') + + assert "Successfully installed simplewheel" in result.stdout + + relative_user = os.path.relpath(script.user_site_path, script.base_path) + assert join(relative_user, 'simplewheel') in result.files_created + + @pytest.mark.network @pytest.mark.skipif("sys.platform != 'win32'") @pytest.mark.parametrize('pip_name', [