Julia environments list

Starting a new Julia environment is very ease

julia>] activate test

(test) pkg> 

Is there a way to visualize a list of all the environments?

3 Likes

I recently found a file ~/.julia/logs/manifest_usage.toml which lists all recently used environments. I understand that this file is also used for ] gc.

4 Likes

Being able to list them all would be a nice feature. Basically, just parse that file, sort the keys and print them. Would be a nice addition to Pkg.

9 Likes

I arrived here looking for a way to list environments =)

julia> using Pkg

julia> Pkg.envdir()
"/home/jrun/data/.julia/environments"

shell> cd "/home/jrun/data/.julia"
/mnt/data/.julia

shell> ls -la
total 36
drwxr-xr-x  8 jrun jrun 6144 Aug  9 19:52 .
drwxr-xr-x  6 jrun jrun 6144 Aug  9 18:29 ..
drwxr-xr-x  5 jrun jrun 6144 Aug  9 19:51 artifacts
drwxr-xr-x  3 jrun jrun 6144 Aug  9 19:48 compiled
drwxr-xr-x  2 jrun jrun 6144 Aug  9 19:51 logs
drwxr-xr-x 16 jrun jrun 6144 Aug  9 19:51 packages
lrwxrwxrwx  1 jrun jrun   15 Aug  9 18:29 registries -> /tmp/registries
drwxr-xr-x  3 jrun jrun 6144 Aug  9 19:52 scratchspaces
drwxr-xr-x  3 jrun jrun 6144 Aug  9 18:29 servers

Looks like there is no env by default for the binary

Opened an issue https://github.com/JuliaLang/Pkg.jl/issues/2688

2 Likes

my workaround:

function list_Pkg_environments()
    env_dir = joinpath(Pkg.envdir(), string("v", VERSION)[1:end-2])
    # env_dir = Pkg.envdir()
    dir_list = readdir(env_dir, join= false)
    dir_list_full = readdir(env_dir, join= true)
    env_list = []
    for i_ = eachindex(dir_list)
        if isdir(dir_list_full[i_]) 
            println(dir_list[i_])
            push!(env_list, dir_list[i_]) 
        end
    end
    return env_list
end
1 Like

here is my function to select and activate a user defined Julia-environment:

function select_Pkg_environment(_environment::String="")
    curr_dir = pwd()
    env_dir = joinpath(Pkg.envdir(), string("v", VERSION)[1:end-2])
    # env_dir = Pkg.envdir()
    dir_list = readdir(env_dir, join= false)
    dir_list_full = readdir(env_dir, join= true)
    env_list = []
    for i_ = eachindex(dir_list)
        if isdir(dir_list_full[i_]) 
            # println(dir_list[i_])
            push!(env_list, dir_list[i_]) 
        end
    end
    if isempty(_environment)
        if isempty(env_list)
            println("No additional environments found!")
        else
            println("----   Number of available environments: ", length(env_list), "  ----")
            for i_ = eachindex(env_list)
                println(i_, ".) ",env_list[i_])
            end
            println("------------------------------------------------")
        end
    else
        if any(occursin.(_environment, string.(env_list)))
            if splitpath(Base.active_project())[end-1] != _environment
                cd(env_dir)
                Pkg.activate(_environment)
                cd(curr_dir)
                println("current dir: ", pwd())
            else
                @info(string("Environment \"", _environment, "is already loaded!"))
            end
        else
            @warn(string("Julia Pkg-environment: \"", _environment, "\" not found!"))
            @info("Call function without argument to list available environments.")
        end
    end
    return env_list
end

The strange thing is, that the command:

Pkg.activate("MyEnvironment")

opens a new user defined environment, if it is not yet known in a subfolder of Pkg.envdir().
And establishes the two environment files Project.toml & Manifest.toml in a sub-directory
with the name of the user defined environment as soon as a package is added via: Pkg.add("PackageName").
But the next time I give the identical command: Pkg.activate("MyEnvironment")
Pkg wants to establish a new environment definition directory at the current directory pwd().
Is this a bug or a feature?

1 Like