Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

lsp-python-ms-locate-python locates the wrong python instance #122

Closed
@randomphrase

Description

@randomphrase

I am using Conda but I believe this problem can be exhibited with other virtual envs. Here is my (simplified) directory heirarchy:

  • venv
    • aaa_env
      • bin
        • python (executable)
    • zzz_env
      • bin
        • python (executable)
      • src
        • my_file.py (source)

Basically the problem is that when loading my_file.py the wrong python interpreter is located. This can be verified by calling (lsp-python-ms-locate-python "/path/to/venv/zzz_env/src/my_file.py"), which results in /path/to/venv/aaa_env/bin/python. I would expect it to locate the python in the containing environment, namely /path/to/venv/zzz_env/bin/python.

I believe the problem is caused by the lsp-python-ms--dominating-venv-python function, namely:

(defun lsp-python-ms--dominating-venv-python (&optional dir)
  "Look for directories that look like venvs"
  (let* ((path (or dir default-directory))
         (dominating-venv (locate-dominating-file path #'lsp-python-ms--venv-dir)))
    (when dominating-venv
      (lsp-python-ms--venv-python (lsp-python-ms--venv-dir dominating-venv)))))

Here, the dominating-venv symbol is set to the directory containing the virtual envs, which in my case is ~/venv. The subsequent call to lsp-python-ms--venv-dir picks the first virtual environment in this directory, namely ~/venv/aaa_env.

I believe it should be using the lsp-python-ms--venv-python predicate to locate-dominating-file instead.

Please let me know if my description is not clear or if I can provide any further details. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions