Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using coc-python with a python inside of a container #664

Open
adamwojt opened this issue Nov 22, 2021 · 13 comments
Open

Using coc-python with a python inside of a container #664

adamwojt opened this issue Nov 22, 2021 · 13 comments
Assignees

Comments

@adamwojt
Copy link

I wonder if it would be possible to setup coc-pyright to use paths inside docker container.
I see there was issue about this in coc-python repo: neoclide/coc-python#85

@fannheyward
Copy link
Owner

Do you mean you have Python & modules installed in the container, run coc-python and your Python code outside? Have no idea about this.

@adamwojt
Copy link
Author

Correct. The idea is that all paths are inside docker but i am editing it outside.

@fannheyward
Copy link
Owner

@adamwojt can you run the inside Python interpreter from outside?

@lyndsysimon
Copy link

I'm going to need this as well, and may be able to help implement it.

My use case:

With the introduction of the Apple M1 series (and their arm64 architecture), I've run into some issues with my Python environments. The first was that some dependencies for legacy projects are not available as Python wheels (psycopg2-binary). I was able to build that one from source but quickly ran into other issues that required moving my existing Docker images to explicitly use an Intel architecture (platform: 'linux/amd64').

Abandoning the concept of creating a Python environment on the host means that I no longer have that available for pyright, which in turn means that Neovim's tree-sitter implementation can't use it for code completion, syntax highlighting, and indentation.

@IvRRimum
Copy link

I run my python code in a docker container, i have python libs in the same directory. Is there a way to define extraPaths for auto-completion/diagnostics? Taht would be awesome!

@adamwojt
Copy link
Author

@fannheyward I am not sure what you mean. I can run python interpreter with docker-compose run $MY_CONTAINER python and that will just simply run docker.

@IvRRimum
Copy link

I mean for imports:
Screenshot from 2021-12-14 20-07-08
You see the red underline?
I have these packages installed in a different directory, would be great if coc-pyright could use that dir.

@fannheyward
Copy link
Owner

@lyndsysimon this needs Pyright support, I don't know Pyright can handle this or not.

@cpfaff
Copy link

cpfaff commented May 10, 2022

microsoft/pyright#582

I guess one would need to make the environment accessible in a local volume. Then configure everything to use that path.

@0inp
Copy link

0inp commented Aug 25, 2022

Hi ! I'm also looking for a solution to this problem.
I've got several API's separated as different github repositories (so different directories on my computer). Every one of them is running in separated docker env (python + pipenv). Each API's got a different set of libraries.
When I'm working, I go to the directory of the API I want to edit and use neovim+coc+coc-pyright to code. With the docker mounted volumes, every changes in local file are mirrored inside the docker container. I would like pyright to use the python and pipenv commands of inside the container.
Is it possible ?

@IamGianluca
Copy link

IamGianluca commented Sep 1, 2022

Hi, I'm also working on doing something similar. I've installed the nvim-dev-container plugin and trying to make coc-pyright load the Python interpreter inside the dev container.

To do so, I've created a coc-settings.json and copied it inside the Docker container. Here I specified as python path the interpreter's location inside the dev container.

{
        "python.pythonPath": "/opt/conda/bin/python",
        "python.analysis.stubPath": "/workspace/src/typings"
}
$  docker exec -it busy_chatterjee /bin/bash
root@101060dd4bb2:/workspace# which python
/opt/conda/bin/python

All libraries installed through pip are available if I access the dev container.

$  docker exec -it busy_chatterjee /bin/bash
root@101060dd4bb2:/workspace# which python
/opt/conda/bin/python
root@101060dd4bb2:/workspace# python
Python 3.8.12 | packaged by conda-forge | (default, Jan 30 2022, 23:42:07)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import timm
>>>

coc-pyright also seems to be loading the interpreter from the right location (/opt/conda/bin/python).

:CocCommand workspace.showOutput Pyright
Workspace: /home/gianluca/git/kaggle/spine
Using python from /opt/conda/bin/python

[Info  - 6:23:36 PM] Pyright language server 1.1.269 starting
[Info  - 6:23:36 PM] Server root directory: /home/gianluca/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/
[Info  - 6:23:36 PM] Starting service instance "spine"
[Info  - 6:23:36 PM] No configuration file found.
[Info  - 6:23:36 PM] No pyproject.toml file found.
[Info  - 6:23:36 PM] Setting pythonPath for service "spine": "/opt/conda/bin/python"
[Warn  - 6:23:36 PM] stubPath /home/gianluca/git/kaggle/spine/typings is not a valid directory.
[Info  - 6:23:36 PM] Unable to get Python version from interpreter
[Info  - 6:23:36 PM] Assuming Python platform Linux
[Info  - 6:23:36 PM] Searching for source files
[Info  - 6:23:36 PM] Found 22 source files

However, I can't "jump to definition" for any library installed through pip while building the (dev) container.

The interesting thing is that coc-pyright can "jump to definition" for every class/function defined in a library I wrote and included in the Docker container inside the src/ folder.

I'm trying to debug the issue with the maintainer of the nvim-dev-container plugin here, but I suspect the issue might not be in that plugin. Perhaps I should change something in the coc-pyright/pyright settings? Any help would be appreciated 🙏

@webus
Copy link

webus commented Feb 15, 2023

Any updates?

@PHChenGit
Copy link

same here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants