jupyterlab-lsp icon indicating copy to clipboard operation
jupyterlab-lsp copied to clipboard

Can Jupyterlab-lsp/pyright work with custom pyrightconfig.json or pyproject.toml files?

Open sntgluca opened this issue 2 years ago • 6 comments

Elevator Pitch

I'd like that pyright would be able to recognise the custom pyrightconfig.json or pyproject.toml foles in my projects, as described in the pyright documentation.

Motivation

I usually work with a central version of JupyterLab (via JupyterHub), and use different conda environments/kernels to run specific code for my projects. To the best of my understanding, currently pyright recognises only the content from the central environment running Jupyterlab, but doesn't recognise the content from a kernel environment. Being able to setup pyright based on different projects and dedicated environments would greatly improve the user experience, removing side-effect errors and warnings, and allowing more flexibility in the setup of my environments and project structures.

Design Ideas

I don't know enough about the implementation to share hints on this topic. I hope this can be addressed via pyright configuration.

Thank you for considering this feature :)

sntgluca avatar Feb 06 '22 21:02 sntgluca

Sorry for the late response, but I would have thought that it already works. Have you encountered problem with either of these approaches?

krassowski avatar Feb 15 '22 20:02 krassowski

Dear @krassowski ,

I have been swamped by other things I could not follow up. I made several attempts, and for me it doesn't work.

I can't exclude a PEBKAC here, but I was able to make something work with VSCode, on the same directory, while JupyterLab doesn't show any difference.

If there's someone who can share a working config, I would appreciate it

sntgluca avatar Apr 09 '22 08:04 sntgluca

I wish to share a couple of screenshots to show what I mean:

I setup a simple example as follows

|-- package/
|    |-- lib.py
|-- test/
|   |-- pyrightconfig.json
|   |-- test.py

I started VSCode and JupyterLab from the test directory, setting pyrightconfig.json to look for packages in .., to find package. VSCode is able to resolve the path, while JupyterLab doesn't

Screenshot 2022-04-09 at 12 05 43 Screenshot 2022-04-09 at 12 08 17

Same file, same starting directory. It's nothing more than annoying, but it would be so nice if it could be investigated by some expert.

Thank you, Gianluca

sntgluca avatar Apr 09 '22 10:04 sntgluca

I am also having problems trying to get pyright to be able to find imports from my current virtual environment by setting venv and venvPath in a pyrightconfig.json file

j-carson avatar Feb 03 '23 19:02 j-carson

After some experimenting, I have found that if we place the pyproject.toml file inside the directory where we install pyright, the pyright server launched by jupyter-lsp will try to read the configuration file.

For example, if we install pyright in a node_modules directory located at C:/path/to/node_modules/, we can go to C:/path/to/node_modules/pyright/dist/, and create a pyproject.toml file there. From my experience, pyright will be able to recognize it, and no more missing imports!

I don't know why pyright tries to load config files from that directory instead of the jupyter root content directory. My guess is that jupyter-lsp does not pass the correct working directory to pyright, and pyright choose the .js entry file's path as its working directory.

However, although the auto-completion and hinting works now, jump-to-definition functionality seems to be broken when using pyright. I have just filed #1005 describing this in detail.

rk-terence avatar Oct 27 '23 04:10 rk-terence