vscode-jupyter icon indicating copy to clipboard operation
vscode-jupyter copied to clipboard

[interactive-window] "Create Interactive Window" command does not open in the current work directory

Open WilianZilv opened this issue 3 years ago • 9 comments

Environment data

  • VS Code version: 1.67.0 (user setup)
  • Jupyter Extension version: v2022.4.1001271738
  • Python Extension version: v2022.6.0
  • OS: Windows 11
  • Python version: 3.7.3
  • Type of virtual environment used: N/A
  • Jupyter server running: Local

Expected behaviour

When run the command "Jupyter: Create Interactive Window" (jupyter.createnewinteractive) The python interactive window should open on the current project's folder as working directory, which can be seen with line command pwd

Actual behaviour

The python interactive window opens in the first folder of the workspace.

Steps to reproduce:

  1. Add 2 sample folder (Ex: project-1 and project-2), in a empty workspace, each folder containing an empty "main.py" file.
  2. Open project-2/main.py (or the last folder in your workspace).
  3. Run the command "Jupyter: Create Interactive Window".
  4. Verify the current work directory with command pwd in the opened Python Interactive Window

gif

Logs

Output for Jupyter in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Jupyter)

info 17:11:25.936: Starting interactive window for resoruce 
info 17:11:25.992: TargetController found ID: .jvsc74a57bd008bb98ca2d6689b39b6f979a5f9bf126935b1dd434099537d44d1a8671c31e85.c:\Users\Wilian\AppData\Local\Programs\Python\Python37\python.exe.c:\Users\Wilian\AppData\Local\Programs\Python\Python37\python.exe.-m#ipykernel_launcher (Interactive) for document Interactive-1.interactive
info 17:11:26.14: Process Execution: > ~\AppData\Local\Programs\Python\Python37\python.exe -m pip list
> ~\AppData\Local\Programs\Python\Python37\python.exe -m pip list
info 17:11:26.111: Starting Notebook id = .jvsc74a57bd008bb98ca2d6689b39b6f979a5f9bf126935b1dd434099537d44d1a8671c31e85.c:\Users\Wilian\AppData\Local\Programs\Python\Python37\python.exe.c:\Users\Wilian\AppData\Local\Programs\Python\Python37\python.exe.-m#ipykernel_launcher for Interactive-1.interactive (disableUI=false)
info 17:11:26.112: Creating raw notebook for 
info 17:11:26.112: Computing working directory 
info 17:11:26.112: Starting raw kernel Python 3.7.3 64-bit for interpreter c:\Users\Wilian\AppData\Local\Programs\Python\Python37\python.exe
info 17:11:26.127: Process Execution: > ~\AppData\Local\Programs\Python\Python37\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
> ~\AppData\Local\Programs\Python\Python37\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
info 17:11:26.177: Kernel launching with ports 9000,9001,9002,9003,9004. Start port is 9000
info 17:11:26.218: Creating daemon process for c:\Users\Wilian\AppData\Local\Programs\Python\Python37\python.exe with env variables count 70
info 17:11:26.222: Process Execution: > ~\AppData\Local\Programs\Python\Python37\python.exe -m vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_interrupt_daemon -v --ppid 23792
> ~\AppData\Local\Programs\Python\Python37\python.exe -m vscode_datascience_helpers.daemon --daemon-module=vscode_datascience_helpers.kernel_interrupt_daemon -v --ppid 23792
info 17:11:26.313: get interrupthandle daemon
info 17:11:26.316: Process Execution: > ~\AppData\Local\Programs\Python\Python37\python.exe -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"ddcbf33d-ccd9-4358-919e-a7e3cafa85eb" --shell=9002 --transport="tcp" --iopub=9004 --f=c:\Users\Wilian\AppData\Roaming\jupyter\runtime\kernel-23792zWQ0Q8r1Myn5.json
> ~\AppData\Local\Programs\Python\Python37\python.exe -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"ddcbf33d-ccd9-4358-919e-a7e3cafa85eb" --shell=9002 --transport="tcp" --iopub=9004 --f=c:\Users\Wilian\AppData\Roaming\jupyter\runtime\kernel-23792zWQ0Q8r1Myn5.json
info 17:11:26.316: Process Execution: cwd: c:\Projetos\project-1
cwd: c:\Projetos\project-1
info 17:11:26.371: ipykernel version 6.13.0 for c:\Users\Wilian\AppData\Local\Programs\Python\Python37\python.exe
info 17:11:26.371: ipykernel location ~\AppData\Local\Programs\Python\Python37\lib\site-packages\ipykernel\__init__.py for c:\Users\Wilian\AppData\Local\Programs\Python\Python37\python.exe
warn 17:11:27.29: StdErr from Kernel Process c:\Users\Wilian\AppData\Local\Programs\Python\Python37\lib\site-packages\traitlets\traitlets.py:2205: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use 'hmac-sha256' instead of '"hmac-sha256"' if you require traitlets >=5.
  FutureWarning)
c:\Users\Wilian\AppData\Local\Programs\Python\Python37\lib\site-packages\traitlets\traitlets.py:2160: FutureWarning: Supporting extra quotes around Bytes is deprecated in traitlets 5.0. Use 'ddcbf33d-ccd9-4358-919e-a7e3cafa85eb' instead of 'b"ddcbf33d-ccd9-4358-919e-a7e3cafa85eb"'.
  FutureWarning)

info 17:11:27.75: Kernel Output: NOTE: When using the `ipython kernel` entry point, Ctrl-C will not work.

To exit, you will have to explicitly quit this process, by either sending
"quit" from a client, or using Ctrl-\ in UNIX-like environments.

To read more about this, see https://github.com/ipython/ipython/issues/2049


To connect another client to this kernel, use:
    --existing c:\Users\Wilian\AppData\Roaming\jupyter\runtime\kernel-23792zWQ0Q8r1Myn5.json

info 17:11:27.166: Started kernel Python 3.7.3 64-bit, (Raw session started and connected)
info 17:11:27.167: Finished connecting 8e6fbbd7-c72a-4f63-92b1-8990dfbbae25
info 17:11:27.187: UpdateWorkingDirectoryAndPath in Kernel
info 17:11:27.189: Executing silently Code (idle) = import types as _VSCODE_types\nimport os\nimport hashlib as _VSCODE_hashlib\nfrom IPython import get_ip
info 17:11:27.216: Executing silently Code (completed) = import types as _VSCODE_types\nimport os\nimport hashlib as _VSCODE_hashlib\nfrom IPython import get_ip
info 17:11:27.216: Executing silently Code (idle) = %load_ext autoreload\n%autoreload 2
info 17:11:27.246: Executing silently Code (completed) = %load_ext autoreload\n%autoreload 2
info 17:11:27.246: Waiting for idle on (kernel): ed968a9d-860d-4eac-b030-79a1ded15251 -> idle
info 17:11:27.246: Finished waiting for idle on (kernel): ed968a9d-860d-4eac-b030-79a1ded15251 -> idle
info 17:11:48.520: Execute Cell 1 Interactive-1.interactive
info 17:11:48.595: Cell 1 executed with state Success

Considerations

It always worked until i did a clean uninstall and install today. Also, i have "jupyter.notebookFileRoot": "${workspaceFolder}" in my settings.json

WilianZilv avatar May 06 '22 20:05 WilianZilv

thanks for filing the issue. I haven't been able to repro this, it always just opens with the workspace folder as the cwd. I do see something in your logs specifying that folder though, so I'm trying to find out where that would come from.

amunger avatar May 06 '22 22:05 amunger

Although, are you saying that you expect the cwd to be c:\Projetos\project-2? If your setting is ${workspaceFolder} then it should be the workspace folder, c:\Projetos\. Still unclear why it's going to project-1, but are you somehow getting the working directory to be the current selected file's directory?

amunger avatar May 06 '22 22:05 amunger

I think this is by design. ${workspaceFolder} is actually dependent upon what file you're in.

The Create Interactive Window command doesn't look at the active file. It's neutral, so it just ends up using the first workspace folder. We could probably change it to use the current active editor.

rchiodo avatar May 07 '22 00:05 rchiodo

We pass undefined here: https://github.com/microsoft/vscode-jupyter/blob/261afd99b9880e31de1fc1e27aa49c836253fcb0/src/interactive-window/interactiveWindowCommandListener.node.ts#L351

That's why it would always use the first workspace folder.

rchiodo avatar May 07 '22 00:05 rchiodo

change it to use the current active editor

when dealing with muti-root workspace, i think we should ask the user. vscode already has an api for this, else where just making guess again and that could again cause other issues.

eg if you create a terminal vacode will ask the user to pick a workspace folder from the list, python extension has the same functionality for some features.

DonJayamanne avatar May 07 '22 04:05 DonJayamanne

ah, I was just trying a workspace with two folders, not a multi-root workspace. Following the terminal's example seems reasonable to me

amunger avatar May 09 '22 15:05 amunger

Maybe the behaviour i was getting before the clean uninstall/install was acctually a bug. That's kinda funny. I have now tested in more 3 different machines and they all behave as i described in the issue.

WilianZilv avatar May 11 '22 22:05 WilianZilv

In my case, "Jupyter: Create Interactive Window" creates a jupyter session in the first folder of my workspace (the one on top). Execute "pwd" in the IPython console to verify. This is very annoying because I work different environment files within the folders.

haeraeus avatar Aug 04 '22 08:08 haeraeus