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

Debug configuration does not override workspace python interpreter #463

Open
eickr opened this issue Sep 26, 2024 · 4 comments
Open

Debug configuration does not override workspace python interpreter #463

eickr opened this issue Sep 26, 2024 · 4 comments
Assignees
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@eickr
Copy link

eickr commented Sep 26, 2024

Fairly straightforward issue. When performing "Start Debugging" or "Run Without Debugging", the debugger will use the current workspace interpreter instead of the interpreter specified in the launch.json configuration with the "python" key.

Steps to reproduce:

  1. Have a multi-folder/root workspace. E.g.:
    • .vscode
      • launch.json
    • ProjectA
      • projecta-abcd-py3.x
      • etc
    • ProjectB
      • projectb-abcd-py3.x
      • etc
  2. Specify the interpreter you want each debug configuration to use in your launch.json file. E.g.:
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "ProjectA",
            "type": "debugpy",
            "python": "${workspaceFolder}/projectA/projecta-abcd-py3.x/bin/python",
            "request": "launch",
            "program": "${workspaceFolder}/projectA/cli.py",
            "console": "integratedTerminal",
            "args": []
        },
        {
            "name": "ProjectB",
            "type": "debugpy",
            "python": "${workspaceFolder}/ProjectB/projectb-abcd-py3.x/bin/python",
            "request": "launch",
            "program": "${workspaceFolder}/ProjectB/cli.py",
            "console": "integratedTerminal",
            "args": []
        },
    ]
}
  1. Set your workspace interpreter to the interpreter for any project. Let's say we set it to A, ./projectA/projecta-abcd-py3.x/bin/python.
  2. Select the run & debug configuration for a different project. Let's say we select B.
  3. Start Debugging or Run Without Debugging.

Expected result (terminal output):

source /home/REDACTED/ProjectB/projectb-abcd-py3.x/bin/activate
user@host:~/REDACTED$ source /home/REDACTED/ProjectB/projectb-abcd-py3.x/bin/activate
(projectb-py3.x) user@host:~/REDACTED$  /usr/bin/env /home/REDACTED/ProjectB/projectb-abcd-py3.x/bin/python /home/REDACTED/.vscode-server/extensions/ms-python.debugpy-2024.10.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher 41261 -- /home/REDACTED/ProjectB/cli.py

Actual result (terminal output):

source /home/REDACTED/ProjectA/projecta-abcd-py3.x/bin/activate
user@host:~/REDACTED$ source /home/REDACTED/ProjectA/projecta-abcd-py3.x/bin/activate
(projecta-py3.x) user@host:~/REDACTED$  /usr/bin/env /home/REDACTED/ProjectA/projecta-abcd-py3.x/bin/python /home/REDACTED/.vscode-server/extensions/ms-python.debugpy-2024.10.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher 41261 -- /home/REDACTED/ProjectB/cli.py

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 26, 2024
@eleanorjboyd
Copy link
Member

Thank you for the comprehensive issue!

First, can you try specifying the absolute path instead of using the variable substitution when defining your python here "python": "${workspaceFolder}/ProjectB/projectb-abcd-py3.x/bin/python", and let me know what that does? Want to narrow down if this is an environment select issue or a variable substitution issue. Thanks!

@eickr
Copy link
Author

eickr commented Oct 1, 2024

Tested again with the absolute path for both "python" values in the launch.json,
"python": "/home/REDACTED/projectA/projecta-abcd-py3.x/bin/python", and "python": "/home/REDACTED/ProjectB/projectb-abcd-py3.x/bin/python",.
The result was the same; The current workspace python interpreter is used instead of what's specified by the python config in the launch.json file.

Unrelated, but while testing this I noticed the python debug console terminal output no longer contains the first line from the examples in my original post, starting instead with the second of the three lines. This remained the case even after I reverted the launch.json file back to using the workspaceFolder variable, so I'm assuming the difference from before is due to an unrelated update or logging quirk.

@eickr
Copy link
Author

eickr commented Oct 4, 2024

Some additional / new information:

  • The "source" commands were coming from the default python.terminal.activateEnvironment setting, which defaults to true. By configuring that setting to false, the first command that appears in python debugger terminals is now the /usr/bin/env /path/to/python/interpreter blah blah command.
  • It seems like whatever file is focused in your editor is affecting the python interpreter selection, seemingly preferring the interpreter for the workspace of whatever file you have focused when you Run/Debug.

@ilyakochik
Copy link

+1

Have a similar issue while trying to work in frontend (TypeScript / NodeJS) and backend (Python) workspace.

No matter how I try to specify VSCode extension: debug Python plugin overrides $workspaceFolder to be ./backend because this is where .venv is located.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Server: debug",
      "type": "debugpy",
      "request": "launch",
      "module": "src.server",
      "cwd": "${workspaceFolder}/backend",
      "console": "integratedTerminal",
      "justMyCode": false
    },
    {
      "name": "Server: create tests",
      "type": "debugpy",
      "request": "launch",
      "module": "tests.update",
      "cwd": "${workspaceFolder}/backend",
      "console": "integratedTerminal"
    },
    {
      "name": "VSCode extension: debug",
      "type": "extensionHost",
      "request": "launch",
      "args": ["--extensionDevelopmentPath=${workspaceFolder}/frontend-vscode"],
      "outFiles": ["${workspaceFolder}/dist/**/*.js"],
      "preLaunchTask": "${defaultBuildTask}",
      "cwd": "${workspaceFolder}/frontend-vscode"
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

3 participants