Skip to content

Attempt to specify a venv for jupyter - #3607

Open
Andrew Casey (amcasey) wants to merge 6 commits into
mainfrom
amcasey/PickKernel
Open

Attempt to specify a venv for jupyter#3607
Andrew Casey (amcasey) wants to merge 6 commits into
mainfrom
amcasey/PickKernel

Conversation

@amcasey

Copy link
Copy Markdown
Member

Use some undocumented APIs to detect changes to, read, and set notebook python environments.

On open, look for a per-course value persisted in qdk-learning.json. If there isn't one, look for a virtual environment in the learning workspace root (typically, the workspace root).

When the user sets an environment, persist it per-course in qdk-learning.json.

The code assumes the undocumented APIs might change or disappear. If we lose reading or events, we'll still try to specify the heuristically chosen environment. If we lose writing, then reading is kind of moot.
The ultimate fallback is the behavior from before this PR: let jupyter and/or the user choose an environment for each notebook.

Use some undocumented APIs to detect changes to, read, and set notebook python environments.

On open, look for a per-course value persisted in qdk-learning.json.
If there isn't one, look for a virtual environment in the learning workspace root (typically, the workspace root).

When the user sets an environment, persist it per-course in qdk-learning.json.

The code assumes the undocumented APIs might change or disappear.
If we lose reading or events, we'll still try to specify the heuristically chosen environment.
If we lose writing, then reading is kind of moot.
The ultimate fallback is the behavior from before this PR: let jupyter and/or the user choose an environment for each notebook.
@amcasey

Copy link
Copy Markdown
Member Author

Full disclosure: there's a semi-official process for calling "prototype" APIs that we're not following - we're just using introspection to pull out the functions we want.

return saved;
}
log.info(
`Persisted venv at ${saved.path} no longer exists; falling back to discovery.`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this correctly, a potential issue may be if a user is using a venv that is NOT the global venv, but is also not in the workspace. It's quite common folks folks to create venvs under their home directory and use those across projects (e.g. ~/.venv). As that is not under the workspace, and uriExists uses workspace APIs to try and find it, would this fail in that scenario? (i.e. not honor the saved kernel)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware VS Code's file APIs restricted themselves to workspace files. If that's the case, then yes, it should probably do a raw stat, assuming such an API is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants