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

Jupyter API to get Env associated with Notebooks #24358

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DonJayamanne
Copy link

@DonJayamanne DonJayamanne commented Oct 30, 2024

See microsoft/vscode-jupyter#15987

Should also fix microsoft/vscode-jupyter#16112
Should also avoid Pylance having to monitor notebook changes and then trying to figure out the Environment for a Notebook.

@rchiodo @heejaechang @debonte Please can you let me know if this works
I.e. going forward (we can plan how we roll this out)

  • Pylance can use just Python extension API to get Python environment for a Uri (the uri can be a Notebook or IW uri)
  • If the kernel is changed, the event onDidChangeActiveEnvironmentPath will be triggered with the corresponding Uri
  • If a kernel is changed to say a Non Python Kernel, then its triggered again, but the active interpreter for that Uri will be the same as the worksapce interpreter

I believe this should simplify things.
@karthiknadig /cc

@DonJayamanne DonJayamanne added the no-changelog No news entry required label Oct 30, 2024
@rchiodo
Copy link

rchiodo commented Oct 30, 2024

Pylance having to monitor notebook changes

For what it's worth, we don't do this now. The vscode-languageclient-npm module does. So theoretically any language can listen for notebook events, not just Pylance.

@DonJayamanne
Copy link
Author

So theoretically any language can listen for notebook events, not just Pylance.

How does Pylance get the Python env associated with a notebook?

@rchiodo
Copy link

rchiodo commented Oct 30, 2024

How does Pylance get the Python env associated with a notebook?

We ask the python extension for the environment for the current file. This happens after we get the notebook changed event.

@DonJayamanne
Copy link
Author

DonJayamanne commented Oct 30, 2024

We ask the python extension for the environment for the current file.

awesome, then this change will make this workflow work properly

What I'm getting at is Pylance will not need the registerJupyterPythonPathFunction (private) api anymore and you can use the official Python extension API. this way others language servers can benefit from this, else if some other extension like Ruff or Jedi (if there were other extension) need this, then they would need a new API or a similar hook...

I.e. just use getActiveEnvironmentPath(resource?: Resource): EnvironmentPath
and onDidChangeActiveEnvironmentPath to detect changes to Python envs associated with Notebooks and the like (still free to use notebook change events as well).

@DonJayamanne DonJayamanne marked this pull request as ready for review December 29, 2024 13:28
@DonJayamanne DonJayamanne marked this pull request as draft December 29, 2024 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog No news entry required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Choosing a kernel for the first time does not cause a kernel change event
2 participants