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
Closed

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

emilburzo opened this issue Sep 30, 2019 · 2 comments · Fixed by #7118
Labels
auto-locked Outdated issues that have been locked by automation kind: crash For situations where pip crashes resolution: wrong project Should be reported elsewhere type: enhancement Improvements to functionality

Comments

@emilburzo
Copy link
Contributor

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 S: needs triage Issues/PRs that need to be triaged label Sep 30, 2019
@pfmoore
Copy link
Member

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 pradyunsg added the resolution: wrong project Should be reported elsewhere label Sep 30, 2019
@triage-new-issues triage-new-issues bot removed the S: needs triage Issues/PRs that need to be triaged label Sep 30, 2019
@pradyunsg pradyunsg added kind: crash For situations where pip crashes type: enhancement Improvements to functionality labels Sep 30, 2019
@pradyunsg
Copy link
Member

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 auto-locked Outdated issues that have been locked by automation 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.
Labels
auto-locked Outdated issues that have been locked by automation kind: crash For situations where pip crashes resolution: wrong project Should be reported elsewhere type: enhancement Improvements to functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants