microsoft / vscode-python

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

UTF-16 encoded .env files fail when loaded via pipenv with no warning #1563

Closed d3r3kk closed 5 years ago

d3r3kk commented 6 years ago

Environment data

Actual behavior

Environment variable set into my .env file is not available in the environment of my runtime.

Expected behavior

Environment variables set into my .env file are available.

Steps to reproduce:

  1. Create a new project using the following (you can do this in a shell, or in the Interactive terminal within VSCode):
    > mkdir test4pipenv
    > cd test4pipenv
    > pipenv --three
  2. Open the folder in VSCode.
  3. Create a .env file using the interactive PowerShell terminal in VSCode:
    PS C:\dev\test4pipenv> "MYVAR=SOMEVALUE" | Out-File .\.env
  4. Open the .env file in VSCode, and notice that the encoding is UTF-16 LE.
  5. Create a main.py file, with the following content:
    
    import os

print(os.environ['COMPUTERNAME'] print(os.environ['MYVAR']

6. Run the file using the debugger (choose Python as the interpreter).

## Logs
Output for `Python` in the `Output` panel:

##########Linting Output - pylint########## No config file found, using default configuration


Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)


Output from `Console` under the `Developer Tools` panel (toggle Developer Tools on under `Help`)

/C:/Program Files/Microsoft VS Code Insiders/resources/app/out/vs/workbench/workbench.main.js:2912 Loading development extension at D:\dev\github\vscode\vscode-python /C:/Program Files/Microsoft VS Code Insiders/resources/app/out/vs/workbench/workbench.main.js:2813 [Extension Host] STOPPED on first line for debugging on port 44832 (anonymous) @ /C:/Program Files/Microsoft VS Code Insiders/resources/app/out/vs/workbench/workbench.main.js:2813 /C:/Program Files/Microsoft VS Code Insiders/resources/app/out/vs/workbench/workbench.main.js:2811 [Extension Host] debugger inspector at %cDebugger listening on port 44832. Warning: This is an experimental feature and could change at any ti%cme. To start debugging, open the following URL in Chrome: chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:44832/768bc727-2970-40bd-8607-4d8c20d45fac

/C:/Program Files/Microsoft VS Code Insiders/resources/app/out/vs/workbench/workbench.main.js:2811 [Extension Host] debugger inspector at %cDebugger attached.


---

Output from the TERMINAL under the 'debuggee':

PS D:\dev\vsts\dekeeler\Python\test4pipenv> cd 'd:\dev\vsts\dekeeler\Python\test4pipenv'; ${env:pythonioencoding}='UTF-8'; ${env:pythonunbuffered}='1'; & 'C:\Users\dekeeler.virtualenvs\test4pipenv-9X8xIwhZ\scripts\python.exe' 'D:\dev\github\vscode\vscode-python\pythonFiles\PythonTools\visualstudio_py_launcher.py' 'd:\dev\vsts\dekeeler\Python\test4pipenv' '14824' '34806ad9-833a-4524-8cd6-18ca4aa74f14' 'RedirectOutput,RedirectOutput' 'd:\dev\vsts\dekeeler\Python\test4pipenv\test.py' DEK-DESKTOP01 Traceback (most recent call last): File "d:\dev\vsts\dekeeler\Python\test4pipenv\test.py", line 4, in print(os.environ['MYVAR']) File "C:\Users\dekeeler.virtualenvs\test4pipenv-9X8xIwhZ\lib\os.py", line 669, in getitem raise KeyError(key) from None KeyError: 'MYVAR' PS D:\dev\vsts\dekeeler\Python\test4pipenv>

kimadeline commented 5 years ago

Still happening in version 2019.9.34911 of the extension

DonJayamanne commented 5 years ago

Has anyone else (user) reported this issue?

kimadeline commented 5 years ago

Doesn't seem like it.

DonJayamanne commented 5 years ago

If that's the case, I'd prefer we close this. No point leaving it open if we aren't going to fix until someone reports this.