Skip to content

Jupyter API to get Env associated with Notebooks - #24358

Closed
Don Jayamanne (DonJayamanne) wants to merge 2 commits into
mainfrom
don/issue15987
Closed

Jupyter API to get Env associated with Notebooks#24358
Don Jayamanne (DonJayamanne) wants to merge 2 commits into
mainfrom
don/issue15987

Conversation

@DonJayamanne

@DonJayamanne Don Jayamanne (DonJayamanne) commented Oct 30, 2024

Copy link
Copy Markdown

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.

Rich Chiodo (@rchiodo) Heejae Chang (@heejaechang) Erik De Bonte (@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.
Karthik Nadig (@karthiknadig) /cc

@rchiodo

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown

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

Don Jayamanne (DonJayamanne) commented Oct 30, 2024

Copy link
Copy Markdown
Author

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
Don Jayamanne (DonJayamanne) marked this pull request as ready for review February 3, 2025 02:15
@vs-code-engineering

Copy link
Copy Markdown

⚠️ This PR originates from a fork. Due to security restrictions, pipelines from forks are no longer triggered automatically. Learn more.

If the changes appear safe, you can manually trigger the pipeline by commenting /AzurePipelines run.

@DonJayamanne

Copy link
Copy Markdown
Author

Closing to push this branch upstream.

Don Jayamanne (DonJayamanne) added a commit that referenced this pull request Feb 4, 2025
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.

previous discussion here
#24358
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