Attempt to specify a venv for jupyter - #3607
Conversation
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.
|
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.`, |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
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.