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

Incorrect Jupyter notebookFileRoot when workspace has more than one folder #8561

Closed
joetoth opened this issue Dec 5, 2021 · 5 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug notebook-kernel Kernels issues (start/restart/switch/execution, install ipykernel) verified Verification succeeded
Milestone

Comments

@joetoth
Copy link

joetoth commented Dec 5, 2021

Issue Type: Bug

I have 2 folders in a workspace, First and Second.

I tried setting "jupyter.notebookFileRoot": "${workspaceFolder}/Second" in the workspace, user, and project json files.

But, no matter how I start a Jupyter Interactive Window (from a file open from Second) the interpreter's root is always First.

I switched the order of the "folders" in the workspace file to:

"folders": [
	{
		"path": "Second"
	},
	{
		"path": "First"
	}

]

Now it "works", the interpreter's root is Second.

VS Code version: Code - Insiders 1.63.0-insider (Universal) (d09289a2b6dd0e56b2a264a8e9380685498e10d6, 2021-12-04T02:02:08.723Z)
OS version: Darwin x64 21.1.0
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz (16 x 2300)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 4, 4, 3
Memory (System) 32.00GB (4.71GB free)
Process Argv --crash-reporter-id 8302b51b-7f2b-4d74-9873-4b0d4892aed7
Screen Reader no
VM 0%
Extensions (29)
Extension Author (truncated) Version
vscode-bazel Baz 0.5.0
vscode-eslint dba 2.2.2
gitlens eam 11.7.0
vscode-pull-request-github Git 0.32.0
markdown-math koe 0.1.0
vscode-docker ms- 1.18.0
python ms- 2021.12.1522449417-dev
vscode-pylance ms- 2021.12.1-pre.1
jupyter ms- 2021.11.1001532801
jupyter-keymap ms- 1.0.0
jupyter-renderers ms- 1.0.4
remote-containers ms- 0.209.0
remote-ssh ms- 0.66.1
remote-ssh-edit ms- 0.66.1
remote-wsl ms- 0.63.4
vscode-remote-extensionpack ms- 0.21.0
cmake-tools ms- 1.9.2
cpptools ms- 1.7.1
sqltools mtx 0.23.0
sqltools-driver-sqlite mtx 0.2.0
vscode-vega-viewer Ran 9.5.0
rust rus 0.7.8
gruvbox-material sai 6.4.6
vscode-3dviewer sle 0.2.2
even-better-toml tam 0.14.2
vscode-icons vsc 11.8.0
vim vsc 1.21.10
markdown-all-in-one yzh 3.4.0
vscode-proto3 zxh 0.5.5

(7 theme extensions excluded)

@rebornix rebornix transferred this issue from microsoft/vscode Dec 16, 2021
@rebornix rebornix removed their assignment Dec 16, 2021
@rchiodo rchiodo added interactive-window Impacts interactive window and removed needs-triage labels Dec 16, 2021
@rchiodo rchiodo added this to the January 2022 milestone Dec 16, 2021
@rchiodo
Copy link
Contributor

rchiodo commented Dec 16, 2021

Thanks for the bug. We'll investigate come January.

@greazer greazer added bug Issue identified by VS Code Team member as probable bug notebook-kernel Kernels issues (start/restart/switch/execution, install ipykernel) and removed interactive-window Impacts interactive window labels Jan 6, 2022
@IanMatthewHuff IanMatthewHuff self-assigned this Jan 7, 2022
@IanMatthewHuff
Copy link
Member

IanMatthewHuff commented Jan 7, 2022

@joetoth Just picking this up to look into now. Initial I'm not seeing the same issue that you are, but I'm not 100% sure if I have my setup the same as yours is. What I did was the following:

image

  1. Workspace side by side in a folder with sibling folders first and second
  2. First and second have their own test.py files and python interpreters
  3. Set Notebook File Root at the workspace level to always point at the Second folder
  4. Execute the python file in First folder, I get the .firstEnv interpreter and the notebook root set to the Second folder

Does that look the same as your setup?

edit: On closer looks looks like you might have the following setup:

Root Folder
    workspace file
    First
        first.py
    Second
        second.py

Which is a bit different from mine which was:

Root Folder
    Workspace
        workspace file
    First
        first.py
    Second
        second.py

Let me try that setup as well.

Apologies that scenario does indeed not seem to respect the notebookFileRoot setting. Looking into it now.

@joetoth
Copy link
Author

joetoth commented Jan 8, 2022

Here is an easy way to reproduce.

Create a project /Users/joetoth/projects/1 and another /Users/joetoth/projects/2
Create a workspace and add them both. Assign different Python interpreters to each.
I have Jupyter: Interactive Window Mode set to perFile.

Now open a file from 1 and Run line in interactive window. The correct interpreter opens, the line is run and pwd returns /Users/joetoth/projects/1

Next open a file from 2, run a line, the correct interpreter opens, then line is run, BUT pwd returns /Users/joetoth/projects/1, when I expect it to return 2.

Let me know if you require further information.

Thanks a bunch!

@IanMatthewHuff
Copy link
Member

I believe that I have a fix for this issue here. My fix is only addressing the issue with the notebookFileRoot setting for multi root workspaces. I believe that there might be a different issue here regarding this that I think might need a usage change:

This specification here I believe is off:
"jupyter.notebookFileRoot": "${workspaceFolder}/Second"

I didn't actually know this myself (don't work with many multi root workspaces) but the VS Code variables actually resolve relative to the folder of the file that is being worked with. So for a file second.py that is in a folder "/Second" the example above would resolve to "MyDirectory/Second/Second" instead of "MyDirectory/Second" since that path doesn't exist it would ignore the notebookFileRoot setting.

See here:
https://code.visualstudio.com/docs/editor/multi-root-workspaces

Variables used in a configuration (for example ${workspaceFolder} or the now deprecated ${workspaceRoot}) are resolved relative to the folder they belong to. It is possible to scope a variable per workspace folder by appending the root folder's name to a variable (separated by a colon).

However regardless of that we did have an issue here where when calculating the startup directory we were not passing the file being opened so we were always just taking the first setting that applied (whatever the setting was for First folder in this case) which I have a fix coming up soon for.

@IanMatthewHuff
Copy link
Member

Note for bug validation:

  1. Setup a multi-root workspace with two folders
  2. In each folder, change the value of notebookFileRoot to something unique
  3. Run both files in the interactive window and check the working directory

Old code:
image

With my fix:
image

Note that the "/Documents" is correct for the settings for Folder "Second".

@JacksonKearl JacksonKearl added the verified Verification succeeded label Jan 28, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug notebook-kernel Kernels issues (start/restart/switch/execution, install ipykernel) verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants