Search code examples
visual-studio-codepylint

Visual Studio Code pylint looking at plugins only in site-packages


I'm using the pylint plugin described in this answer in Visual Studio Code.

I have entered the following in the settings.json

{
    "python.linting.enabled": true,
    "python.linting.pylintEnabled": true,
    "python.linting.pylintArgs": ["--load-plugins","pylintplugins"],
}

My problem (found after a few hours of research, see also my second question below) is that I have to place pylintplugins.py under venv\Lib\site-packages: why is that happening and how can I instruct pylint from Visual Studio Code to look under my project root folder instead?

Notice that I have a PYTHONPATH pointing to my project root folder and that running from the terminal

pylint --load-plugins pylintplugins -E sample00.py

is OK.

A second question, if possible. When I move pylintplugins.py under my project root folder and pylint from Visual Studio Code can't find it, it silently fails: Studio Code simply stops showing the lint problems when I open a python file. It has been difficult for me to understand what was going wrong: where is a log of Visual Studio or something where one is supposed to find such a problem for python.linting?


Solution

  • The way I've found to make pylint read the path of the plugin from Visual Studio Code is

    1. put the following .pylintrc under the project root folder opened from Visual Studio Code

      [MASTER]

      load-plugins=C:/my/project/root/pylintplugins

    2. write the absolute path (*) of the project root folder as shown above

    Second Question

    Look at the OUTPUT tab of Visual Studio code and select Python from the dropdown list. You will find there how it is calling pylint.

    (*) In my case, since I didn't like the idea of keeping an absolute path, I ended up leveraging the init-hook option to run the following python commands as initialization (the current path is the work-dir and it is added to the sys path where it was missing, there you will find the python plugins file)

    [MASTER]
    init-hook="import sys; import os; sys.path.append(os.getcwd());"
    load-plugins=pylintplugins