-
Notifications
You must be signed in to change notification settings - Fork 222
/
nu_conda.nu
80 lines (65 loc) · 1.81 KB
/
nu_conda.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
export-env {
let-env CONDA_BASE_PATH = (if ((sys).host.name == "Windows") {$env.Path} else {$env.PATH})
let info = (
if not (which mamba | is-empty) {
(mamba info --envs --json | from json)
} else if not (which conda | is-empty) {
(conda info --envs --json | from json)
} else {
('{"root_prefix": "", "envs": ""}' | from json)
})
let-env CONDA_ROOT = $info.root_prefix
let-env CONDA_ENVS = ($info.envs | reduce -f {} {|it, acc|
if $it == $info.root_prefix {
$acc | upsert "base" $it
} else {
$acc | upsert ($it | path basename) $it
}})
let-env CONDA_CURR = null
}
export def-env activate [name: string] {
if ($env.CONDA_ROOT | is-empty) {
echo "Neither Conda nor Mamba is valid."
return
}
if not $name in $env.CONDA_ENVS {
echo $"Environment ($name) is invalid. Available:"
echo $env.CONDA_ENVS
return
}
let new_path = (
if ((sys).host.name == "Windows") {
update-path-windows ($env.CONDA_ENVS | get $name)
} else {
update-path-linux ($env.CONDA_ENVS | get $name)
})
load-env ({CONDA_CURR: $name} | merge $new_path)
}
export def-env deactivate [] {
if ($env.CONDA_ROOT | is-empty) {
echo "Neither Conda nor Mamba is valid."
return
}
let-env CONDA_CURR = null
load-env {Path: $env.CONDA_BASE_PATH, PATH: $env.CONDA_BASE_PATH}
}
def update-path-linux [env_path: path] {
let env_path = [
$env_path,
([$env_path, "bin"] | path join)
]
return {
Path: ($env.PATH | prepend $env_path),
PATH: ($env.PATH | prepend $env_path)
}
}
def update-path-windows [env_path: path] {
let env_path = [
$env_path,
([$env_path, "Scripts"] | path join),
]
return {
Path: ($env.Path | prepend $env_path),
PATH: ($env.Path | prepend $env_path)
}
}