let configured ~conda_env ~(run_program : Machine.Make_fun.t) ~host =
let open KEDSL in
let create_env =
com ~conda_env "create -y -q --prefix %s python=%d"
(envs_dir ~conda_env // conda_env.name)
(match conda_env.python_version with `Python2 -> 2 | `Python3 -> 3)
in
let install_package (package, version) =
Program.(
shf "conda install -y %s%s"
package
(match version with `Latest -> "" | `Version v -> "=" ^ v)
)
in
let force_rm_package package =
Program.(shf "conda remove -y --force %s" package)
in
let make =
run_program
~requirements:[
`Internet_access;
`Self_identification ["conda"; "configuration"];
]
Program.(
sh create_env
&& shf "source %s %s" (activate ~conda_env) (envs_dir ~conda_env // conda_env.name)
&& chain (List.map ~f:(shf "conda config --add channels %s") conda_env.channels)
&& chain (List.map ~f:install_package conda_env.base_packages)
&& chain (List.map ~f:force_rm_package conda_env.banned_packages)
)
in
let edges = [ depends_on (installed ~run_program ~host ~conda_env) ] in
let product =
(single_file ~host (envs_dir ~conda_env // conda_env.name // "bin/conda")
:> < is_done : Common.KEDSL.Condition.t option >) in
let name =
sprintf "Configure conda: %s" conda_env.name in
workflow_node product ~make ~name ~edges