microsoft / vscode-python

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

launch envFile cannot use the variable ${fileDirname} #11915

Open snr278 opened 4 years ago

snr278 commented 4 years ago

Environment data

Expected behaviour

configurations.envFile can use the variable ${fileDirname} (eg:"envFile": "${fileDirname}/${fileBasenameNoExtension}.env")

Actual behaviour

env variables define in file ${fileDirname}/${fileBasenameNoExtension}.env are not working.

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. create test file ${workspaceFolder}/test/test.py ${workspaceFolder}/test/test.env. 2.test.env define the env variable TEST_ENV_MY=hello world test_env 3.test.py print the env variable TEST_ENV_MY 4.define the envFile in launch.json "envFile": "${fileDirname}/.env"

record

Logs

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

``` XXX ```


Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

``` XXXX ```

kimadeline commented 4 years ago

Hi @snr278,

Thank you for reporting this issue! Seems like we don't interpolate fileDirname correctly.

Notes

image image
mattgillard commented 4 years ago

I just came across this bug today. I thought it was just me!

weinand commented 4 years ago

@kimadeline above you said

"we don't interpolate fileDirname correctly"

Please note that it is dangerous to interpolate variables yourself because you will miss newly introduced variables (and your variable substitution code might differ from VS Code's code).

A fully interpolated launch config is passed into the DebugConfigurationProviders method resolveDebugConfigurationWithSubstitutedVariables. If you are already implementing a method resolveDebugConfiguration then you can just rename that method to resolveDebugConfigurationWithSubstitutedVariables and drop your own variable substitution code.

kimadeline commented 4 years ago

Thank you for the heads-up @weinand! We indeed use resolveDebugConfiguration, so resolveDebugConfigurationWithSubstitutedVariables is a very likely part of the solution (we still need to investigate further and see if there's anything else that could be causing this issue).

@mattgillard feel free to upvote the issue report to help us prioritize this.

Thanks!

jtele2 commented 1 year ago

This seems to work sometimes for me and other times it does not. Any ideas?