Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

micromamba support #578

Open
eikaramba opened this issue Aug 17, 2023 · 0 comments
Open

micromamba support #578

eikaramba opened this issue Aug 17, 2023 · 0 comments

Comments

@eikaramba
Copy link

eikaramba commented Aug 17, 2023

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.

fdncred pushed a commit that referenced this issue Mar 26, 2024
I initially tried to get Micromamba to work with Nushell by using the
script from [this
issue](#578). But even after
fixing the syntax errors I couldn't activate any env.
With these modifications, Micromamba seems to be working fine.  
Please note that I'm far from a Nu expert so my code might not be very
idiomatic. If that is the case please tell me so and I'll be happy to do
the necessary changes.
maxim-uvarov pushed a commit to maxim-uvarov/nu_scripts_reduced_size that referenced this issue Oct 12, 2024
I initially tried to get Micromamba to work with Nushell by using the
script from [this
issue](nushell/nu_scripts#578). But even after
fixing the syntax errors I couldn't activate any env.
With these modifications, Micromamba seems to be working fine.  
Please note that I'm far from a Nu expert so my code might not be very
idiomatic. If that is the case please tell me so and I'll be happy to do
the necessary changes.
maxim-uvarov pushed a commit to maxim-uvarov/nu_scripts_reduced_size that referenced this issue Oct 13, 2024
I initially tried to get Micromamba to work with Nushell by using the
script from [this
issue](nushell/nu_scripts#578). But even after
fixing the syntax errors I couldn't activate any env.
With these modifications, Micromamba seems to be working fine.  
Please note that I'm far from a Nu expert so my code might not be very
idiomatic. If that is the case please tell me so and I'll be happy to do
the necessary changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant