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

support micromamba as a backend #680

Closed
yarnabrina opened this issue Jan 3, 2023 · 1 comment · Fixed by #807
Closed

support micromamba as a backend #680

yarnabrina opened this issue Jan 3, 2023 · 1 comment · Fixed by #807

Comments

@yarnabrina
Copy link

How would this feature be useful?

I would like to be able to use micromamba along with mamba/conda/venv. It's a lot smaller/faster than mamba (that's why we use it in our Gitlab CI flows), and to my knowledge lacks no functionality that is required for nox backend purposes.

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Anything else?

No response

@mforbes
Copy link

mforbes commented Jun 15, 2023

Here is a hacky strategy to do this now. The idea is to link your micromamba executable to conda somewhere on PATH. Here I effectively do

ln <micromamba> build/bin/conda
export PATH="./build/bin;${PATH}"

Here is an example which uses micromamba to install the fftw libraries, then pip installs pyfftw and runs a test.

# noxfile.py
import os
import subprocess

import nox

try:
    MICROMAMBA = subprocess.check_output(["type", "-p", "micromamba"]).strip().decode()
except:
    MICROMAMBA = None

if MICROMAMBA:
    BIN_DIR = os.path.join("build", "bin")
    CONDA = os.path.join(BIN_DIR, "conda")
    if not os.path.exists(CONDA):
        os.makedirs(BIN_DIR, exist_ok=True)
        os.link(MICROMAMBA, CONDA)
    os.environ["PATH"] = os.pathsep.join([BIN_DIR, os.environ["PATH"]])

# If on Mac OS X Silicon and you need to use Rosetta
os.environ["CONDA_SUBDIR"] = "osx-64"

args = dict(python=["3.10", "3.11"])


@nox.session(venv_backend="conda", venv_params=["-c", "defaults"], **args)
def test(session):
    # The following fails with micromamba -- gets quoted to '"fftw>=0.3.10"'
    #session.conda_install("fftw>=0.3.10", channel="conda-forge")
    session.conda_install("fftw", channel="conda-forge")
    session.install("pyfftw>=0.13.1", "pytest")
    session.run("pytest", "tests")

I noticed one bug: I could not specify the version of fftw:

    session.conda_install("fftw>=0.3.10", channel="conda-forge")

This gets quoted as '"fftw>=0.3.10"' by _dblquote_pkg_install_args, and then micromamba thinks this is a package name. It should instead be quoted to "fftw>=0.3.10". This will need to be fixed if micromamba is going to be used.

Desired Features

It would be nice if there were some hooks one could use to change the session behavior so that users can implement custom solutions before features like this are fully implemented. For example:

  • Provide a way of changing the conda executable to micromamba so the link and PATH manipulations are not needed.
  • Maybe provide a hook that can be called before the virtual environment is created so that one could change venv.conda_cmd.
  • Maybe provide a way of subclassing the Session object so users could hook in, overloading features as needed. (Is there an easy way of doing this now? Things seem pretty hard-coded in terms of conda functionality.)

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

Successfully merging a pull request may close this issue.

2 participants