JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
44.95k stars 5.42k forks source link

Julia REPL should show environment name inline #54235

Open kdheepak opened 2 months ago

kdheepak commented 2 months ago

Currently, without any changes to startup.jl, running julia from the command activates the root environment. I think this is a poor UX but it exists for safety reasons ( we don't want julia -e "using Foo" to load arbitrary malicious code ).

In internal documentation, I've recommended using julia --project=. as the default way new users should start a REPL.

Screenshot 2024-04-24 151916

But it can be easy to fat finger this and you can end up nesting levels a folder level. Here's an example I've seen people do accidentally:

Screenshot 2024-04-24 152357

Here's another screenshot I took of a colleague's computer from this morning, where they forgot to add a . in @.:

Screenshot 2024-04-24 114725

I think if the prompt has some indication of what the environment was, it would have been more clear to my colleague without me intervening. I've seen new users run into this issue enough times that I think it is worth making some UX change to the Julia REPL to improve the situation.

I particularly like how in conda, the environment is always listed as part of the shell:

(base) C:\Users\USERNAME\gitrepos\empty-new-folder>conda activate projectx

(projectx) C:\Users\USERNAME\gitrepos\empty-new-folder>

We don't have to go that far as to make the shell aware of Julia but making a prompt inside the Julia REPL more user friendly would be an improvement imho.

If we wanted to preserve space, we can leave the display as is for shorter terminal widths but with wider terminals are available, we can print the environment name on the right hand side. e.g.:

julia>                                         <(projectx)
jishnub commented 3 days ago

The current way to check the active project is to switch to the Pkg mode by pressing ]

KristofferC commented 3 days ago

I particularly like how in conda, the environment is always listed as part of the shell:

Ok, should we do that too then? Oh wait...? So maybe that isn't such a good idea, or?

kdheepak commented 3 days ago

The current way to check the active project is to switch to the Pkg mode by pressing ]

Do you press ] to sanity check for the active project and then press Backspace? I do it all the time after I open a Julia REPL.

Ok, should we do that too then? Oh wait...? So maybe that isn't such a good idea, or?

I'm not sure I particularly follow this comment, can you elaborate on what you think we should or should not do?

On Windows, when users install conda and open an Anaconda Command Prompt, it shows the current conda environment by default:

(base) C:\Users\USERNAME>

If a conda environment (or pixi environment or poetry environment) is active, the python instance you run will always be from that environment.

image

So once I start a REPL in Python I never need to check which environment I'm in. Particularly, once you activate an environment running scripts like python scripts/start.py run in the conda environment. This is easy for me and my team to remember and execute (though I still find people new to conda make mistakes here early on). So it makes sense for python / conda / pixi / poetry to add the environment name to the shell itself.

However, with julia, unlike conda, you have to specify the environment every time you execute a script or open a REPL. In my experience more people make mistakes at the beginning and continue to make mistakes even with experience. I've ran code in the wrong environment and I've been using Julia for more than 5 years. I think a change here to the UX will help minimize footguns for users.

I personally now have JULIA_PROJECT=@. set in my shell environment variables. And for me, having julia always default to the behavior that JULIA_PROJECT=@. enables would be the ideal solution. But barring that, even printing the current environment after the julia REPL starts would go a long way to making it easier for users to realize what is going on, imho.