pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Highlighting fails after switching between monorepo projects (when switching python interpreters)

Open alita-moore opened this issue 8 months ago • 30 comments

Applies To

  • [X] Notebooks (.ipynb files)
  • [ ] Interactive Window and/or Cell Scripts (.py files with #%% markers)

What happened?

Basically, I expect the highlighting on the Jupyter notebook to update when I switch from one project to another. However, when I switch from one project to another it fails to update the highlighting until I either reload the window or I restart the extension host. Note that normal python files highlight just fine.

To reproduce this see the following codesandbox

After you've loaded into the codesandbox, open it in vscode. Make sure that you have the following extensions:

  1. pylance
  2. jupyter
  3. python envy (teticio.python-envy)

open "third_project/another_one.ipynb" and select the appropriate .venv which is located at "third_project/.venv". Notice that things are highlighting. Screenshot 2024-06-08 at 11 55 42 PM

open other_project/init.py

You can also get here by navigating to the definition of the "other_project" module. Notice that python envy changes the interpreter. Screenshot 2024-06-08 at 11 58 07 PM

Now navigate back to the "third_project/another_one.ipynb". If you're "lucky" you'll see that when you scroll down and then back up (to force re-draw the highlihgts) that sometimes it freezes. When it freezes like this it's frozen indefinitely. Screenshot 2024-06-09 at 12 01 44 AM

NOTE:

  1. It may be somewhat difficult to reproduce the results, and you may have to go back and forth between notebooks / files quickly in order to overload the system and then force the behavior. However, note that in larger codebases it happens nearly every time you switch between notebooks / project interpreters.
  2. I am using poetry to import from other modules in the monorepo using their relative path importing system

VS Code Version

1.90.0

Jupyter Extension Version

v2024.5.0

Jupyter logs

Visual Studio Code (1.90.0, ssh-remote, desktop)
Jupyter Extension Version: 2024.5.0.
Python Extension Version: 2024.8.0.
Pylance Extension Version: 2024.6.1.
Platform: linux (x64).
Workspace folder /project/workspace, Home = /root
14:55:37.492 [info] Starting Kernel (Python Path: /project/workspace/third_project/.venv/bin/python, Poetry, 3.8.19) for '/project/workspace/third_project/another_one.ipynb' (disableUI=true)
14:55:38.300 [info] Process Execution: /project/workspace/third_project/.venv/bin/python -m pip list
14:55:38.367 [info] Process Execution: /project/workspace/third_project/.venv/bin/python -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
14:55:38.382 [info] Process Execution: /project/workspace/third_project/.venv/bin/python -m ipykernel_launcher --f=/~/.local/share/jupyter/runtime/kernel-v2-18791fQR1MB8Io0Zd.json
    > cwd: //project/workspace/third_project
14:55:40.250 [info] Kernel successfully started
14:55:40.270 [info] Process Execution: /project/workspace/third_project/.venv/bin/python /~/.vscode-server/extensions/ms-toolsai.jupyter-2024.5.0-linux-x64/pythonFiles/printJupyterDataDir.py
14:58:47.202 [info] Starting Kernel (Python Path: /project/workspace/.venv/bin/python, Poetry, 3.8.19) for '/project/workspace/notebook.ipynb' (disableUI=true)
14:58:48.116 [info] Process Execution: /project/workspace/.venv/bin/python -m pip list
14:58:48.189 [info] Process Execution: /project/workspace/.venv/bin/python -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
14:58:48.206 [info] Process Execution: /project/workspace/.venv/bin/python -m ipykernel_launcher --f=/~/.local/share/jupyter/runtime/kernel-v2-18791DaYZEb5bjEdQ.json
    > cwd: //project/workspace
14:58:50.302 [info] Kernel successfully started
14:58:50.317 [info] Process Execution: /project/workspace/.venv/bin/python /~/.vscode-server/extensions/ms-toolsai.jupyter-2024.5.0-linux-x64/pythonFiles/printJupyterDataDir.py
14:58:57.241 [info] Starting Kernel (Python Path: /project/workspace/other_project/.venv/bin/python, Poetry, 3.8.19) for '/project/workspace/other_project/other.ipynb' (disableUI=true)
14:58:57.949 [info] Process Execution: /project/workspace/other_project/.venv/bin/python -m pip list
14:58:58.162 [info] Process Execution: /project/workspace/other_project/.venv/bin/python -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
14:58:58.192 [info] Process Execution: /project/workspace/other_project/.venv/bin/python -m ipykernel_launcher --f=/~/.local/share/jupyter/runtime/kernel-v2-18791UmM5kZOsfZ8o.json
    > cwd: //project/workspace/other_project
14:59:00.672 [info] Kernel successfully started
14:59:00.691 [info] Process Execution: /project/workspace/other_project/.venv/bin/python /~/.vscode-server/extensions/ms-toolsai.jupyter-2024.5.0-linux-x64/pythonFiles/printJupyterDataDir.py

Coding Language and Runtime Version

python v3.8

Language Extension Version (if applicable)

Pylance v2024.6.1

Anaconda Version (if applicable)

No response

Running Jupyter locally or remotely?

Remote

alita-moore avatar Jun 08 '24 15:06 alita-moore