Skip to content

micromamba support #578

Closed
Closed

Description

@eikaramba

I adapted the conda script to also support micromamba. i am not a nushell expert, so i am hesitant to make a PR out of it, but wanted to first post it here for other people to find.

BTW i first needed to create a scripts folder and uncomment the command in the env.nu file to actually make it load the module

export-env {
  $env.CONDA_BASE_PATH = (if ((sys).host.name == "Windows") {$env.Path} else {$env.PATH})

  mut info = (
      if not (which micromamba | is-empty) {
        (micromamba env list --json | from json)
      } else if not (which conda | is-empty) {
        (conda info --envs --json | from json)
      } else {
        ('{"root_prefix": "", "envs": ""}' | from json)
      })
  $info.root_prefix = (micromamba info --json | from json)."base environment"

  $env.CONDA_ROOT = $info.root_prefix

  $env.CONDA_ENVS = ($info.envs | reduce -f {} {|it, acc|
      if $it == $env.CONDA_ROOT {
        $acc | upsert "base" $it
      } else {
        $acc | upsert ($it | path basename) $it
      }})

  $env.CONDA_CURR = null
}

export def-env activate [name: string] {
  if ($env.CONDA_ROOT | is-empty) {
    print "Neither Conda nor Mamba is valid."
    return
  }

  if not ($name in $env.CONDA_ENVS) {
    print $"Environment ($name) is invalid. Available:"
    print $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) {
    print "Neither Conda nor Mamba is valid."
    return
  }

  $env.CONDA_CURR = null

  load-env {Path: $env.CONDA_BASE_PATH, PATH: $env.CONDA_BASE_PATH}
}

export def-env list [] {
  print $env.CONDA_ENVS
}

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)
  }
}

i just changed the mamba executable, adapted the command and quickfixed the mutable variable.

Activity

  1. added a commit that references this issue on Mar 26, 2024
  2. Kissaki commented on Apr 20, 2025

    @Kissaki
    Contributor

    This has been replaced by PR #800. @fdncred could you please close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions