Skip to content
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

pip install --help fails #9191

Closed
Rosswell opened this issue Dec 1, 2020 · 5 comments · Fixed by #9207
Closed

pip install --help fails #9191

Rosswell opened this issue Dec 1, 2020 · 5 comments · Fixed by #9207
Labels
type: bug A confirmed bug or unintended behavior
Milestone

Comments

@Rosswell
Copy link

Rosswell commented Dec 1, 2020

Environment

  • pip version: 20.3
  • Python version: 3.7.9 & 2.7.16
  • OS: macOS Catalina 10.15.7

Description
pip install --help fails to parse the cli args, resulting in it raising with an AttributeError, for both py2.7 and py3.7

Expected behavior
normal help output for the install command, as in pip 20.2.4:

$ pip install --help

Usage:
  pip install [options] <requirement specifier> [package-index-options] ...
  pip install [options] -r <requirements file> [package-index-options] ...
  pip install [options] [-e] <vcs project url> ...
  pip install [options] [-e] <local project path> ...
  pip install [options] <archive url/path> ...

Description:
  Install packages from:

  - PyPI (and other indexes) using requirement specifiers.
  - VCS project urls.
  - Local project directories.
  - Local or remote source archives.

  pip also supports installing from "requirements files", which provide
  an easy way to specify a whole environment to be installed.

Install Options:
  -r, --requirement <file>    Install from the given requirements file. This option can be used multiple times.
{...}

How to Reproduce

  1. set up and activate fresh virtual env
    $ python -m virtualenv ve && . ve/bin/activate
  2. install old pip
    $ pip install pip==20.2.4
  3. get expected help output
    $ pip install --help
  4. install new pip
    $ pip install pip==20.3
  5. try again, should fail
    $ pip install --help

Output

for python 3.7.9, pip install --help fails with the following error:

$ pip install --help
Traceback (most recent call last):
  File "/Users/rblanchard/repos/invitae-evidence-service/ve/bin/pip", line 8, in <module>
    sys.exit(main())
  File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/cli/main.py", line 75, in main
    return command.main(cmd_args)
  File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 117, in main
    return self._main(args)
  File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 131, in _main
    options, args = self.parse_args(args)
  File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 111, in parse_args
    return self.parser.parse_args(args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1387, in parse_args
    stop = self._process_args(largs, rargs, values)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1427, in _process_args
    self._process_long_opt(rargs, values)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1501, in _process_long_opt
    option.process(opt, value, values, self)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 785, in process
    self.action, self.dest, opt, value, values, parser)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 807, in take_action
    parser.print_help()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1647, in print_help
    file.write(self.format_help())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1635, in format_help
    result.append(self.format_option_help(formatter))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1618, in format_option_help
    result.append(group.format_help(formatter))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1101, in format_help
    result += OptionContainer.format_help(self, formatter)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1072, in format_help
    result.append(self.format_option_help(formatter))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 1061, in format_option_help
    result.append(formatter.format_option(option))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/optparse.py", line 322, in format_option
    help_text = self.expand_default(option)
  File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/cli/parser.py", line 123, in expand_default
    default_value, redact_auth_from_url(default_value))
  File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/utils/misc.py", line 826, in redact_auth_from_url
    return _transform_url(url, _redact_netloc)[0]
  File "/Users/rblanchard/repos/invitae-evidence-service/ve/lib/python3.7/site-packages/pip/_internal/utils/misc.py", line 786, in _transform_url
    purl = urllib_parse.urlsplit(url)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 418, in urlsplit
    url, scheme, _coerce_result = _coerce_args(url, scheme)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 123, in _coerce_args
    return _decode_args(args) + (_encode_result,)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 107, in _decode_args
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/parse.py", line 107, in <genexpr>
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
AttributeError: 'list' object has no attribute 'decode'

using python 2.7.16 produces a similar, but slightly different error:

$ pip install --help
Traceback (most recent call last):
  File "/Users/rblanchard/repos/invitae-evidence-service/v2/bin/pip", line 8, in <module>
    sys.exit(main())
  File "/Users/rblanchard/repos/invitae-evidence-service/v2/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 75, in main
    return command.main(cmd_args)
  File "/Users/rblanchard/repos/invitae-evidence-service/v2/lib/python2.7/site-packages/pip/_internal/cli/base_command.py", line 117, in main
    return self._main(args)
  File "/Users/rblanchard/repos/invitae-evidence-service/v2/lib/python2.7/site-packages/pip/_internal/cli/base_command.py", line 131, in _main
    options, args = self.parse_args(args)
  File "/Users/rblanchard/repos/invitae-evidence-service/v2/lib/python2.7/site-packages/pip/_internal/cli/base_command.py", line 111, in parse_args
    return self.parser.parse_args(args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1400, in parse_args
    stop = self._process_args(largs, rargs, values)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1440, in _process_args
    self._process_long_opt(rargs, values)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1515, in _process_long_opt
    option.process(opt, value, values, self)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 789, in process
    self.action, self.dest, opt, value, values, parser)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 811, in take_action
    parser.print_help()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1670, in print_help
    file.write(self.format_help().encode(encoding, "replace"))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1650, in format_help
    result.append(self.format_option_help(formatter))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1633, in format_option_help
    result.append(group.format_help(formatter))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1114, in format_help
    result += OptionContainer.format_help(self, formatter)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1085, in format_help
    result.append(self.format_option_help(formatter))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 1074, in format_option_help
    result.append(formatter.format_option(option))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/optparse.py", line 316, in format_option
    help_text = self.expand_default(option)
  File "/Users/rblanchard/repos/invitae-evidence-service/v2/lib/python2.7/site-packages/pip/_internal/cli/parser.py", line 123, in expand_default
    default_value, redact_auth_from_url(default_value))
  File "/Users/rblanchard/repos/invitae-evidence-service/v2/lib/python2.7/site-packages/pip/_internal/utils/misc.py", line 826, in redact_auth_from_url
    return _transform_url(url, _redact_netloc)[0]
  File "/Users/rblanchard/repos/invitae-evidence-service/v2/lib/python2.7/site-packages/pip/_internal/utils/misc.py", line 786, in _transform_url
    purl = urllib_parse.urlsplit(url)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urlparse.py", line 176, in urlsplit
    cached = _parse_cache.get(key, None)
TypeError: unhashable type: 'list'
@pradyunsg
Copy link
Member

HUH. This is definitely worth fixing. ;)

Thanks for the bug report @Rosswell! Would it be possible to provide the output of pip config list?

@pradyunsg pradyunsg added this to the 20.3.1 milestone Dec 1, 2020
@Rosswell
Copy link
Author

Rosswell commented Dec 1, 2020

@pradyunsg sure thing:

global.extra-index-url='https://pypi.python.org/simple/'
global.index-url='https://nexus.it.locusdev.net/repository/invitae-pypi/simple/'
global.no-cache-dir='true'
global.retries='1'
global.timeout='2'
global.trusted-host='nexus.it.locusdev.net'

@Rosswell
Copy link
Author

Rosswell commented Dec 1, 2020

I figured it would prolly be a good first issue, but didn't want to presume without looking into the cli parsing

@sbidoul
Copy link
Member

sbidoul commented Dec 1, 2020

#9163 touched that area in 20.3

@brainwane brainwane added the type: bug A confirmed bug or unintended behavior label Dec 1, 2020
@pradyunsg
Copy link
Member

I'd start by reverting #9163, and we can revisit it after. :)

bors bot referenced this issue in duckinator/emanate Dec 15, 2020
204: Update pip to 20.3.3 r=duckinator a=pyup-bot


This PR updates [pip](https://pypi.org/project/pip) from **20.3.1** to **20.3.3**.



<details>
  <summary>Changelog</summary>
  
  
   ### 20.3.3
   ```
   ===================

Bug Fixes
---------

- Revert &quot;Skip candidate not providing valid metadata&quot;, as that caused pip to be overeager about downloading from the package index. (`9264 &lt;https://github.com/pypa/pip/issues/9264&gt;`_)
   ```
   
  
  
   ### 20.3.2
   ```
   ===================

Features
--------

- New resolver: Resolve direct and pinned (``==`` or ``===``) requirements first
  to improve resolver performance. (`9185 &lt;https://github.com/pypa/pip/issues/9185&gt;`_)
- Add a mechanism to delay resolving certain packages, and use it for setuptools. (`9249 &lt;https://github.com/pypa/pip/issues/9249&gt;`_)

Bug Fixes
---------

- New resolver: The &quot;Requirement already satisfied&quot; log is not printed only once
  for each package during resolution. (`9117 &lt;https://github.com/pypa/pip/issues/9117&gt;`_)
- Fix crash when logic for redacting authentication information from URLs
  in ``--help`` is given a list of strings, instead of a single string. (`9191 &lt;https://github.com/pypa/pip/issues/9191&gt;`_)
- New resolver: Correctly implement PEP 592. Do not return yanked versions from
  an index, unless the version range can only be satisfied by yanked candidates. (`9203 &lt;https://github.com/pypa/pip/issues/9203&gt;`_)
- New resolver: Make constraints also apply to package variants with extras, so
  the resolver correctly avoids backtracking on them. (`9232 &lt;https://github.com/pypa/pip/issues/9232&gt;`_)
- New resolver: Discard a candidate if it fails to provide metadata from source,
  or if the provided metadata is inconsistent, instead of quitting outright. (`9246 &lt;https://github.com/pypa/pip/issues/9246&gt;`_)

Vendored Libraries
------------------

- Update vendoring to 20.8

Improved Documentation
----------------------

- Update documentation to reflect that pip still uses legacy resolver by default in Python 2 environments. (`9269 &lt;https://github.com/pypa/pip/issues/9269&gt;`_)
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/pip
  - Changelog: https://pyup.io/changelogs/pip/
  - Homepage: https://pip.pypa.io/
</details>



205: Update pytest to 6.2.1 r=duckinator a=pyup-bot


This PR updates [pytest](https://pypi.org/project/pytest) from **6.1.2** to **6.2.1**.



*The bot wasn't able to find a changelog for this release. [Got an idea?](https://github.com/pyupio/changelogs/issues/new)*

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/pytest
  - Homepage: https://docs.pytest.org/en/latest/
</details>



Co-authored-by: pyup-bot <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants