Skip to content

Commit

Permalink
Add nu shell test
Browse files Browse the repository at this point in the history
Added condabin to prefix
  • Loading branch information
cvanelteren committed Aug 6, 2023
1 parent 0f2f5ac commit 1dbe2a6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
22 changes: 16 additions & 6 deletions libmamba/data/micromamba.nu
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ def-env "micromamba activate" [name: string] {
)

if $env.MAMBA_SHLVL? == null {
$env.MAMBA_SHLVL = "0"
$env.MAMBA_SHLVL = 0
}


# fetch path of current environment and update if present
let p = ($envs | transpose key value | find $name)
if ($p | length) >= 1 {
let path = ([($p.value.0 | ansi strip) "bin"] | path join)
if not $path in $env.PATH {
$env.PATH = ($env.PATH | prepend $path)
$env.MICROMAMBA_CURRENT_ENV = ($p.key.0 | ansi strip)
$env.MAMBA_CURRENT_ENV = ($p.key.0 | ansi strip)
$env.CONDA_PREFIX = ($p.value.0 | ansi strip| path join condabin)
}
}
}
Expand All @@ -30,11 +32,19 @@ def-env "micromamba deactivate" [] {
}
)
# fetch path of current environment and remove current environment
let p = ($envs | transpose key value | find $env.MICROMAMBA_CURRENT_ENV)
let p = ($envs | transpose key value | find $env.MAMBA_CURRENT_ENV)
if ($p | length) >= 1 {
let path = ([$p.value.0 "bin"] | path join)
$env.PATH = ($env.PATH | filter {|it| $it != $path})
$env.MICROMAMBA_CURRENT_ENV = ""
let path = ([$p.value.0 "bin"] | path join)
$env.PATH = ($env.PATH | filter {|it| $it != $path})
$env.MAMBA_CURRENT_ENV = ""
$env.CONDA_PREFIX = ($env.MAMBA_ROOT_PREFIX | path join condabin )
}
}

# adding conda bin in current env
if $env.CONDA_SHLVL? == null {
$env.CONDA_SHLVL = 0
let conda_prefix = ($env.MAMBA_ROOT_PREFIX | path join condabin )
$env.PATH = ( $env.PATH | append $conda_prefix)
$env.CONDA_PREFIX = $conda_prefix
}
8 changes: 4 additions & 4 deletions libmamba/src/core/shell_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,10 @@ namespace mamba

content << "\n# >>> mamba initialize >>>\n";
content << "# !! Contents within this block are managed by 'mamba init' !!\n";
content << "$env.MICROMAMBA_MAMBA_EXE = " << mamba_exe << "\n";
content << "$env.MICROMAMBA_ROOT_PREFIX = " << env_prefix << "\n";
content << "$env.MICROMAMBA_CURRENT_ENV = \"\"\n";
content << "$env.PATH = ($env.PATH | append ([$env.MICROMAMBA_ROOT_PREFIX bin] | path join) | uniq)\n";
content << "$env.MAMBA_EXE = " << mamba_exe << "\n";
content << "$env.MAMBA_ROOT_PREFIX = " << env_prefix << "\n";
content << "$env.MAMBA_CURRENT_ENV = \"\"\n";
content << "$env.PATH = ($env.PATH | append ([$env.MAMBA_ROOT_PREFIX bin] | path join) | uniq)\n";
content << "source " << env_prefix.string() << "/etc/profile.d/micromamba.nu\n";
content << "# <<< mamba initialize <<<\n";
return content.str();
Expand Down
22 changes: 16 additions & 6 deletions mamba/mamba/shell_templates/micromamba.nu
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ def-env "micromamba activate" [name: string] {
)

if $env.MAMBA_SHLVL? == null {
$env.MAMBA_SHLVL = "0"
$env.MAMBA_SHLVL = 0
}


# fetch path of current environment and update if present
let p = ($envs | transpose key value | find $name)
if ($p | length) >= 1 {
let path = ([($p.value.0 | ansi strip) "bin"] | path join)
if not $path in $env.PATH {
$env.PATH = ($env.PATH | prepend $path)
$env.MICROMAMBA_CURRENT_ENV = ($p.key.0 | ansi strip)
$env.MAMBA_CURRENT_ENV = ($p.key.0 | ansi strip)
$env.CONDA_PREFIX = ($p.value.0 | ansi strip| path join condabin)
}
}
}
Expand All @@ -30,11 +32,19 @@ def-env "micromamba deactivate" [] {
}
)
# fetch path of current environment and remove current environment
let p = ($envs | transpose key value | find $env.MICROMAMBA_CURRENT_ENV)
let p = ($envs | transpose key value | find $env.MAMBA_CURRENT_ENV)
if ($p | length) >= 1 {
let path = ([$p.value.0 "bin"] | path join)
$env.PATH = ($env.PATH | filter {|it| $it != $path})
$env.MICROMAMBA_CURRENT_ENV = ""
let path = ([$p.value.0 "bin"] | path join)
$env.PATH = ($env.PATH | filter {|it| $it != $path})
$env.MAMBA_CURRENT_ENV = ""
$env.CONDA_PREFIX = ($env.MAMBA_ROOT_PREFIX | path join condabin )
}
}

# adding conda bin in current env
if $env.CONDA_SHLVL? == null {
$env.CONDA_SHLVL = 0
let conda_prefix = ($env.MAMBA_ROOT_PREFIX | path join condabin )
$env.PATH = ( $env.PATH | append $conda_prefix)
$env.CONDA_PREFIX = $conda_prefix
}
2 changes: 1 addition & 1 deletion micromamba/tests/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def skip_if_shell_incompat(shell_type):

@pytest.mark.parametrize(
"shell_type",
["bash", "posix", "powershell", "cmd.exe", "xonsh", "zsh", "fish", "tcsh"],
["bash", "posix", "powershell", "cmd.exe", "xonsh", "zsh", "fish", "tcsh", "nu"],
)
def test_hook(tmp_home, tmp_root_prefix, shell_type):
res = helpers.shell("hook", "-s", shell_type)
Expand Down

0 comments on commit 1dbe2a6

Please sign in to comment.