juliaup icon indicating copy to clipboard operation
juliaup copied to clipboard

Empty `DEPOT_PATH` segments throws an error

Open MichaelHatherly opened this issue 3 years ago • 1 comments

From the documented behaviour of JULIA_DEPOT_PATH in https://docs.julialang.org/en/v1/manual/environment-variables/#JULIA_DEPOT_PATH I'd expect passing an empty segment in JULIA_DEPOT_PATH to still launch julia, but juliaup throws an error when it's provided, as shown below. I can kind of work around it by pre-expanding it to what julia would do, but seems like juliaup should be able to handle this for me instead.

I assume it's probably just a case of adjusting https://github.com/JuliaLang/juliaup/blob/34b41f4f34d7dd5e5fca76761495c4bc4dfa5508/src/global_paths.rs#L24-L26= to expand to the user's home directory when encountering an empty string instead of throwing?

[mike@desktop ~]$ JULIA_DEPOT_PATH=":/home/mike/custom-depot" julia
Error: Trying to load all global paths.

Caused by:
    The `JULIA_DEPOT_PATH` environment variable contains a value that resolves to an an invalid path ``.
[mike@desktop ~]$ JULIA_DEPOT_PATH=":/home/mike/custom-depot" .julia/juliaup/julia-1.7.3+0~x64/bin/julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.3 (2022-05-06)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia>

MichaelHatherly avatar Jul 12 '22 16:07 MichaelHatherly

It also doesn't handle layered definitions:

$ JULIA_DEPOT_PATH="::/usr/share/julia" julia
Error: Trying to load all global paths.

Caused by:
    The `JULIA_DEPOT_PATH` environment variable contains a value that resolves to an an invalid path ``.

In this case, it should also look in /usr/share/julia for a juliaup dir (so that it doesn't needlessly redownload if there's a global version already), and write to ~/.julia/juliaup if necessary.

maleadt avatar Aug 10 '22 13:08 maleadt

I would like to implement this, but I'm utterly confused as to what the behaviour should be:

  • What should the get_bin_dir return if JULIAUP_BIN_DIR is not set? What if there are multiple segments in the path?
  • What should get_juliaup_home_path be?
    • If there are multiple segments, where some of them contain a juliaup sub-directory
    • If there is an invalid segment before a valid segment?
    • If JULIA_DEPOT_PATH is unset?
  • Should the binary directory be able to be different from the depot path, in case the latter is writeable, and the former is not?

jakobnissen avatar Nov 29 '22 13:11 jakobnissen

What should the get_bin_dir return if JULIAUP_BIN_DIR is not set? What if there are multiple segments in the path?

Should the binary directory be able to be different from the depot path, in case the latter is writeable, and the former is not?

I believe nothing should be changed there, everything can just stay the way it is. This entire part of the implementation is unrelated to JULIA_DEPOT_PATH.

I think really all we need to do is change get_juliaup_home_path in the following way:

  • If JULIA_DEPOT_PATH is not set, just keep the current behavior.
  • Keep the split at https://github.com/JuliaLang/juliaup/blob/e5208f9f85b32bbd04f21d5d58cdcbae517640ce/src/global_paths.rs#L24, but then don't just grab the first element, but instead put things into a vector.
  • Go through the vector just created and replace every empty element with an expanded path as described in https://docs.julialang.org/en/v1/manual/environment-variables/#JULIA_DEPOT_PATH.
  • Then loop through the paths vector until one of the depots there has an actual juliaup/juliaup.json file, i.e. until we find a depot that has a Juliaup installation in it. If so, return that juliaup path.
  • If none of the vectors contains an existing juliaup/juliaup.json, return the first one so that a new one gets initialized there.

I believe that implementation would fix the issue here, and then also actually either help or fix as well https://github.com/JuliaLang/juliaup/issues/257 and https://github.com/JuliaLang/juliaup/issues/276.

davidanthoff avatar Nov 29 '22 17:11 davidanthoff