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

env file not loaded if specified in launch.json and python.envFile #7210

Closed
kodalipraveen opened this issue Sep 5, 2019 · 13 comments
Closed
Assignees
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority regression Bug didn't exist in a previous release

Comments

@kodalipraveen
Copy link

Environment data

  • VS Code version: 1.38.0
  • Extension version (available under the Extensions sidebar): 2019.9.34474
  • OS and version: MAC OS Mojave - 10.14.6
  • Python version (& distribution if applicable, e.g. Anaconda): Pyhton 3.7.2 - 64 bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: XXX
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): Language Server

Issue description

In the latest build, when debugging a python file using integrated terminal, the contents of ".env" file are not being loaded.
This issue is not seen in 2019.8.0. I downgraded to verify that this is a regression issue.
Content of launch.json file

        {
            "name": "Python: Terminal (integrated)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "envFile": "${workspaceRoot}/.env"
        },

Contents of .env file

PYTHONPATH=/opt/library/python:/opt/lib/PythonApi
TCLLIBPATH="/opt/library /Library/Tcl/teapot/package/macosx10.5-i386-x86_64/lib"
@kodalipraveen kodalipraveen added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Sep 5, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Sep 5, 2019
@erlichsefi
Copy link

Same here.
my launch.json config was working before the last update.

@kimadeline
Copy link

Hello @kodalipraveen and @erlichsefi 👋 Thank you for reaching out! In version 2019.9 of the extension we changed the way we handle .env files (introduced in e095693, which then got reverted in 1499a8f, and then the revert got reverted in b4499f0):

🛑 You don't specify the envFile key in your launch config anymore
👉 Instead you should set the path to your .env file in the python.envFile setting:
image

Can you try setting python.envFile and reply here on whether it works or not? If not, you can also try passing the environment variables directly in your launch config using the env key (note that there is an open issue about environment variables passed by the env key not being shown for the first run: #6986).

Thank you!

@kimadeline kimadeline added the info-needed Issue requires more information from poster label Sep 5, 2019
@kodalipraveen
Copy link
Author

Thanks for looking at this issue @kimadeline
The setting Python.envFile is already present and set to the default value.
Based on your comments I tried to repo the issue. This issue is seen if envFile is defined in the launch.json file. If I remove that entry than the environment variables are being updated correctly.

@kimadeline
Copy link

We don't support envFile in the launch.json anymore due to ptvsd changes (see #6770), so you should update your launch configuration to remove the envFile key, and use python.envFile if you need to specify an environment file if it's not located at ${workspaceFolder}/.env.

In your case @kodalipraveen since your env file is already in the default location, I assume you only need to update your launch.json and remove the envFile entry.

@kodalipraveen
Copy link
Author

In my case the same file was being referenced by both the launch.json and python.envFile entries. When this is the case, neither entry is being honoured. It should have loaded the .env file from the python.envFile entry.

@kimadeline
Copy link

Thank you for the helpful clarification @kodalipraveen 👍 There is a little bit more work and some spec'ing needed to solve this issue, so I will add the needs-spec label and we'll review it as soon as we can!

@kimadeline kimadeline added area-debugging needs proposal Need to make some design decisions regression Bug didn't exist in a previous release and removed info-needed Issue requires more information from poster triage labels Sep 5, 2019
@kimadeline kimadeline changed the title .env file specified in launch.json not being loaded env file not loaded if specified in launch.json and python.envFile Sep 6, 2019
@kimadeline kimadeline added the important Issue identified as high-priority label Sep 6, 2019
@kimadeline kimadeline removed their assignment Sep 6, 2019
@luabud luabud added this to the 2019 - September Sprint 2 milestone Sep 10, 2019
@martinstein
Copy link

So if envFile in the launch configuration is no longer supported, that means there is no easy way to switch between different env-files for different launch configurations anymore? That feature was very helpful, and it's even nicely documented here: https://code.visualstudio.com/docs/python/environments#_environment-variable-definitions-file :

A debug configuration also contains an envFile property that also defaults to the .env file in the current workspace (see Debugging - Set configuration options). This property allows you to easily set variables for debugging purposes that replace variables specified in the default .env file

Now you have to go into settings and modify python.envFile each time when you want to run a launch config with a different env-file?

I'm aware of the env option, but that's not really a good alternative, because it would mean duplicating the values from the env-files.

@DonJayamanne
Copy link

So if envFile in the launch configuration is no longer supported, that means there is no easy way to switch between different env-files for different launch configurations anymore? That feature was very helpful, and it's even nicely documented here:

I'm sorry for the confusion. The envFile option is still supported. @kimadeline /cc

@DonJayamanne
Copy link

introduced in e095693, which then got reverted in 1499a8f, and then the revert got reverted in b4499f0):

If this is the case we'll need to fix this asap. It was never supposed to be removed.

@kimadeline @karthiknadig /cc

@DonJayamanne DonJayamanne removed the needs proposal Need to make some design decisions label Sep 13, 2019
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Sep 13, 2019
@DonJayamanne
Copy link

I have submitted a PR to resolve this issue.

@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Sep 13, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Sep 13, 2019
@erlichsefi
Copy link

Thank you all! meanwhile, is there a way to use the previous version of the extension?

@DonJayamanne
Copy link

@kimadeline
Copy link

✅ Validated with Insiders build 2019.9.36496:

  • same env file specified in both settings and launch config: env file is loaded
  • 2 different env files (one in user settings, one in launch config): launch config takes precedence
  • 2 different env files (one in workspace settings, one in launch config): launch config takes precedence
  • default value in user and workspace settings, custom env file in launch.json: env file is loaded
  • change default value in user settings, no env file in launch config: env file is loaded
  • leave default value in user settings, update value in workspace settings, no env file in launch config: env file is loaded.

@ghost ghost removed the needs PR label Sep 17, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority regression Bug didn't exist in a previous release
Projects
None yet
Development

No branches or pull requests

9 participants