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

Creating new Integrated Terminal doesn't take selected workspace into account when activating environment #15522

Closed
jchang10 opened this issue Mar 1, 2021 · 13 comments
Assignees
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug good first issue verified Verification succeeded
Milestone

Comments

@jchang10
Copy link

jchang10 commented Mar 1, 2021

Environment data

  • Version: 1.54.0-insider (user setup)
  • Commit: e590188f17162393f50feec19263398e6fe02d13
  • Date: 2021-02-26T20:39:10.253Z
  • Electron: 11.3.0
  • Chrome: 87.0.4280.141
  • Node.js: 12.18.3
  • V8: 8.7.220.31-electron.0
  • OS: Windows_NT x64 10.0.19042
  • Python version (& distribution if applicable, e.g. Anaconda): python3.8
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): Pipenv and just venv
    -- Relevant/affected Python packages and their versions: XXX
    -- Relevant/affected Python-related VS Code extensions and their versions: XXX
    -- Value of the python.languageServer setting: XXX

Expected behaviour

This is while working with multiple projects in a workspace.

Up until recently, just a day or two ago, Selecting a "New Integrated Terminal" worked perfectly. It asks "Select current working directory for new terminal". The terminal would perfectly pick up the correct venv based on the folder's settings namely python.pythonPath.

Actual behaviour

Now, it seems to pick the venv based on the last file or editor only. If I click a workspaceX file, it uses the venv for workspaceX no matter what "Select current working directory for new terminal" directory is chosen in the prompt. :(

Steps to reproduce:

Here is a minimal example.

  1. Create new project folder test1.
  2. Create new project folder test2.
  3. cd test1; mkdir venv; python -m venv venv; touch test1.py; cd ..
  4. cd test2; mkdir venv; python -m venv venv; touch test2.py; cd ..
  5. Save project settings.
mkdir test1/.vscode
cat > test1/.vscode/settings.json
{
    "python.pythonPath": "venv/bin/python"
}                                                                                                                                                                                                                                                                                                                                                          
mkdir test2/.vscode
cat > test2/.vscode/settings.json
{
    "python.pythonPath": "venv/bin/python"
}                                                                                                                                                                                                                                                                                                                                                          
  1. Save workspace
cat > workspace.code-workspace
{
        "folders": [
                {
                        "path": "test1"
                },
                {
                        "path": "test2"
                }
        ],
        "settings": {}
}                                                                                                                                                                                                                                                                                                                                                          
  1. Now open the workspace. Select test2.py. New Integrated Terminal -> Select test1 -> you get:
    source /home/jchang/proj/tests/bugreport/test2/venv/bin/activate

This should be using test1 not test2!!! This used to work up until the last day or two! :(

@jchang10 jchang10 added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Mar 1, 2021
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Mar 2, 2021
@karrtikr
Copy link

karrtikr commented Mar 2, 2021

Hi @jchang10 👋 Please provide the logs as mentioned in the issue template, also what extension version are you using?

Logs

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

XXX

@jchang10
Copy link
Author

jchang10 commented Mar 2, 2021

Hi. Sorry. ms-python version ms-python.python-2021.2.582707922. I am on the nightly build.

Below is my entire python log output after a window reload. Not seeing anything major.

The weird thing is that this is what my terminal windows shows after New Terminal. I only have test2.py showing in the editor. I do New Terminal -> Select test1 as my working dir, and this is what I get. It correctly opens a terminal with the directory in test1, but the environment is from test2!

source /home/jchang/proj/tests/bugreport/test2/venv/bin/activate
➜  bugreport/test1 source /home/jchang/proj/tests/bugreport/test2/venv/bin/activate
(venv) ➜  bugreport/test1 which python  
/home/jchang/proj/tests/bugreport/test2/venv/bin/python
(venv) ➜  bugreport/test1 
User belongs to experiment group 'pythonaa'
User belongs to experiment group 'pythonSendEntireLineToREPL'
User belongs to experiment group 'pythonNotDisplayLinterPrompt'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - control'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'LocalZMQKernel - experiment'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'EnableIPyWidgets - experiment'
User belongs to experiment group 'RunByLine - experiment'
User belongs to experiment group 'CustomEditorSupport - control'
> conda --version
> pyenv root
> ~/miniconda3/bin/conda info --json
> python3.7 ~/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 ~/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 ~/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 ~/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python ~/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> ~/proj/tests/bugreport/test2/venv/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> ~/miniconda3/bin/conda env list
> ~/miniconda3/bin/conda env list
Error 2021-03-02 12:02:57: Failed to check if file needs to be fixed [EntryNotFound (FileSystemError): Unable to read file 'vscode-remote://wsl+ubuntu-20.04/home/jchang/.config/Code - Insiders/User/settings.json' (Error: Unable to resolve non-existing file 'vscode-remote://wsl+ubuntu-20.04/home/jchang/.config/Code - Insiders/User/settings.json')
	at _handleError (/home/jchang/.vscode-server-insiders/bin/e7989863202eac0ec4e66ca82733d968bca7527a/out/vs/server/remoteExtensionHostProcess.js:87:151863)
	at async y.readText (/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/out/client/extension.js:9:298390)
	at async p.doesFileNeedToBeFixed (/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/out/client/extension.js:59:481374)
	at async /home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/out/client/extension.js:59:480501
	at async Promise.all (index 0)
	at async p.getFilesToBeFixed (/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/out/client/extension.js:59:480447)
	at async p.updateTestSettings (/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/out/client/extension.js:59:480074)] {
  code: 'FileNotFound'
}
Starting Pylance language server.
Python interpreter path: ./venv/bin/python
> ~/proj/tests/bugreport/test1/venv/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/proj/tests/bugreport/test1 -s --cache-clear
cwd: ~/proj/tests/bugreport/test1
Error 2021-03-02 12:03:06: Failed to parse discovered Test [r [Error]: Traceback (most recent call last):
  File "/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/testing_tools/run_adapter.py", line 17, in <module>
    from testing_tools.adapter.__main__ import parse_args, main
  File "/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/testing_tools/adapter/__main__.py", line 9, in <module>
    from . import pytest, report
  File "/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/testing_tools/adapter/pytest/__init__.py", line 7, in <module>
    from ._discovery import discover
  File "/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 8, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'

	at ChildProcess.<anonymous> (/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/out/client/extension.js:9:702732)
	at Object.onceWrapper (events.js:422:26)
	at ChildProcess.emit (events.js:315:20)
	at ChildProcess.EventEmitter.emit (domain.js:483:12)
	at maybeClose (internal/child_process.js:1021:16)
	at Socket.<anonymous> (internal/child_process.js:443:11)
	at Socket.emit (events.js:315:20)
	at Socket.EventEmitter.emit (domain.js:483:12)
	at Pipe.<anonymous> (net.js:674:12)]
> ~/proj/tests/bugreport/test1/venv/bin/python ~/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/pyvsc-run-isolated.py -c "import pytest"
Error 2021-03-02 12:03:06: Python Extension: displayDiscoverStatus [r [Error]: Traceback (most recent call last):
  File "/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/testing_tools/run_adapter.py", line 17, in <module>
    from testing_tools.adapter.__main__ import parse_args, main
  File "/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/testing_tools/adapter/__main__.py", line 9, in <module>
    from . import pytest, report
  File "/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/testing_tools/adapter/pytest/__init__.py", line 7, in <module>
    from ._discovery import discover
  File "/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 8, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'

	at ChildProcess.<anonymous> (/home/jchang/.vscode-server-insiders/extensions/ms-python.python-2021.2.582707922/out/client/extension.js:9:702732)
	at Object.onceWrapper (events.js:422:26)
	at ChildProcess.emit (events.js:315:20)
	at ChildProcess.EventEmitter.emit (domain.js:483:12)
	at maybeClose (internal/child_process.js:1021:16)
	at Socket.<anonymous> (internal/child_process.js:443:11)
	at Socket.emit (events.js:315:20)
	at Socket.EventEmitter.emit (domain.js:483:12)
	at Pipe.<anonymous> (net.js:674:12)]
Python interpreter path: ./venv/bin/python
Python interpreter path: ~/proj/tests/bugreport/test1/venv/bin/python
Python interpreter path: ./venv/bin/python
Python interpreter path: ~/proj/tests/bugreport/test1/venv/bin/python
Python interpreter path: ./venv/bin/python
Python interpreter path: ~/proj/tests/bugreport/test1/venv/bin/python
Python interpreter path: ./venv/bin/python
Python interpreter path: ~/proj/tests/bugreport/test1/venv/bin/python

@karrtikr
Copy link

karrtikr commented Mar 2, 2021

Thanks for the logs, I'll try to reproduce and get back to you soon.

@karrtikr
Copy link

karrtikr commented Mar 22, 2021

@jchang10 I'm able to reproduce this issue, thanks! Although that is how it always used to work.

// If we have just one workspace, then pass that as the resource.
// Until upstream VSC issue is resolved https://github.com/Microsoft/vscode/issues/63052.
await this.activator.activateEnvironmentInTerminal(terminal, {
resource: this.activeResourceService.getActiveResource(),
});

As the comment states we were waiting on VSCode for the fix on microsoft/vscode#63052. Looks like it has been fixed, so we'll need to change that line to get terminal.creationOptions.cwd instead of the active resource when possible.

Passing the following as resource instead should fix the issue:

const cwd =
    'cwd' in terminal.creationOptions
        ? terminal.creationOptions.cwd
        : this.activeResourceService.getActiveResource();
const resource = typeof cwd === 'string' ? Uri.file(cwd) : cwd;

You're welcome to fix it as well.

@karrtikr karrtikr removed their assignment Mar 22, 2021
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Mar 22, 2021
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Mar 22, 2021
@karrtikr karrtikr changed the title Workspaces and New Integrated Terminal choosing a virtualenv has changed Creating new Integrated Terminal doesn't take selected workspace into account when activating environment Mar 22, 2021
@ShahzaibParacha
Copy link

Can I get in on this issue?

@karrtikr
Copy link

@ShahzaibParacha Sure. Just FYI I have mentioned the fix here #15522 (comment)

@KamalSinghKhanna
Copy link

is this issue still open I would like to work on this.

@ShahzaibParacha
Copy link

is this issue still open I would like to work on this.

I'm working on it.

@CodePint
Copy link

CodePint commented Jul 7, 2021

Not sure if some of these issues are related to depreciate python path experiment:
#12313

I resolved the issue by adding the following to my user/settings.json
{"python.experiments.optOutFrom": ["pythonDeprecatePythonPath"]}

and making sure that in my project settings.json i had:
{"python.pythonPath": "/home/users/.local/path/to/project/virtualenv/bin/python"}

@karrtikr
Copy link

karrtikr commented Jul 7, 2021

@KamalSinghKhanna As it's been a while, you can give it a shot too.

@ShahzaibParacha Are you still tackling it?

@GordonRBurgess
Copy link

GordonRBurgess commented Sep 10, 2021

I think I can provide some more context here - I have two completely different Python projects that I'd like to be able to compare. They both have virtual environments created with pipenv. If I set the interpreter for the workspace on both environments, as long as no other instances of vscode (VSCodium) are running everything works as expected; new terminal windows launch the correct interpreter.

If one workspace is already open the second workspace can be opened, but new terminal windows will NOT use the interpreter saved as a preference. If the first workspace is closed and the second (re)opened, new terminal windows behave as expected.

There seems to be some crosstalk between multiple open vscode workspaces on the same machine. (possibly an inadvertent global in node?) IMO more isolation would be very desirable.

Temporary work-around is to only open one workspace at a time, or to manually run pipenv shell in new terminals in the second workspace. (noting that this does not sort out debugging)

Thanks, and good luck!

Gordon

VSCodium
Version: 1.60.0
Commit: e7d7e9a9348e6a8cc8c03f877d39cb72e5dfb1ff
Date: 2021-09-07T00:20:05.363Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.10.0-8-amd64

(Cinnamon desktop on Debian 11)

@Vidushi-Gupta
Copy link

Can I get assigned to this? Thanks!

Vidushi-Gupta added a commit to Vidushi-Gupta/vscode-python that referenced this issue Oct 1, 2021
Vidushi-Gupta added a commit to Vidushi-Gupta/vscode-python that referenced this issue Oct 1, 2021
Vidushi-Gupta added a commit to Vidushi-Gupta/vscode-python that referenced this issue Oct 1, 2021
karthiknadig pushed a commit to Vidushi-Gupta/vscode-python that referenced this issue Oct 4, 2021
karthiknadig pushed a commit to Vidushi-Gupta/vscode-python that referenced this issue Oct 4, 2021
karthiknadig pushed a commit to Vidushi-Gupta/vscode-python that referenced this issue Oct 4, 2021
karthiknadig added a commit that referenced this issue Oct 4, 2021
… account when activating environment (#17595)

* Worked on issue #15522

* worked on #15522 issue

* added #15522 issue fix and contributor name

* Impored Uri from VSCode

* imported Uri correctly

* imported Uri correctly

* used short hand property on line 61

* formatted document using prettier

* formatted code using prettier

* formatted code using prettier

* updated formatting of the document

used 4 tab spaces in prettier

* Fix formatting.

Co-authored-by: Karthik Nadig <[email protected]>
karthiknadig added a commit to karthiknadig/vscode-python that referenced this issue Oct 13, 2021
… account when activating environment (microsoft#17595)

* Worked on issue microsoft#15522

* worked on microsoft#15522 issue

* added microsoft#15522 issue fix and contributor name

* Impored Uri from VSCode

* imported Uri correctly

* imported Uri correctly

* used short hand property on line 61

* formatted document using prettier

* formatted code using prettier

* formatted code using prettier

* updated formatting of the document

used 4 tab spaces in prettier

* Fix formatting.

Co-authored-by: Karthik Nadig <[email protected]>
karthiknadig added a commit that referenced this issue Oct 13, 2021
… account when activating environment (#17595)

* Worked on issue #15522

* worked on #15522 issue

* added #15522 issue fix and contributor name

* Impored Uri from VSCode

* imported Uri correctly

* imported Uri correctly

* used short hand property on line 61

* formatted document using prettier

* formatted code using prettier

* formatted code using prettier

* updated formatting of the document

used 4 tab spaces in prettier

* Fix formatting.

Co-authored-by: Karthik Nadig <[email protected]>
@karrtikr karrtikr added the verification-needed Verification of issue is requested label Oct 20, 2021
@karrtikr karrtikr added this to the October 2021 milestone Oct 20, 2021
@karrtikr
Copy link

Fixed with #17595

@karrtikr karrtikr self-assigned this Oct 20, 2021
@karrtikr karrtikr added verified Verification succeeded and removed verification-needed Verification of issue is requested labels Oct 25, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug good first issue verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

8 participants