File indexing completed on 2024-03-24 16:05:54
0001 #!/usr/bin/env python3 0002 0003 from contextlib import redirect_stdout 0004 from io import StringIO 0005 from sys import stdin, stdout, stderr 0006 import sys 0007 try: 0008 from pycodestyle import Checker, StyleGuide 0009 except ImportError: 0010 try: 0011 from pep8 import Checker, StyleGuide 0012 except ImportError: 0013 Checker = None 0014 0015 while True: 0016 size = stdin.buffer.read(10) 0017 size = int(size) 0018 if not size > 0: 0019 continue 0020 buf = bytes() 0021 while len(buf) < size: 0022 buf += stdin.buffer.read(min(1024, size - len(buf))) 0023 lines = buf.decode("utf-8").splitlines() 0024 opts, text = lines[:3], [l + "\n" for l in lines[3:]] 0025 0026 if Checker is not None: 0027 style_guide = StyleGuide() 0028 options = style_guide.options 0029 select = [x for x in opts[0].strip().split(',') if len(x) > 0] 0030 ignore = [x for x in opts[1].strip().split(',') if len(x) > 0] 0031 options.select = tuple(select) 0032 options.ignore = tuple(ignore) 0033 options.max_line_length = int(opts[2]) 0034 stderr.flush() 0035 c = Checker(lines=text, options=options) 0036 output = StringIO() 0037 with redirect_stdout(output): 0038 # writes directly to stdout, so catch it ... 0039 c.check_all() 0040 output = output.getvalue() 0041 output = output[:2**15] 0042 0043 stdout.write("{0:>10}".format(len(output))) 0044 stdout.write(output) 0045 stdout.flush() 0046 else: 0047 stderr.write("The `pycodestyle` (previously `pep8`) module is not installed.") 0048 stderr.flush() 0049 stdout.write("{0:>10}".format(0)) 0050 stdout.flush()