From 41393c9b6de513ea169b61c175b71018e8a12336 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Fri, 4 Dec 2015 00:13:28 -0600 Subject: [PATCH] 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 --- flake8/engine.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/flake8/engine.py b/flake8/engine.py index d8345ad..e90940e 100644 --- a/flake8/engine.py +++ b/flake8/engine.py @@ -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()