fixed the stdin, thanks to zeeg

This commit is contained in:
Tarek Ziade 2012-07-27 11:52:37 +02:00
parent c41011901f
commit aaa14dc4e1
3 changed files with 22 additions and 4 deletions

View file

@ -1127,6 +1127,9 @@ class Checker(object):
if filename is None:
self.filename = 'stdin'
self.lines = lines or []
elif hasattr(filename, 'readlines'):
self.lines = filename.readlines()
self.filename = 'stdin'
elif lines is None:
self.lines = readlines(filename)
else:
@ -1644,8 +1647,10 @@ def process_options(arglist=None):
options.repeat = False
if options.testsuite:
args.append(options.testsuite)
if not args and not options.doctest:
parser.error('input not specified')
pass
options.prog = os.path.basename(sys.argv[0])
options.exclude = options.exclude.split(',')
for index, value in enumerate(options.exclude):

View file

@ -6,6 +6,11 @@ import sys
import os
import os.path
from subprocess import PIPE, Popen
import select
try:
from StringIO import StringIO # NOQA
except ImportError:
from io import StringIO # NOQA
from flake8.util import skip_file
from flake8 import pep8
@ -22,7 +27,8 @@ def check_file(path, complexity=-1):
def check_code(code, complexity=-1):
warnings = pyflakes.check(code, '<stdin>')
warnings = pyflakes.check(code, 'stdin')
warnings += pep8.input_file(StringIO(code))
if complexity > -1:
warnings += mccabe.get_code_complexity(code, complexity)
return warnings
@ -53,10 +59,17 @@ def main():
if builtins:
orig_builtins = set(pyflakes._MAGIC_GLOBALS)
pyflakes._MAGIC_GLOBALS = orig_builtins | builtins
if args:
if args and options.filename is not None:
for path in _get_python_files(args):
warnings += check_file(path, complexity)
else:
# wait for 1 second on the stdin fd
reads, __, __ = select.select([sys.stdin], [], [], 1.)
if reads == []:
print('input not specified')
raise SystemExit(1)
stdin = sys.stdin.read()
warnings += check_code(stdin, complexity)

View file

@ -3,7 +3,7 @@ import sys
ispy3 = sys.version_info[0] == 3
if ispy3:
from distutils.core import setup
from distutils.core import setup # NOQA
else:
try:
from setuptools import setup # NOQA