Skip to content

Commit

Permalink
Merge branch 'pep8-stdin-fix' into 'master'
Browse files Browse the repository at this point in the history
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

See merge request !44
  • Loading branch information
sigmavirus24 committed Dec 4, 2015
2 parents 54a81c0 + 41393c9 commit d5e3987
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions flake8/engine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
import errno
import io
import platform
import re
import sys
import warnings

import pep8
Expand Down Expand Up @@ -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()

0 comments on commit d5e3987

Please sign in to comment.