microsoft / vscode-python

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

Native REPL should allow for environment configuration #23570

Open Apreche opened 3 weeks ago

Apreche commented 3 weeks ago

For a lot of Python projects, in my case Django web projects, simply running a straight Python REPL isn't very helpful. There's a lot of environment setup and initialization that is required for the REPL to be useful within the context of the project. That's why there are facilities such as ./manage.py shell and with django-extensions ./manage.py shell_plus.

Those tools are already capable of launching different Python REPLs such as the default one, bpython and iPython. It would be great if they could seamlessly launch the VSCode native Python REPL in the same way.

Failing that, there should still be extensive configuration options for the native REPL. What directory does is run in? What environment variables to set automatically? What Python code to run automatically at the start of every REPL instance?

iPython profiles is a good place to start looking for what kinds of configuration options are desirable. Every time I have ever wanted to change the behavior of a Python REPL, I've found it was possible to do with iPython.

anthonykim1 commented 2 weeks ago

Hello @Apreche, thanks much for your suggestions on improving the REPL experience. I kindly appreciate it.

Failing that, there should still be extensive configuration options for the native REPL. What directory does is run in? What environment variables to set automatically? What Python code to run automatically at the start of every REPL instance?

I do agree with you that equivalent or similar concept of IPython profiles would be great addition to the REPL experience, especially some sort of start up script that would run at the start of session which would allow users to automatically set their desired variables (such as environment variables) in a consistent manner. Or moreover, additional things that are listed in the example config file such as which scripts to automatically execute in each instance of iPython.

In terms of django related, I believe there is already a feature request on this: https://github.com/microsoft/vscode-python/issues/13027