neoclide / coc-python

Python extension for coc.nvim, fork of vscode-python
574 stars 51 forks source link

Load "poetry" interpreter #131

Closed IamGianluca closed 4 years ago

IamGianluca commented 4 years ago

Hi,

How can I tell coc-python that I want to use the virtual environment created by poetry for a specific project?

I've tried to set the parameter python.poetryPath in coc-settings.json but it doesn't seem to do anything. Below is a copy of my coc-settings.json for this specific Python project.

{
    "python.analysis.diagnosticEnabled": true,
        "python.linting.enabled": true,
    "python.linting.pylintEnabled": false,
    "python.linting.flake8Enabled": false,
    "python.linting.mypyEnabled": false,
    "python.formatting.provider": "black",
    "python.formatting.blackArgs": [
            "-l",
            "79"
        ],
    "python.poetryPath": "poetry",
    "python.jediEnabled": false,
    "coc.preferences.formatOnSaveFiletypes": ["python"]
}
StrayDragon commented 4 years ago

I have the same problem, it can't automatically activate the virtual environment related to your project now. If you want to do that, you need to specify python.venvPath or python.venvFolders(If these don't work, you even need to specify python.pythonPath), which is not convenient for me.

I chose another way. And I don't want the virtual environment of the project to be placed outside the project (that is not very manageable for me when debugging are needed...)

In fact, you can let poetry generate virtualenv folder(.venv/) in your project folder, and it works well. As the poetry doc says:

$ poetry config virtualenvs.in-project true --local # remove "--local" will set global

https://python-poetry.org/docs/configuration/#virtualenvsin-project-boolean

IamGianluca commented 4 years ago

Thank you @StrayDragon, it works!

marco-silva0000 commented 4 years ago

What I've done is ad the poetry venv location to the coc settings json file, "python.venvPath": "~/Library/Caches/pypoetry/virtualenvs/" (note that this is on a mac, your location can be different) and then I could select the correct env with :CocCommand python.setInterpreter

I still thing this coc-python should correctly handle all of this with proper poetry integration, or maybe ad it's defaults to the default configuration, or have a poetry flag that would try to use poetry to figure out the correct venv.

yuttie commented 4 years ago

This problem is tracked by this issue on the original repository.

One of the development team mentioned a workaround there.