#VScode IDE integration issue with Dagger python SDK

1 messages Β· Page 1 of 1 (latest)

turbid bobcat
#

Hello!

I'm having an issue with dagger integration with my IDE (vscode), where imports are not resolved despite all CLI calls working as expected.

What I did:

  • I'm using uv to handle my project dependencies.

What I did:

  • I've installed v0.15.2 on Linux using Brew.
  • When initializing dagger in my project
dagger init --sdk=python --source=./dagger

Observations:

  • When importing sub-modules from dagger, the IDE complains "Container" is unknown import symbol
from dagger import Container, Ignore, Secret, dag, function, object_type 
  • I can get right of these IDE messages by adding dagger-io in my application pyproject.toml
uv add dagger-io
  • However, it now creates a new warning on third-party modules from Daggerverse that cannot be resolved: Cannot access member "hello" for type "Client" Member "hello" is unknown
async def greeting(self) -> str:
   return await dag.hello().hello()

I've followed the Dagger doc on IDE integration but am stuck on these issues. Is there something I'm missing, or is this expected?
I appreciate any help you can provide.

Jean-Paul

pale citrus
#

Hi! πŸ‘‹

#

You don't need to add the dagger-io library. When you did dagger init it was already created with the right value. When you did uv add dagger-io that replaced the vendored client library (in ./sdk) with the one published in PyPI, however that one only has the core API, not your dependencies from daggerverse.

To fix it, recover with:

uv add --editable ./sdk
#

In VS Code it makes a difference if you're opening your module at the root of the VS Code workspace or not. If it's at the root then VS Code detects it automatically, you just have to make sure you have the Python virtual environment set up. You can do it with:

uv sync

That'll make sure the environment is installed correctly locally, in a .venv folder which VS Code should pick up on its own.

turbid bobcat
#

Hi thanks for your help.
Should both commands be run from root directory OR dagger/ ? Running it from dagger folder created another .venv, but the default interpreter is still using the .venv from the root.

#

Here is my repo structure

.
β”œβ”€β”€ .venv
β”œβ”€β”€ uv.lock
β”œβ”€β”€ pyproject.toml
β”œβ”€β”€ app/
β”‚   └── (application code)
└── dagger/
    β”œβ”€β”€ .venv
    β”œβ”€β”€ uv.lock
    β”œβ”€β”€ pyproject.toml
    β”œβ”€β”€ sdk/
    β”‚   └── ...
    β”œβ”€β”€ src/
    β”‚   └── app/

The issue is i can only select one python interpreter at a time.
When using interpreter path .venv/bin/python, my IDE complains about all code in dagger/
When using interpreter path dagger/.venv/bin/python, my IDE doesn't complain anymore about code in dagger/, but now all my code in app/ at the root

#

To start from scratch, I have deleted the folder dagger + dagger.json and followed the docs in the IDE integration. The issue persists.
Possibly an issue with VSCode itself, unable to pick up the right interpreter based on file location?

dagger init --sdk=python --source=./dagger
dagger develop
cd dagger
uv sync
#

My only solution was to add dagger-io in the root pyproject.toml to remove warnings, but the third party modules are not handled with this hack

pale citrus
#

Dagger modules using the Python SDK are normal Python projects. The easiest solution is to develop dagger modules in their own VS Code windows.

To use a single window you need to look into working with a Python monorepo in VS Code, where there’s separate virtual environments.

turbid bobcat
#

This is neat thanks a lot for your guidance

turbid bobcat
#

I've been digging into this topic. Monorepo support is still under active development in VS Code
https://github.com/microsoft/vscode-python/issues/21204#issuecomment-1603329727
This is especially true if you have a root workspace, and folders sub-workspaces, like after dagger init

GitHub

We talked to a lot of folks at PyCon that were complaining about our support for mono repos. This issue is to track feedback about this experience. Current hypothesis is that our multiroot support ...