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 variables aren't considered on venv activation (which is happening behind the scenes?) #22927

Closed
NewtonChutney opened this issue Feb 18, 2024 · 9 comments
Assignees
Labels
experimenting Feature is part of an experiment info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@NewtonChutney
Copy link

Type: Bug

Behaviour

Expected vs. Actual

Expected:
When using a custom prompt manager, we export the variable VIRTUAL_ENV_DISABLE_PROMPT.
The activate script looks for this variable and doesn't change the PS1 prompt.

Actual:
The env variable doesn't seem to be respected. Moreover the venv activation doesn't happen when a terminal is spawned.. leading me to deduce VSCode is using a subshell/cached session?

Steps to reproduce:

vscode's default behaviour:

  1. Export VIRTUAL_ENV_DISABLE_PROMPT in bashrc/zshrc, restart vscode, then open a new terminal in a venv-containing python folder

expected native behaviour

  1. Try disabling automatic venv activation : setting -> python.terminal.activateEnvironment
  2. source the .venv/bin/activate script (still with export VIRTUAL_ENV_DISABLE_PROMPT in bashrc/zshrc)
  3. this time, the prompt prefix isn't modified.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.2
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Default
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

2024-02-18 11:43:37.231 [info] Experiment 'pythonRecommendTensorboardExt' is active
2024-02-18 11:43:37.231 [info] Experiment 'pythonREPLSmartSend' is active
2024-02-18 11:43:37.231 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2024-02-18 11:43:37.231 [info] Experiment 'pythonTestAdapter' is active
2024-02-18 11:43:37.502 [info] Default formatter is set to null for workspace /home/newtonchutney/log_parsing
2024-02-18 11:43:39.062 [info] Test server listening.
2024-02-18 11:43:39.067 [info] Python interpreter path: ./.venv/bin/python
2024-02-18 11:43:53.372 [info] > . ./.venv/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode-server/extensions/ms-python.python-2024.1.10451007/pythonFiles/printEnvVariables.py
2024-02-18 11:43:53.372 [info] shell: zsh
2024-02-18 11:43:53.643 [info] > /bin/python ~/.vscode-server/extensions/ms-python.python-2024.1.10451007/pythonFiles/printEnvVariables.py
2024-02-18 11:43:53.653 [info] shell: zsh
2024-02-18 11:43:54.624 [info] Send text to terminal: /bin/python /home/newtonchutney/.vscode-server/extensions/ms-python.python-2024.1.10451007/pythonFiles/printEnvVariablesToFile.py /home/newtonchutney/.vscode-server/extensions/ms-python.python-2024.1.10451007/pythonFiles/deactivate/zsh/envVars.txt
2024-02-18 11:43:56.191 [info] Starting Pylance language server.

User Settings


languageServer: "Pylance"

Extension version: 2024.0.1
VS Code version: Code 1.86.2 (903b1e9d8990623e3d7da1df3d33db3e42d80eda, 2024-02-13T19:40:56.878Z)
OS version: Windows_NT x64 10.0.22631
Modes:
Remote OS version: Linux arm64 6.1.0-rpi8-rpi-v8

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz (8 x 2611)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 15.50GB (5.64GB free)
Process Argv --crash-reporter-id fb233ff0-fc3c-4bff-bc6b-1860315734f1
Screen Reader no
VM 36%
Item Value
Remote SSH: bookwormpi.rufous-bee.ts.net
OS Linux arm64 6.1.0-rpi8-rpi-v8
CPUs Cortex-A72 (4 x 1500)
Memory (System) 3.70GB (2.63GB free)
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstes627:30244334
vscod805cf:30301675
binariesv615:30325510
vsaa593:30376534
py29gd2263:30899288
vscaac:30438847
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythongtdpath:30769146
welcomedialogc:30910334
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
pythontbext0:30879054
accentitlementsc:30887149
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
pydisww2:30959801
b1063948:30958189
a89i1917:30961429
3ef8e399:30964150
e3gdj431:30958358

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 18, 2024
@NewtonChutney
Copy link
Author

BTW, peek is deprecated, please remove this from the bug report template..
https://github.com/phw/peek

@NewtonChutney
Copy link
Author

Here's a screencap
vscode_py_venv.mp4

@lcoutu
Copy link

lcoutu commented Feb 21, 2024

same here

@karrtikr karrtikr added the experimenting Feature is part of an experiment label Feb 21, 2024
@karrtikr
Copy link

Python extension unfortunately does not have access to .zshrc right now, this should be fixed with #22128. As a workaround you can temporarily fix it by adding VIRTUAL_ENV_DISABLE_PROMPT as a systems variable: https://unix.stackexchange.com/a/117473. Alternatively, you can also add a ".env" file in workspace root and set that variable, which we will make sure to pick up.

@karrtikr karrtikr closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2024
@NewtonChutney
Copy link
Author

Python extension unfortunately does not have access to .zshrc right now, this should be fixed with #22128. As a workaround you can temporarily fix it by adding VIRTUAL_ENV_DISABLE_PROMPT as a systems variable: https://unix.stackexchange.com/a/117473. Alternatively, you can also add a ".env" file in workspace root and set that variable, which we will make sure to pick up.

Thanks, that would be a better fix.. I've had to comment out the PS1-modifying block.. 😅

@NewtonChutney
Copy link
Author

Nah Karthik, exporting in the workspace .env file nor setting vars in the terminal env variables section (terminal.integrated.env.linux) works.
I'll wait for the PR you mentioned np..✌️

@karrtikr
Copy link

Sure, btw I didn't claim setting in terminal env setting would work. But setting in as a systems variable should.

@NewtonChutney
Copy link
Author

Sorry I don't mean to blame you.. 😅

I'm in an enterprise setting, using a managed dev environment.. No sudo access sadly.. ᓚᘏᗢ

My reasoning was to try the terminal env way as it might be deeper than the workspace env file method when it didn't work out.. ¯_(ツ)_/¯

@karrtikr
Copy link

No problem I understand. Actually workspace env setting is deeper as it is a feature of the Python extension so applies everywhere, as opposed to terminal specific VS Code setting which only applies to terminal.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Feb 22, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
experimenting Feature is part of an experiment info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

3 participants