microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.34k stars 1.19k forks source link

Variable substitution not working in environment variable definitions file when debugging #14950

Open martinResearch opened 3 years ago

martinResearch commented 3 years ago

Environment data

Expected behaviour

Should print the content of the PATH environment variable

Actual behaviour

the string "${env:PATH};" get printed

Steps to reproduce:

Steps to Reproduce:

create these files

d:\repos\bug_vscode\test.py:

import os
print(os.environ["PATH"])

d:\repos\bug_vscode.vscode.env

PATH=${env:PATH};

d:\repos\bug_vscode.vscode\launch.json

{
  "version": "0.2.0",
  "configurations": [

    {
      "name": "Current File",
      "type": "python",
      "envFile": "${workspaceFolder}/.vscode/.env",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal"
    }
  ]
}

launch with the debug configuration from the GUI This produces these prints in the terminal:

${env:PATH};

while, according to the documentation here I would expect ${env:PATH} to be replaced by the content of the environment variable

Documented the issue here https://github.com/microsoft/vscode/issues/112142 but got closed assuming it was a problem with the extension

ericsnowcurrently commented 3 years ago

@martinResearch, thanks for letting us know about this. Currently when you provide the "envFile" setting to the debugger, the extension only applies to that .env file the env vars defined in the "env" setting. Process-defined and other extension-defined env vars are not used. We'll check on what can be done about that and get back to you.

@int19h

ericsnowcurrently commented 3 years ago

See: src/client/debugger/extension/configuration/resolvers/helper.ts

mlisovyi commented 3 years ago

For me it seems to actually work, if i skip env: portion, i.e. (assuming Windows like in the OP)

PYTHONPATH=${PYTHONPATH}
kimadeline commented 3 years ago

Still happening when using 2021.4.681399556-dev.