Vscode-remote-release: Python extension activates Python environment even though devcontainers.json's settings say not to

Created on 17 Nov 2020  路  6Comments  路  Source: microsoft/vscode-remote-release

Versions

  • VSCode Version: 1.51.1
  • Local OS Version: macOS 10.15.7
  • Remote OS Version: Debian 10
  • Remote Extension/Connection Type: Docker

Bug description

VS Code's Python extension will attempt to activate the selected Python environment in the Terminal, even when devcontainers.json's settings section explicitly says not to.

Steps to Reproduce

  1. Create a development container (devcontainer.json spec below).
  2. Open a .py file to activate VS Code's Python extension.
  3. Open a new Terminal in VS Code and watch the Python extension attempt to activate the selected Python environment.


devcontainer.json spec:

{
    "name": "entities",
    "image": "continuumio/miniconda3:latest",
    "extensions": [
        "ms-python.python",
        "ms-python.vscode-pylance",
        "ms-toolsai.jupyter",
        "eamodio.gitlens"
    ],
    "settings": {
        "terminal.integrated.shell.linux": "/usr/bin/fish",
        "python.pythonPath": "/opt/conda/envs/entities-env/bin/python",
        "python.terminal.activateEnvironment": false,  // <-- Explicitly requesting not to activate the environment
        "python.terminal.activateEnvInCurrentTerminal": false  // <-- Explicitly requesting not to activate the environment
    },
    "postCreateCommand": "./tasks/init.sh devcontainer"  // Installs fish shell and creates conda environment
}

Workaround

No workaround other than disabling environment activation in the project's Workspace Settings.

*question containers

All 6 comments

Make sure you rebuild the container after changing the settings in the devcontainer.json. These are copied to the container's machine settings only once. You can check the container's current "machine settings" in the VS Code settings editor while connected to the container.

If that doesn't explain it, please open an issue for the Python extension.

  • Container was freshly built for the devcontainer.json described above.
  • In the Remote settings screen I indeed see that settings to activate the Python environment are set to false:
    image
  • The Workspace settings screen shows that the settings to activate the Python environment are set to true:
    image
  • Are you sure this is a Python extension issue? It feels like the Remote settings don't override the Workspace settings. Both are clearly set correctly.

The workspace settings win over the remote settings. That's as designed. Can you remove the workspace settings or do you depend on these locally?

The desired behaviour is this:

  1. In the Dev Container we _don't_ want the Python extension to activate the conda environment because it's already active in the container.
  2. Locally, the _do_ want the Python extension to activate the conda environment because there you cannot count on the conda environment already being active.

Is there a way to achieve both (1) and (2)? Based on the fact that you say that Workspace settings override Dev Container settings, it would seem that this is not possible.

You could add the following to your devcontainer.json:

    "mounts": ["type=bind,src=${localWorkspaceFolder}/.vscode/devcontainer-settings.json,dst=${containerWorkspaceFolder}/.vscode/settings.json"]

And then place the dev container settings in the .vscode/devcontainer-settings.json. Let me know if that works for you.

Thanks for the workaround @chrmarti! I submitted this as a bug originally, but since the behaviour is intended this is at best a feature request. The workaround feels like it's good enough though, so I think this issue can be closed.

Was this page helpful?
0 / 5 - 0 ratings