Commits

Tarek Ziadé committed 125822e

fixed the stdin, thanks to zeeg

Comments (0)

Files changed (3)

         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:
         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):
 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
 
 
 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
     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)
 
 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