Pip: crash when `sys.stdin` is `None` in subversion.py

Created on 30 Sep 2019  路  2Comments  路  Source: pypa/pip

Environment

  • pip version: 19.2.3
  • Python version: 3.7.4
  • OS: archlinux

Description

The code that determines if to use interactive mode in subversion.py breaks when sys.stdin is None

Expected behavior

Does not crash.

How to Reproduce

(On linux)

  1. Run: virtualenv -p python3 env
  2. Run: source env/bin/activate
  3. Run: python -c 'import pip._internal as pip' 0<&- (this simulates a None sys.stdin)

Output

$ virtualenv -p python3 env
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /tmp/env/bin/python3
Also creating executable in /tmp/env/bin/python
Installing setuptools, pip, wheel...
done.
$ source env/bin/activate
(env) $ python -c 'import pip._internal as pip' 0<&-
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/__init__.py", line 40, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/cli/main_parser.py", line 11, in <module>
    from pip._internal.commands import (
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 6, in <module>
    from pip._internal.commands.completion import CompletionCommand
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/commands/completion.py", line 6, in <module>
    from pip._internal.cli.base_command import Command
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 21, in <module>
    from pip._internal.download import PipSession
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/download.py", line 47, in <module>
    from pip._internal.vcs import vcs
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/vcs/__init__.py", line 12, in <module>
    import pip._internal.vcs.subversion  # noqa: F401
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/vcs/subversion.py", line 314, in <module>
    vcs.register(Subversion)
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/vcs/versioncontrol.py", line 165, in register
    self._registry[cls.name] = cls()
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/vcs/subversion.py", line 180, in __init__
    use_interactive = sys.stdin.isatty()
AttributeError: 'NoneType' object has no attribute 'isatty'
(env) $ 

Notes

And in case you're wondering how I got to this internal API: I'm running (on AWS Lambda) awslimitchecker, which uses versionfinder, which uses pip

crash wrong project auto-locked enhancement

Most helpful comment

FWIW, python src/pip install --upgrade pip 0<&- on master, also crashes the same way and the proposed patch fixes it. :)

All 2 comments

Have you reported the incorrect usage of pip's internals to the offending project(s)? They should fix their code. Also, the python docs don't seem to indicate that None is a valid value for sys.stdin. Experimentally, it seems like it's possible though:

[vagrant@localhost ~]$ python3 -V
Python 3.7.0
[vagrant@localhost ~]$ python3 -c 'import sys; print(repr(sys.stdin))' 0<&-
None

Having said that, the fix seems relatively harmless so I have no real objection to adding a bit of defensive code to pip.

FWIW, python src/pip install --upgrade pip 0<&- on master, also crashes the same way and the proposed patch fixes it. :)

Was this page helpful?
0 / 5 - 0 ratings