def __init__(self, messagesAllowed, output=sys.stdout): """ Initiate the the limited reporter. Load a list of allowed messages. @param output: output stream """ TextReporter.__init__(self, output) self.messagesAllowed = messagesAllowed
def __init__(self, pane): TextReporter.__init__(self) self.pane = pane
def test_pkginfo(self): """Make pylint check itself.""" self._runtest(["pylint.__pkginfo__"], reporter=TextReporter(StringIO()), code=0)
def test_no_crash_with_formatting_regex_defaults(self): self._runtest(["--ignore-patterns=a"], reporter=TextReporter(StringIO()), code=32)
if fName == os.path.basename(filename): if not len(fMsg): exceptDetected = True break ARGS_RUN.append(fMsg) if exceptDetected: nbExceptions += 1 continue print(ARGS_RUN) # execute pylint to analyze the code pylint_output = WritableObject() lint.Run([filename] + ARGS_RUN, reporter=TextReporter(pylint_output), exit=False) if GenerateRepport: # extract the note note = 0 for line in pylint_output.read(): if line.startswith("Your code has been rated at"): note = line.split("Your code has been rated at ")[1].split( '/10')[0] notes.append(float(note)) break else: nbTotError = 0 nbTotFatal = 0 nbTotWarning = 0
def add_message(self, msg_id, location, msg): """ Manage message of different type and in the context of path. """ if msg_id in self.messagesAllowed: TextReporter.add_message(self, msg_id, location, msg)
def check_python_lint(repo_root, staged_files, pylint_file, filter_pylint_stderr=False): """Runs pylint on all python scripts staged for commit. Return success and number of errors.""" class TextReporterBuffer(object): """Stores the output produced by the pylint TextReporter.""" def __init__(self): """init""" self.content = [] def write(self, input_str): """write""" self.content.append(input_str) def read(self): """read""" return self.content if filter_pylint_stderr: print("Running pylint...") # Parse each pylint output line individually and searches # for errors in the code. pylint_errors = [] for changed_file in staged_files: if not os.path.isfile(changed_file): continue if re.search(r'\.py$', changed_file): name_to_print = changed_file if name_to_print[:len(repo_root)] == repo_root: name_to_print = changed_file[len(repo_root) + 1:] pylint_output = TextReporterBuffer() pylint_args = [ "--rcfile=" + pylint_file, "-rn", repo_root + "/" + name_to_print ] # Prevent pylint from printing the config XX times prev_stderr = sys.stderr if filter_pylint_stderr: stderr_buffer = StringIO() sys.stderr = stderr_buffer # Run the linter from pylint.reporters.text import TextReporter pylint.lint.Run(pylint_args, reporter=TextReporter(pylint_output), exit=False) # Reset stderr and print filtered warnings. sys.stderr = prev_stderr if filter_pylint_stderr: warnings = stderr_buffer.getvalue().splitlines() for warning in warnings: if warning[:18] != 'Using config file ': sys.stderr.write(warning) sys.stderr.flush() errors = [] for output_line in pylint_output.read(): if re.search(r'^(E|C|W):', output_line): errors.append(output_line) pylint_errors.append(output_line) if errors: print("-" * 80) print("Found {} errors in : {}".format(len(errors), name_to_print)) print("-" * 80) print("\n".join(errors)) if pylint_errors: print("=" * 80) print("Found {} pylint errors".format(len(pylint_errors))) print("=" * 80) return False, len(pylint_errors) else: return True, 0
def run_pylint(filename='a1/a1_solution.py'): ARGS = [] ARGS = ['--output-format=json'] pylint_output = WritableObject() Run([filename] + ARGS, reporter=TextReporter(pylint_output), do_exit=False)
def run_pylint(self, directory): pylint_rc = os.path.join('core', 'controllers', 'tests', 'pylint.rc') pylint_args = [directory, '-E', '--rcfile=%s' % pylint_rc] pylint_output = WritableObject() lint.Run(pylint_args, reporter=TextReporter(pylint_output), exit=False) return pylint_output
#!/usr/bin/env python # encoding:utf-8 import sys from pylint.lint import Run from pylint.reporters.text import TextReporter from cStringIO import StringIO filename = sys.argv[1] args = ['--errors-only', filename] my_output = StringIO() reporter = TextReporter(output=my_output) Run(args, reporter=reporter, exit=False) output_str = my_output.getvalue() print "len %d characters" % len(output_str) print "Got %s characters" % output_str
from pylint.reporters.text import TextReporter from pylint.lint import Run with open("report.out", "w") as f: reporter = TextReporter(f) Run(["test.py"], reporter=reporter, do_exit=False)
def test_process_tokens() -> None: with timeout(8.0): with pytest.raises(SystemExit) as cm: Run([os.path.join(REGR_DATA, "very_long_line.py")], reporter=TextReporter()) assert cm.value.code == 0