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

support multiple venvs in a monorepo #88

Open
randomphrase opened this issue Sep 30, 2023 · 0 comments
Open

support multiple venvs in a monorepo #88

randomphrase opened this issue Sep 30, 2023 · 0 comments

Comments

@randomphrase
Copy link

Hi, I am attempting to use lsp-pyright with a monorepo and multiple venvs. There is an example repo here which can be used to demonstrate the problem. Specifically:

  1. Clone the repo, and create two venvs, one for libs/base and one for libs/fancy. The specific instructions are here under the heading "Sandboxes". This should result in two .venv directories within the two library directories.
  2. In emacs, open libs/base/adder2.py and ensure that lsp mode is active. This should start pyright.
  3. Use lsp-workspace-folders-add to add the libs/base and libs/fancy folders.
  4. Restart pyright.

If I understand correctly, the above steps should result in Pyright correctly able to resolve both internal and external dependencies. However it does not seem to. The problem, I believe, stems from setting the pythonPath incorrectly. Here is an extract from the *lsp-log* buffer.

Setting pythonPath for service "fancy": "/Users/alastair/hack/extern/python-monorepo-example/libs/base/.venv/bin/python"
Loading pyproject.toml file at /Users/alastair/hack/extern/python-monorepo-example/libs/fancy/pyproject.toml
Assuming Python version 3.11
No include entries specified; assuming /Users/alastair/hack/extern/python-monorepo-example/libs/fancy
Auto-excluding **/node_modules
Auto-excluding **/__pycache__
Auto-excluding **/.*
Found 4 source files
Setting pythonPath for service "base": "/Users/alastair/hack/extern/python-monorepo-example/libs/base/.venv/bin/python"
Loading pyproject.toml file at /Users/alastair/hack/extern/python-monorepo-example/libs/base/pyproject.toml
Assuming Python version 3.11
No include entries specified; assuming /Users/alastair/hack/extern/python-monorepo-example/libs/base
Auto-excluding **/node_modules
Auto-excluding **/__pycache__
Auto-excluding **/.*
Found 4 source files
Setting pythonPath for service "python-monorepo-example": "/Users/alastair/hack/extern/python-monorepo-example/libs/base/.venv/bin/python"
Loading pyproject.toml file at /Users/alastair/hack/extern/python-monorepo-example/pyproject.toml
Pyproject file "/Users/alastair/hack/extern/python-monorepo-example/pyproject.toml" is missing "[tool.pyright]" section.
Assuming Python version 3.11
Found 14 source files

Note specifically that the base venv is used for the fancy service. This is evident from the pythonPath setting.

Apologies if I have misunderstood something, but I believe this is a bug in lsp-pyright, and it should instead pick up the correct .venv directory for each workspace folder (a.k.a. service IIUC).

As an additional observation, I also attempted to get this to work by setting lsp-pyright-venv-directory and creating named venvs in that directory, with corresponding venv settings in each library's pyright.toml. This did not work either, as - again - the pythonPath was set to something completely different and incorrect, namely the system python instance.

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

1 participant