microsoft / vscode-python

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

Use shell integration to get environment variables #23159

Closed anthonykim1 closed 4 weeks ago

anthonykim1 commented 6 months ago

Use shell integration to get environment variables and activate environment, instead of NodeJS process environment variables.

Python extension should be able to leverage: https://github.com/microsoft/vscode/blob/main/src/vscode-dts/vscode.proposed.terminalShellIntegration.d.ts and https://github.com/microsoft/vscode/issues/207504 to get a full context of user's environment variables, especially those stored, modified in shell specific initialization scripts such as .zshrc, .bashrc.

Using hidden terminal which would have context of these initialization scripts, we can activate terminal environment with better context compared to the currently used process approach by enhancing shell integration hidden terminal approach.

This will resolve lot of issues where users are missing environment variables that are set inside their shell specific initialization script modified such as by conda activate if we know they have shell integration working/enabled for their terminal.

There will be additional issue/PR to resolve PS1 so users do not see unwanted PS1 if they are using specific prompt such from starship.

There will be additional PR to use replacing option for environment variable instead of prepending option(this is known to shadow some of the important parts such as for PATH variable).

AtharvaShekatkar commented 4 months ago

@anthonykim1 Any idea when this will be resolved?

anthonykim1 commented 4 months ago

@AtharvaShekatkar I can't provide a specific date but the team is definitely aware of this. Are you having any specific/complains to the new terminal environment variable experiment?

AtharvaShekatkar commented 3 months ago

@anthonykim1 No complaints. I am a starship user facing the double (.venv) issue and just wanted to know when it'll be solved.

anthonykim1 commented 3 months ago

@AtharvaShekatkar I see, did any of the suggestion https://github.com/microsoft/vscode-python/issues/23137 work out? Can you also opt out of shell integration in your settings and see if you still see the duplicate (venv)? Please also check if virtual environment is still correctly activated in this case. This is all in the assumption with you are opt-in for Terminal env var activation experiment.

This is late (I think it might've got looked over with issue being tracked here) but to answer https://github.com/microsoft/vscode-python/issues/23304#issuecomment-2084659155, not too sure why it is only happening to mac in your scenario. I'm guessing one of the possibility might be from currently how we are trying to predict user's PS1 and see if there is (venv) in it.

AtharvaShekatkar commented 3 months ago

@anthonykim1 I'd checked the #23137 thread and tried the solutions listed there, but none worked for me. I also tried opting out of shell integration. That did get rid of the double (venv), but it didn't activate the environment. I haven't opted in for the experiment, and I'm not sure I can given that this is a work laptop.

Also, I'm not sure if this only happens on Mac, since I've only used conda with Windows. I'll try using venv and update the thread.

AtharvaShekatkar commented 3 months ago

@anthonykim1 The issue is fixed now. I didn't do anything, so I don't know what fixed it. Letting you know so you can stop tracking it here.

anthonykim1 commented 3 months ago

Great, thank you for letting me know! @AtharvaShekatkar Will still keep this open so we can better handle other's scenario too. Please feel free to open another issue or let me know if it comes back up again.

anthonykim1 commented 4 weeks ago

Closing this against: https://github.com/microsoft/vscode/issues/227467