Пример #1
0
 def check_filename(self, root, filename):
     pep8.process_options(
         ["--repeat", "--select=%s" % (",".join(ERRORS),), filename]
     )
     pep8.input_file(filename)
     result = pep8.get_count()
     if result:
         raise AssertionError("ERROR: %d PEP8 errors in %s" % (result, filename,))
Пример #2
0
 def closure(self, fullpath=fullpath):
     pep8.process_options([
         '--first', fullpath,
         '--ignore', ','.join(PEP8_IGNORE)],
         )
     pep8.input_file(fullpath)
     if len(pep8.get_statistics()):
         self.fail('PEP8 issue in "%s"' % fullpath)
Пример #3
0
 def check_filename(self, root, filename):
     pep8.process_options([
         '--repeat',
         '--select=%s' % (','.join(ERRORS), ), filename
         ])
     pep8.input_file(filename)
     result = pep8.get_count()
     if result:
         raise AssertionError("ERROR: %d PEP8 errors in %s" % (result,
                                                               filename))
Пример #4
0
    def output(self):

        options = [self.path, '--repeat']

        options.extend(('--ignore', self.get_ignored_ids()))

        stdout, sys.stdout = sys.stdout, StringIO.StringIO()
        try:

            import pep8
            pep8.MAX_LINE_LENGTH = self.max_line_length or 79
            pep8.process_options(options)
            pep8.input_file(self.path)
            return sys.stdout.getvalue().strip()

        finally:
            sys.stdout = stdout
Пример #5
0
def check(path, ignore=None, to_file=False):

    quite = '-qq'
    source = '--show-source'
    pep = '--show-pep8'
    rep = '--repeat'

    args = [rep]

    if ignore is None:
        ignore = []

    if to_file:
        out_file = './pep8.txt'
        if os.path.exists(out_file):
            os.remove(out_file)
        file_handle = open(out_file, 'a')

    files_count = 0

    for the_file in walk_path(path, recurse=True, pattern='*.py', ignore=ignore):
        arglist = args[:] + [the_file]
        pep8.process_options(arglist)
        try:
            pep8.input_file(the_file)
            error_stats = pep8.get_error_statistics()
            warning_stats = pep8.get_warning_statistics()

            if to_file:
                if warning_stats or error_stats:
                    file_handle.write('\n')
                file_handle.write(the_file)
                file_handle.write('\n')
                
                for warning in warning_stats:
                    file_handle.write("%s\n" % warning)
                for errors in error_stats:
                    file_handle.write("%s\n" % errors)

            files_count += 1
            sys.stdout.write('Processed %d file(s) \r' % files_count)

        except  Exception, e:
            pass
Пример #6
0
    def _check_pep8(self, path):
        if not install_flg["pep8"]:
            return [{"line": 0, "msg": "no install pep8"}]

        pep8.process_options([""])
        t = tempfile.TemporaryFile()
        sys.stdout = t
        pep8.input_file(path)
        t.seek(0)
        s = t.read()
        sys.stdout.close()
        sys.stdout = sys.__stdout__

        res = []
        arr = s.split("\n")
        for e in arr:
            if e.strip() == "":
                continue
            cols = e.split(":")
            res.append({"line": int(cols[1]), "msg": ":".join(cols[3:])})
        return res
Пример #7
0
    def _check_pep8(self, path):
        if not install_flg['pep8']:
            return [{'line': 0, 'msg': 'no install pep8'}]

        pep8.process_options([''])
        t = tempfile.TemporaryFile()
        sys.stdout = t
        pep8.input_file(path)
        t.seek(0)
        s = t.read()
        sys.stdout.close()
        sys.stdout = sys.__stdout__

        res = []
        arr = s.split('\n')
        for e in arr:
            if e.strip() == '':
                continue
            cols = e.split(':')
            res.append({'line': int(cols[1]), 'msg': ':'.join(cols[3:])})
        return res
  def display_pep8(self, path, summary=True):
    pep8_out = StringIO()
    try:
      with RedirectedIO(target=pep8_out, close_target=False):
        pep8.process_options([path])
        pep8.input_file(path)
        error_stats = pep8.get_error_statistics()
        warning_stats = pep8.get_warning_statistics()
      val = pep8_out.getvalue().splitlines()
      for line in [ x.split(':',1)[1] for x in val if ':' in x]:
        self.writeln(line)

      if summary:
        self.writeln()
        self.writeln("Summary:")
        for e in error_stats:
          self.writeln(e)
        for w in warning_stats:
          self.writeln(w)
        self.writeln()
    except tokenize.TokenError:
      self.boxed_text(["PEP8 processing failed - check your source code"], symbol="#")
Пример #9
0
    def _check_pep8(self, path):
        if not install_flg['pep8']:
            return [{'line': 0, 'msg': 'no install pep8'}]

        pep8.process_options([''])
        t = tempfile.TemporaryFile()
        sys.stdout = t
        pep8.input_file(path)
        t.seek(0)
        s = t.read()
        sys.stdout.close()
        sys.stdout = sys.__stdout__

        res = []
        arr = s.split('\n')
        for e in arr:
            if e.strip() == '':
                continue
            cols = e.split(':')
            res.append({
                'line': int(cols[1]),
                'msg': ':'.join(cols[3:])
            })
        return res
Пример #10
0
#!/usr/local/bin/python3.2
import tkinter
from tkinter.filedialog import askopenfilename
import sys

import pep8

if __name__ == "__main__":
    root = tkinter.Tk()
    py_file = askopenfilename(title="Select a Python file to stylecheck ...",
                              initialdir=".")
    if not py_file:
        sys.exit("No file selected")

    pep8.process_options(['-v', '--count', py_file])
    pep8.input_file(py_file)
    if pep8.get_statistics() == []:
        print("Congrats! No style errors were detected.")
Пример #11
0
 def beforeImport(self, filename, module):
     if filename.endswith(".py") and filename not in self.seen:
         pep8.input_file(filename)
         self.seen.append(filename)
Пример #12
0
 def seen_runner(filename):
     if filename not in self.seen:
         pep8.input_file(filename)
         self.seen.append(filename)
Пример #13
0
def check(filename):
    pep8.process_options(['-qq', filename])
    pep8.input_file(filename)
    return pep8.get_error_statistics(), pep8.get_warning_statistics()
Пример #14
0
fh.close()

# backup stdout
stdout = sys.stdout

# handle each module
for path in paths:
    module = path.split(os.sep)[-2]
    sys.stdout = StringIO()
    # clean up runner options
    options, args = process_options()
    options.repeat = True
    if os.path.isdir(path):
        input_dir(path, runner=input_file)
    elif not excluded(path):
        input_file(path)
    sys.stdout.seek(0)
    data = sys.stdout.read()
    statistic = get_statistics('')
    count = get_count()
    # write rst file
    fh = open(os.path.join('source', 'pep8', module + '.rst'), 'wt')
    title = "%s (%d)" % (module, count)
    fh.write(len(title) * "=" + "\n")
    fh.write(title + "\n")
    fh.write(len(title) * "=" + "\n")
    fh.write("\n")

    if count == 0:
        fh.write("The PEP 8 checker didn't find any issues.\n")
        fh.close()
Пример #15
0
 def beforeImport(self, filename, module):
     if filename.endswith(".py") and self.want_file(filename):
         pep8.input_file(filename)
Пример #16
0
 def seen_runner(filename):
     if self.want_file(filename):
         pep8.input_file(filename)