Skip to content

Allow for use_user_site being set to an integer #7258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
6 changes: 4 additions & 2 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

@atugushev atugushev Oct 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it can be reproduced outside of tox. Add user = true to pip.conf and you'll get the same error on pip install six. That happens because ConfigOptionParser uses distutils.util.strtobool() (wich returns int) when parses values from config file:

val = strtobool(val)

distutils.util:

def strtobool (val):
    """Convert a string representation of truth to true (1) or false (0).

    True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
    are 'n', 'no', 'f', 'false', 'off', and '0'.  Raises ValueError if
    'val' is anything else.
    """
    val = val.lower()
    if val in ('y', 'yes', 't', 'true', 'on', '1'):
        return 1
    elif val in ('n', 'no', 'f', 'false', 'off', '0'):
        return 0
    else:
        raise ValueError("invalid truth value %r" % (val,))

It could be worth to comment the case with config file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have a test fot that case, btw.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this one, but install:

def test_pip_wheel_with_user_set_in_config(script, data, common_wheels):
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(
'wheel', data.src / 'withpyproject',
'--no-index', '-f', common_wheels
)
assert "Successfully built withpyproject" in result.stdout, result.stdout

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, copied part of that and added a test.

# 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 is True:
if use_user_site:
if prefix_path:
raise CommandError(
"Can not combine '--user' and '--prefix' as they imply "
Expand Down
14 changes: 14 additions & 0 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down