Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run pylint from inside Python?

Tags:

python

pylint

I want to run pylint on all my modules, which are in different locations in a big directory. Because running pylint in this directory is still not supported, I assume I need to walk through each module in my own Python scripts and run pylint on each module from there.

To run pylint inside a Python script, the documentation seems clear:

It is also possible to call Pylint from another Python program, thanks to the Run() function in the pylint.lint module (assuming Pylint options are stored in a list of strings pylint_options) as:

import pylint.lint
pylint_opts = ['--version']
pylint.lint.Run(pylint_opts)

However, I cannot get this to run successfully on actual files. What is the correct syntax? Even if I copy-paste the arguments that worked on the command-line, using an absolute file path, the call fails:

import pylint.lint 
pylint_opts = ["--load-plugins=pylint.extensions.docparams /home/user/me/mypath/myfile.py"]
pylint.lint.Run(pylint_opts)

The output is the default fallback dialogue of the command-line tool, with my script's name instead of pylint:

No config file found, using default configuration
Usage: myscript.py [options] module_or_package

  Check that a module satisfied a coding standard (and more !).

    myscript.py --help`  
[...]

What am I missing?

I know that epylint exists as an alternative, and I can get that to run, but it is extremely inconvenient that it overrides the --msg-format and --reports parameters and I want to figure out what I am doing wrong.

like image 231
FvD Avatar asked Jan 24 '26 02:01

FvD


1 Answers

The answer is to separate the options into a list, as shown in this related question:

pylint_opts = ["--load-plugins=pylint.extensions.docparams", "/home/user/me/mypath/myfile.py"]
like image 107
FvD Avatar answered Jan 26 '26 16:01

FvD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!