Skip to content

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

Closed

Description

@jchang10

Environment data

  • Version: 1.54.0-insider (user setup)
  • Commit: e590188
  • 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! :(

Activity

  1. added
    triage-neededNeeds assignment to the proper sub-team
    bugIssue identified by VS Code Team member as probable bug
    on Mar 1, 2021
  2. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Mar 2, 2021
  3. karrtikr commented on Mar 2, 2021

    @karrtikr

    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 (View→Output, change the drop-down the upper-right of the Output panel to Python)

    XXX
    

  4. jchang10 commented on Mar 2, 2021

    @jchang10
    Author

    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
    
  5. karrtikr commented on Mar 2, 2021

    @karrtikr

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

  6. karrtikr commented on Mar 22, 2021

    @karrtikr

    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.

  7. removed their assignment
    on Mar 22, 2021
  8. ghost added
    triage-neededNeeds assignment to the proper sub-team
    on Mar 22, 2021
  9. 14 remaining items

  10. added a commit that references this issue on Oct 1, 2021
  11. karrtikr commented on Oct 20, 2021

    @karrtikr

    Fixed with #17595

  12. locked as resolved and limited conversation to collaborators on Nov 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions