(prefix, packages)
Ensure packages (from conda-forge) are installed in the conda prefix.

    Note that conda seem to update dependencies by default, so there is probably
    no need to have a update parameter exposed for this function.
Ensure packages (from conda-forge) are installed in the conda prefix.
Ensure packages ( from conda - forge ) are installed in the conda prefix .
def ensure_conda_packages(prefix, packages):
    """
    Ensure packages (from conda-forge) are installed in the conda prefix.

    Note that conda seem to update dependencies by default, so there is probably
    no need to have a update parameter exposed for this function.
    """
    conda_executable = [os.path.join(prefix, "bin", "mamba")]
    abspath = os.path.abspath(prefix)
    # Let subprocess errors propagate
    # Explicitly do *not* capture stderr, since that's not always JSON!
    # Scripting conda is a PITA!
    # FIXME: raise different exception when using
    raw_output = subprocess.check_output(
        conda_executable
        + [
            "install",
            "-c",
            "conda-forge",  # Make customizable if we ever need to
            "--json",
            "--prefix",
            abspath,
        ]
        + packages
    ).decode()
    # `conda install` outputs JSON lines for fetch updates,
    # and a undelimited output at the end. There is no reasonable way to
    # parse this outside of this kludge.
    filtered_output = "\n".join(
        [
            l
            for l in raw_output.split("\n")
            # Sometimes the JSON messages start with a \x00. The lstrip removes these.
            # conda messages seem to randomly throw \x00 in places for no reason
            if not l.lstrip("\x00").startswith('{"fetch"')
        ]
    )
    output = json.loads(filtered_output.lstrip("\x00"))
    if "success" in output and output["success"] == True:
        return
    fix_permissions(prefix)
def ensure_conda_packages ( prefix , packages ) : conda_executable = [ os . path . join ( prefix , "bin" , "mamba" ) ] abspath = os . path . abspath ( prefix ) # Let subprocess errors propagate # Explicitly do *not* capture stderr, since that's not always JSON! # Scripting conda is a PITA! # FIXME: raise different exception when using raw_output = subprocess . check_output ( conda_executable + [ "install" , "-c" , "conda-forge" , # Make customizable if we ever need to "--json" , "--prefix" , abspath , ] + packages ) . decode ( ) # `conda install` outputs JSON lines for fetch updates, # and a undelimited output at the end. There is no reasonable way to # parse this outside of this kludge. filtered_output = "\n" . join ( [ l for l in raw_output . split ( "\n" ) # Sometimes the JSON messages start with a \x00. The lstrip removes these. # conda messages seem to randomly throw \x00 in places for no reason if not l . lstrip ( "\x00" ) . startswith ( '{"fetch"' ) ] ) output = json . loads ( filtered_output . lstrip ( "\x00" ) ) if "success" in output and output [ "success" ] == True : return fix_permissions ( prefix )