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

Conversation

takluyver
Copy link
Member

This can come from tox config, as described in a comment:
#7002 (comment)

This PR implements @pradyunsg's suggested fix. The alternatives are to delve into how options & config are handled to fix it there, or to get it fixed in tox and hope no-one else hits it.

The # noqa: E712 markers are required to stop flake8 from complaining that the comparisons should use is, as normally they should.

@takluyver
Copy link
Member Author

takluyver commented Oct 24, 2019 via email

@pfmoore
Copy link
Member

pfmoore commented Oct 24, 2019

How about if user_site is not None and not user_site:? It's more verbose, but says what it means (the value is set, and it's not true) and avoids the code smell of equality-testing booleans.

@pradyunsg
Copy link
Member

@pfmoore's suggestion as well as this PR as is, both work for me. :)

@takluyver
Copy link
Member Author

That makes sense. I've pushed a new commit.

@@ -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.

@pradyunsg pradyunsg merged commit be13cf9 into pypa:master Oct 27, 2019
@pradyunsg
Copy link
Member

Thanks y'all! :)

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Nov 26, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants