Cache stdin for Flake8 plugins

Currently plugins (e.g., flake8-docstrings) are struggling to support
users passing data in on stdin (e.g., cat file.py | flake8 -). Until
pep8 fixes this itself, we can monkey-patch its `stdin_get_value`
function to handle the caching for us.

Closes #105
This commit is contained in:
Ian Cordasco 2015-12-04 00:13:28 -06:00
parent 54a81c0595
commit 41393c9b6d

View file

@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
import errno
import io
import platform
import re
import sys
import warnings
import pep8
@ -293,3 +295,15 @@ def get_python_version():
except AttributeError: # Python 2.5
impl = ''
return '%s%s on %s' % (impl, platform.python_version(), platform.system())
def make_stdin_get_value():
value = pep8.stdin_get_value()
if sys.version_info < (3, 0):
stdin = io.BytesIO(value)
else:
stdin = io.StringIO(value)
return stdin.getvalue
pep8.stdin_get_value = make_stdin_get_value()