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

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

Open
WilianZilv opened this issue May 6, 2022 · 9 comments
Assignees
Labels
feature-request Request for new features or functionality interactive-window Impacts interactive window

Comments

@WilianZilv
Copy link

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 WilianZilv added the bug Issue identified by VS Code Team member as probable bug label May 6, 2022
@github-actions github-actions bot added the triage-needed Issue needs to be triaged label May 6, 2022
@amunger
Copy link
Contributor

amunger commented May 6, 2022

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
Copy link
Contributor

amunger commented May 6, 2022

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 amunger added the info-needed Issue requires more information from poster label May 6, 2022
@rchiodo
Copy link
Contributor

rchiodo commented May 7, 2022

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
Copy link
Contributor

rchiodo commented May 7, 2022

We pass undefined here:

await this.interactiveWindowProvider.getOrCreate(undefined, connection);

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

@DonJayamanne
Copy link
Contributor

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.

@amunger amunger removed the info-needed Issue requires more information from poster label May 9, 2022
@amunger
Copy link
Contributor

amunger commented May 9, 2022

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

@greazer greazer added feature-request Request for new features or functionality papercut 🩸 Something affecting the productivity of the team interactive-window Impacts interactive window and removed bug Issue identified by VS Code Team member as probable bug triage-needed Issue needs to be triaged labels May 9, 2022
@WilianZilv
Copy link
Author

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.

@amunger amunger removed their assignment Jun 3, 2022
@haeraeus
Copy link

haeraeus commented Aug 4, 2022

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.

@rebornix rebornix removed their assignment Dec 6, 2023
@ma-sadeghi
Copy link

Yeah, it'd be nice if the user was prompted which workspace folder (in a multi-root one) to used when creating a new Interactive Window, similar to what already happens with terminals.

@amunger amunger removed the papercut 🩸 Something affecting the productivity of the team label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality interactive-window Impacts interactive window
Projects
None yet
Development

No branches or pull requests

8 participants