microsoft / vscode-python

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

Support for .envrc / direnv #14250

Closed tbenst closed 3 years ago

tbenst commented 4 years ago

VScode has great out-of-the-box suport for .envrc files: opening a terminal will automatically load the .envrc for example. Because of this behavior, many VSCode extensions also run in the .envrc environment, like the Julia plugin. Unfortunately, vscode-python is the exception.

Loading .envrc files is critical when using systems that do not have a python interpreter available on the path by default. In my case, I encounter this on Sherlock, Stanford's HPC, where I need to load modules before starting a Jupyter kernel. This is also problematic on NixOS and other sandoxed OSes, which may need a line or two of setup to bring dependencies into the current environment.

It would be great if VScode-python could first setup the environment using .envrc before launching the ipykernel. This is consistent with VScode's default behavior, and will enable HPC users to use Python Interactive on the cluster itself.

karthiknadig commented 4 years ago

Thank you for the suggestion! We have marked this issue as "needs decision" to make sure we have a conversation about your idea. We plan to leave this feature request open for at least a month to see how many đź‘Ť votes the opening comment gets to help us make our decision.

tbenst commented 4 years ago

Great thanks for the transparency! I added direnv to the title to help with users finding this issue with search

luabud commented 3 years ago

Thanks for the suggestion! We talked about it with the team and we have unfortunately decided we will not be moving forward with this idea. We think there isn't an enough widespread need for this to warrant the maintenance cost for the feature.

tbenst commented 3 years ago

Ok understood. Would you consider another approach for supporting python on HPC? Most of the worlds supercomputers (or at least all the ones I’ve used in the US) use a module system, and given both the rise of python in HPC and vscode, it would seem to be an obvious marriage. I doubt you have many users right now that run VSCode in HPC environments because it’s not possible on many systems.

The solution is trivial. It’s a single line of code that needs to run before calling python (in my case, module load py-scipystack). A .encrc file is a reasonable standard, but any solution that makes this simple to do is welcome.

Right now the only solution is to create a “fake python binary” that is actually a shell script that runs the module load command and passes arguments to a exec python call. Which is....fine for me...but I doubt you will gain HPC users as is with this clunky solution.

Edit: for additional context, users on HPC will actually be running vscode-python inside a remote-ssh session, so it’s not possible to run the module load command before launching vscode.

tbenst commented 3 years ago

@luabud few other users with same issue: https://www.reddit.com/r/vscode/comments/g7joeg/setting_up_a_remote_ssh_python_developing_setup/ https://stackoverflow.com/questions/65190772/vscode-remote-development-server-prerequisites-on-hpc-server-managed-via-environ

More information on environment modules, that I and the users on the two link above mention: http://modules.sourceforge.net/