def lint(filename, settings): """ Run flake8 lint with internal interpreter. """ # check if active view contains file if not filename or not os.path.exists(filename): return # skip file check if 'noqa' for whole file is set if util.skip_file(filename): return # place for warnings =) warnings = [] # lint with pyflakes if settings.get('pyflakes', True): warnings.extend(pyflakes.checkPath(filename)) # lint with pep8 if settings.get('pep8', True): pep8style = pep8.StyleGuide(reporter=Pep8Report) pep8style.input_file(filename) warnings.extend(pep8style.options.report.errors) # check complexity complexity = settings.get('complexity', -1) if complexity > -1: warnings.extend(mccabe.get_module_complexity(filename, complexity)) return warnings
def lint(filename, settings): """ Run flake8 lint with internal interpreter. """ # check if active view contains file if not filename or not os.path.exists(filename): return # skip file check if 'noqa' for whole file is set if util.skip_file(filename): return # place for warnings =) warnings = [] # lint with pyflakes if settings.get('pyflakes', True): warnings.extend(pyflakes.checkPath(filename)) # lint with pep8 if settings.get('pep8', True): pep8style = pep8.StyleGuide( reporter=Pep8Report, ignore=settings.get('ignore', []), max_line_length=settings.get('pep8_max_line_length')) pep8style.input_file(filename) warnings.extend(pep8style.options.report.errors) # check complexity complexity = settings.get('complexity', -1) if complexity > -1: warnings.extend(mccabe.get_module_complexity(filename, complexity)) return warnings
def lint_external(filename, settings, interpreter, linter): """ Run flake8 lint with external interpreter. """ import subprocess # check if active view contains file if not filename or not os.path.exists(filename): return # skip file check if 'noqa' for whole file is set if util.skip_file(filename): return # first argument is interpreter arguments = [interpreter, linter] # do we need to run pyflake lint if settings.get('pyflakes', True): arguments.append('--pyflakes') # do we need to run pep8 lint if settings.get('pep8', True): arguments.append('--pep8') max_line_length = settings.get('pep8_max_line_length') arguments.append('--pep8-max-line-length') arguments.append(str(max_line_length)) # do we need to run complexity check complexity = settings.get('complexity', -1) if complexity > 0: arguments.extend(('--complexity', str(complexity))) # last argument is script to check filename arguments.append(filename) # place for warnings =) warnings = [] # run subprocess proc = subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr = subprocess.STDOUT) # parse STDOUT for warnings and errors for line in proc.stdout: line = line.decode('utf-8') warning = line.strip().split(':', 2) if len(warning) == 3: warnings.append((int(warning[0]), int(warning[1]), warning[2])) # and return them =) return warnings
def lint_external(filename, settings, interpreter, linter): """ Run flake8 lint with external interpreter. """ import subprocess # check if active view contains file if not filename or not os.path.exists(filename): return # skip file check if 'noqa' for whole file is set if util.skip_file(filename): return # first argument is interpreter arguments = [interpreter, linter] # do we need to run pyflake lint if settings.get('pyflakes', True): arguments.append('--pyflakes') # do we need to run pep8 lint if settings.get('pep8', True): arguments.append('--pep8') max_line_length = settings.get('pep8_max_line_length') arguments.append('--pep8-max-line-length') arguments.append(str(max_line_length)) # do we need to run complexity check complexity = settings.get('complexity', -1) if complexity > 0: arguments.extend(('--complexity', str(complexity))) # last argument is script to check filename arguments.append(filename) # place for warnings =) warnings = [] # run subprocess proc = subprocess.Popen(arguments, stdout=subprocess.PIPE) # parse STDOUT for warnings and errors for line in proc.stdout: warning = line.strip().split(':', 2) if len(warning) == 3: warnings.append((int(warning[0]), int(warning[1]), warning[2])) # and return them =) return warnings