Другой точкой входа для pylint является функция epylint.py_run
, которая реализует перехват stdout и stderr. Однако, как показано в следующем коде, pylint, похоже, не пишет свои отчеты в stdout:
from pylint import epylint
pylint_stdout, pylint_stderr = epylint.py_run(__file__, return_std=True)
print(pylint_stdout.getvalue()) # -> there is just the final rank, no report nor message
print(pylint_stderr.getvalue())
Теперь я обнаружил, что pylint из API и pylint из CLI не используют одинаковые параметры по умолчанию. Таким образом, вам просто нужно указать параметры, которые вам нужны.
from pylint import epylint
options = '--enable=all' # all messages will be shown
options += '--reports=y' # also print the reports (ascii tables at the end)
pylint_stdout, pylint_stderr = epylint.py_run(__file__ + ' ' + options, return_std=True)
print(pylint_stdout.getvalue())
print(pylint_stderr.getvalue())
Как описано здесь , pylint выполнит сам синтаксический анализ и правильно выведет ожидаемые результаты в стандартный вывод.