1
1
module Conda
2
2
3
- import .. External
3
+ import .. External, JSON
4
4
5
5
const _env = Ref (" " )
6
6
@@ -15,22 +15,20 @@ const ENV_STACK = Vector{Dict{String,String}}()
15
15
function activate ()
16
16
push! (ENV_STACK, copy (ENV ))
17
17
e = env ()
18
- # these steps imitate a minimal "conda activate"
19
- # TODO : run "conda shell.posix activate ..." or "conda shell.cmd.exe activate ...", capture the resulting environment, and set that here
20
- oldlvl = parse (Int, get (ENV , " CONDA_SHLVL" , " 0" ))
21
- if oldlvl > 0
22
- ENV [" CONDA_PREFIX_$oldlvl " ] = ENV [" CONDA_PREFIX" ]
18
+ shell = Sys. iswindows () ? " cmd.exe" : " posix"
19
+ pathsep = Sys. iswindows () ? " ;" : " :"
20
+ # ask conda for a JSON description of how it would activate the environment
21
+ info = JSON. parse (read (External. Conda. _set_conda_env (` $(External. Conda. conda) shell.$shell +json activate $e ` ), String))
22
+ # make these changes
23
+ # TODO : we currently ignore info["scripts"]["activate"]
24
+ # run these in a subshell, print the resulting environment vars, and merge into ENV
25
+ # (or just run the full `conda shell.* activate *` script)
26
+ ENV [" PATH" ] = join (info[" path" ][" PATH" ], pathsep)
27
+ for k in info[" vars" ][" unset" ]
28
+ delete! (ENV , k)
23
29
end
24
- ENV [" CONDA_SHLVL" ] = string (oldlvl+ 1 )
25
30
ENV [" CONDA_PREFIX" ] = e
26
- ENV [" CONDA_DEFAULT_ENV" ] = e
27
- ENV [" CONDA_PROMPT_MODIFIER" ] = " ($e ) "
28
- ENV [" _CE_M" ] = " "
29
- ENV [" _CE_CONDA" ] = " "
30
- ENV [" CONDA_PYTHON_EXE" ] = python_exe ()
31
- oldpath = get (ENV , " PATH" , " " )
32
- pathsep = Sys. iswindows () ? " ;" : " :"
33
- ENV [" PATH" ] = oldpath == " " ? External. Conda. bin_dir (e) : (External. Conda. bin_dir (e) * pathsep * oldpath)
31
+ merge! (ENV , info[" vars" ][" export" ])
34
32
return
35
33
end
36
34
0 commit comments