palantir / python-language-server

An implementation of the Language Server Protocol for Python
MIT License
2.61k stars 283 forks source link

Pylint is not working to provide linting in conda envs #753

Open vakker opened 4 years ago

vakker commented 4 years ago

How do you set the conda environment for pyls? I'm using emacs and pyls only uses the base environment. I tried using conda-mode for changing the environment, but pyls still uses the base.

goanpeca commented 4 years ago

You mean this

https://github.com/palantir/python-language-server/blob/develop/vscode-client/package.json#L43

?

vakker commented 4 years ago

I think so. So pyls resolves the environment based on jedi?

goanpeca commented 4 years ago

Well the issue is that we should not need to install the pyls plus all the required deps on a given environment. pyls should (in theory) just live on the main environment. Jedi provides such facilities so that most of the things can be done by setting that option to point to the right env (python executable).

Now @andfoy might want to chime in with more information.

goanpeca commented 4 years ago

Otherwise you need to install pyls on that environment an use

                "pyls.executable": {
                    "type": "string",
                    "default": "pyls",
                    "description": "Language server executable"
                },
vakker commented 4 years ago

I see what you mean.

Okey, I managed to activate the environment in Emacs and restart pyls and then it picks up the right environment. However, as you said, this requires pyls to be installed in the target environment which is not ideal.

If I just set the pyls.plugins.jedi.environment, and use pyls from the base env then jedi works as expected, but I'm still getting pylint issues as it seems to run in the base env.

Looking into your pylint_lint.py setting the env based on jed.environment seems to be missing (if I'm not mistaken). For the record, pylint doesn't provide an easy way to do this, e.g. see this and there's also this project (for venv, but I assume the same logic applies for conda).

ccordoba12 commented 4 years ago

If I just set the pyls.plugins.jedi.environment, and use pyls from the base env then jedi works as expected

Great! That's what @goanpeca was talking about.

but I'm still getting pylint issues as it seems to run in the base env.

That's a separate issue, but since you verified that completion is working for different envs, I'll change the title of this issue to reflect that Pylint is not working for this use case.

there's also this project (for venv, but I assume the same logic applies for conda).

I took a look at that project and it seems pretty simple: we just need to extend the sys.path of the Pylint process to include the one provided by the env.

If you want to tackle this one, we'd be really grateful. Else, you'll have to wait us a couple of months for a fix.

vakker commented 4 years ago

For the record, it's not just pylint, but everything else than jedi I think. Probably it doesn't make any difference for yapf, isort, etc. , but mypy, flake, and alike would benefit from setting the environment according to the project.

For now I'll just go with installing pyls in the project environment as I already got that working and I'm a bit swamped currently so I can't work on this at the moment. But if you need any input on this just let me know.