Environment
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)
virtualenv -p python3 env
source env/bin/activate
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
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. :)
Most helpful comment
FWIW,
python src/pip install --upgrade pip 0<&-
onmaster
, also crashes the same way and the proposed patch fixes it. :)