Skip to content

Expose a unified way to retrieve Python Env Associated with Jupyter NotebooksΒ #15987

@DonJayamanne

Description

@DonJayamanne

Currently there's a private API that Pylance gets to use in order to determine the Python Env associated with Jupyter notebooks.
Unfortunately there are a few problems with this API:

  • Its built specifically for Pylance, other extensions cannot get this same information
  • Upon selecting a new Kernel, the Pylance extension won't always know that a new Python Env has been selected for a Jupyter Notebook
  • The API is inconsistent, currently there's an API in Python extension to get the Python Env associated with a Uri, but Jupyter Notebooks is not part of this (when Jupyter Notebooks are also just Uris).

Pros:

  • Unified approach to getting Python Environments for notebooks, Python files, workspaces etc.
  • No code change for extensions consuming the Python API
  • Resolves some bugs as well

Solution:

  • Keep the Python extension + Jupyter Extension API internal (as today)
  • Update the Python extension as follows:
export type ActiveEnvironmentPathChangeEvent = EnvironmentPath & {
    /**
     * Workspace folder the environment changed for.
     * Or Resource the environment changed for.
     */
    readonly resource: WorkspaceFolder | Uri | undefined;
};

Internally, the call to getActiveEnvironmentPath(resource?: Resource): EnvironmentPath; would now handle Uris a little differently. If the Uri is a notebook Uri, then get the interpreter from Jupyter extension (using existing code).
The check if the Uri is a notebook can optionally be passed into Jupyter as well, i.e. keep it super simple.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions