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

crash when `sys.stdin` is `None` in subversion.py #7119

Closed
emilburzo opened this issue Sep 30, 2019 · 2 comments · Fixed by #7118

Comments

@emilburzo
Copy link
Contributor

@emilburzo emilburzo commented Sep 30, 2019

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

@triage-new-issues triage-new-issues bot added the triage label Sep 30, 2019
@pfmoore

This comment has been minimized.

Copy link
Member

@pfmoore pfmoore commented Sep 30, 2019

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.

@pradyunsg

This comment has been minimized.

Copy link
Member

@pradyunsg pradyunsg commented Sep 30, 2019

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

@lock lock bot added the S: auto-locked label Nov 1, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Nov 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.