invoking pylint programmatically

mariotomo picture mariotomo · Jan 8, 2010 · Viewed 11.5k times · Source

I'd like to invoke the pylint checker, limited to the Error signalling part, as part of my unit testing. so I checked the pylint executable script, got to the pylint.lint.Run helper class and there I got lost in a quite long __init__ function, ending with a call to sys.exit().

anybody ever tried and managed to do so?

the dream-plan would be this:

if __name__ == '__main__':
  import pylint.lint
  pylint.lint.something(__file__, justerrors=True)
  # now continue with unit testing

any hints? other than "copy the __init__ method and skip the sys.exit()", I mean?

I don't need the tests to be run by pylint, it might as well be pyflakes or other software: feel free to suggest alternatives. thanks!

Answer

syt picture syt · Jan 14, 2010

Take a look at the pylint/epylint.py which contains two different ways to start pylint programatically.

You can also simply call :

from pylint.lint import Run
Run(['--errors-only', 'myfile.py']) 

for instance.