coc-python icon indicating copy to clipboard operation
coc-python copied to clipboard

Provide a per-project way to customize PYTHONPATH for pylint

Open ellbur opened this issue 4 years ago • 0 comments

It would be useful to be able to customize the PYTHONPATH used by pylint on a per-project basis.

I found a work-around, although it is somewhat circuitous.

First, I created a .pylintrc file in the directory of the python script, with content that adds to the path:

[MASTER]

init-hook='import sys; sys.path.insert(0, "..");'

However, coc-python does not invoke pylint in the working directory of the source file you are editing. So, I created a script called pylint-in-file-dir:

#!/bin/zsh

last_arg=${*[-1]}
dir_of_file=${last_arg:a:h}

cd $dir_of_file

~/.local/bin/pylint $*

Then, I edited coc-settings.json to use pylint-in-file-dir:

{
    "python.linting.pylintPath": "/home/owen/bin/pylint-in-file-dir"
}

This ultimately achieved the desired result.

ellbur avatar Jul 17 '20 21:07 ellbur