basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

Editable modules installed by uv aren't found

Open krmax44 opened this issue 1 year ago • 4 comments

I'm using uv as my package manager. When I install modules as editable (with -e), the module cannot be resolved by Pyright: Import mymodule could not be resolved. basedpyright(reportMissingImports)

With verbose output enabled, there is one potentially interesting message logged:

Skipping '__editable__.mymodule-1.0.0.finder.__path_hook__' because it is not a valid directory

uv does seem to create a .pth though. In this case, it's located at .venv/lib/python3.12/site-packages/__editable__.mymodule-1.0.0.pth and contains:

import __editable___mymodule_1_0_0_finder; __editable___mymodule_1_0_0_finder.install()

The referenced module contains the MAPPING and NAMESPACES.

When I install the module without -e, the types are found.

krmax44 avatar Oct 02 '24 10:10 krmax44

i'm not really familiar with how editable packages work, but i wasn't able to reproduce the issue by running uv pip install -e . on my project

  • what command are you running exactly?
  • what's your pyproject.toml & project structure look like?
  • how are you running basedpyright? CLI (if so, what command?) or language server (if so, which editor?)
  • are you able to check if the issue also occurs in pyright?

thanks

DetachHead avatar Oct 03 '24 10:10 DetachHead

Sorry, should have been more specific here. It's happening when installing another package as editable, like uv pip install -e /my/project/somewhere. I'm using basedpyright in VS Codium with the Pylance language server. I have nothing regarding basedpyright in my pyproject.toml, the only thing configured is type checking set to basic via VS Code.

krmax44 avatar Oct 03 '24 14:10 krmax44

hmm, i'm still not able to reproduce it. according to the documentation about editable installs, it should work as long as it uses .pth files with file paths in them, which as far as i can tell is what uv already does by default.

after you install the package as editable, can you try restarting the language server and see if the issue persists? (F1 > "Tasks: Run Task" > "basedpyright: Restart Server")

DetachHead avatar Oct 12 '24 02:10 DetachHead

oh wait i think i misunderstood how this works.

that config is specified on the build backend, as in the build tool on the package you're installing rather than what you're installing it with. from my understanding uv does not have a build backend yet (https://github.com/astral-sh/uv/issues/3957), so the way to get your package to work with (based)pyright depends on whatever build backend it uses. hope the documentation i linked in the previous comment helps

DetachHead avatar Oct 12 '24 02:10 DetachHead

closing this as i'm pretty sure my comment above explains the situation. i also clarified the docs in #770.

let us know if you're still having issues and we can re-open this if needed

DetachHead avatar Oct 18 '24 11:10 DetachHead

Thanks, that works perfectly. Just to leave the solution right here, one can use either uv pip install -e /path/to/module --config-setting editable_mode=compat or set an option in the pyproject.toml.

krmax44 avatar Oct 21 '24 07:10 krmax44