STASIS
A pipeline delivery generator
Loading...
Searching...
No Matches
conda.h File Reference
#include <stdio.h>
#include <string.h>
#include <sys/utsname.h>
#include "core.h"
#include "download.h"
Include dependency graph for conda.h:

Go to the source code of this file.

Data Structures

struct  CondaCapabilities
 Collection of feature flags to support older, newer, and transitional versions of conda/mamba. More...
struct  MicromambaInfo

Macros

#define CONDA_INSTALL_PREFIX   "conda"
#define PYPI_INDEX_DEFAULT   "https://pypi.org/simple"
#define PKG_USE_PIP   0
#define PKG_USE_CONDA   1
#define PKG_NOT_FOUND   0
#define PKG_FOUND   1
#define PKG_INDEX_PROVIDES_ERROR_MESSAGE_OFFSET   (-10)
#define PKG_E_SUCCESS   (PKG_INDEX_PROVIDES_ERROR_MESSAGE_OFFSET + 0)
#define PKG_INDEX_PROVIDES_E_INTERNAL_MODE_UNKNOWN   (PKG_INDEX_PROVIDES_ERROR_MESSAGE_OFFSET + 1)
#define PKG_INDEX_PROVIDES_E_INTERNAL_LOG_HANDLE   (PKG_INDEX_PROVIDES_ERROR_MESSAGE_OFFSET + 2)
#define PKG_INDEX_PROVIDES_E_MANAGER_RUNTIME   (PKG_INDEX_PROVIDES_ERROR_MESSAGE_OFFSET + 3)
#define PKG_INDEX_PROVIDES_E_MANAGER_SIGNALED   (PKG_INDEX_PROVIDES_ERROR_MESSAGE_OFFSET + 4)
#define PKG_INDEX_PROVIDES_E_MANAGER_EXEC   (PKG_INDEX_PROVIDES_ERROR_MESSAGE_OFFSET + 5)
#define PKG_INDEX_PROVIDES_FAILED(ECODE)

Functions

int conda_capable (struct CondaCapabilities *ccap, const char *root)
void conda_capable_free (struct CondaCapabilities *ccap)
int micromamba_install (const struct MicromambaInfo *info)
int micromamba (const struct MicromambaInfo *info, char *command,...)
int python_exec (const char *args)
int pip_exec (const char *args)
char * python_importlib_metadata_version (const char *package_name)
int conda_exec (const char *args)
int conda_activate (const char *root, const char *env_name)
int conda_setup_headless (struct CondaCapabilities *cc)
int conda_env_create_from_uri (char *name, char *uri, char *python_version)
int conda_env_create (char *name, char *python_version, char *packages)
int conda_env_remove (char *name)
int conda_env_export (char *name, char *output_dir, char *output_filename)
int conda_index (const char *path)
int pkg_index_provides (int mode, const char *index, const char *spec, const char *logdir)
const char * pkg_index_provides_strerror (int code)
char * conda_get_active_environment ()
int conda_env_exists (const char *root, const char *name)

Macro Definition Documentation

◆ PKG_INDEX_PROVIDES_FAILED

#define PKG_INDEX_PROVIDES_FAILED ( ECODE)
Value:
((ECODE) <= PKG_INDEX_PROVIDES_ERROR_MESSAGE_OFFSET)

Function Documentation

◆ conda_activate()

int conda_activate ( const char * root,
const char * env_name )

Configure the runtime environment to use Conda/Mamba

if (conda_activate("/path/to/conda/installation", "base")) {
fprintf(stderr, "Failed to activate conda's base environment\n");
exit(1);
}
int conda_activate(const char *root, const char *env_name)
Definition conda.c:496
Parameters
rootdirectory where conda is installed
env_namethe conda environment to activate
Returns
0 on success, -1 on error

◆ conda_capable()

int conda_capable ( struct CondaCapabilities * ccap,
const char * root )

Check for the existence of "Conda" and set flags based on the availability of features

Parameters
ccapa pointer to an empty struct CondaCapabilities
rootconda installation root directory
Returns
0 on success
Here is the call graph for this function:

◆ conda_capable_free()

void conda_capable_free ( struct CondaCapabilities * ccap)

Free memory allocated by conda_capable

Parameters
ccapa pointer to a populated struct CondaCapabilities

◆ conda_env_create()

int conda_env_create ( char * name,
char * python_version,
char * packages )

Create a Conda environment using generic package specs

// Create a basic environment without any conda packages
if (conda_env_create("myenv", "3.11", NULL)) {
fprintf(stderr, "Environment creation failed\n");
exit(1);
}
// Create a basic environment and install conda packages
if (conda_env_create("myenv", "3.11", "hstcal fitsverify")) {
fprintf(stderr, "Environment creation failed\n");
exit(1);
}
int conda_env_create(char *name, char *python_version, char *packages)
Definition conda.c:793
Parameters
nameEnvironment name
python_versionDesired version of Python
packagesPackages to install (or NULL)
Returns
exit code from "conda"

◆ conda_env_create_from_uri()

int conda_env_create_from_uri ( char * name,
char * uri,
char * python_version )

Creates a Conda environment from a YAML config

if (conda_env_create_from_uri("myenv", "https://myserver.tld/environment.yml")) {
fprintf(stderr, "Environment creation failed\n");
exit(1);
}
int conda_env_create_from_uri(char *name, char *uri, char *python_version)
Definition conda.c:740
Parameters
nameName of new environment to create
uri/path/to/environment.yml
urifile:///path/to/environment.yml
urihttp://myserver.tld/environment.yml
urihttps://myserver.tld/environment.yml
uriftp://myserver.tld/environment.yml
Returns
exit code from "conda"
Here is the call graph for this function:

◆ conda_env_export()

int conda_env_export ( char * name,
char * output_dir,
char * output_filename )

Export a Conda environment in YAML format

if (conda_env_export("myenv", "./", "myenv.yml")) {
fprintf(stderr, "Unable to export environment\n");
exit(1);
}
int conda_env_export(char *name, char *output_dir, char *output_filename)
Definition conda.c:814
Parameters
nameEnvironment name to export
output_dirDestination directory
output_filenameDestination file name
Returns
exit code from "conda"

◆ conda_env_remove()

int conda_env_remove ( char * name)

Remove a Conda environment

if (conda_env_remove("myenv")) {
fprintf(stderr, "Unable to remove conda environment\n");
exit(1);
}
int conda_env_remove(char *name)
Definition conda.c:808
Parameters
nameEnvironment name
Returns
exit code from "conda"

◆ conda_exec()

int conda_exec ( const char * args)

Execute conda (or if possible, mamba) Conda/Mamba is determined by PATH

if (conda_exec("env list")) {
fprintf(stderr, "Failed to list conda environments\n");
exit(1);
}
int conda_exec(const char *args)
Definition conda.c:383
Parameters
argsarguments to pass to Conda
Returns
exit code from Conda
Here is the call graph for this function:

◆ conda_index()

int conda_index ( const char * path)

Run "conda index" on a local conda channel

if (conda_index("/path/to/channel")) {
fprintf(stderr, "Unable to index requested path\n");
exit(1);
}
int conda_index(const char *path)
Definition conda.c:846
Parameters
pathTop-level directory of conda channel
Returns
exit code from "conda"

◆ conda_setup_headless()

int conda_setup_headless ( struct CondaCapabilities * cc)

Configure the active conda installation for headless operation

Here is the call graph for this function:

◆ micromamba()

int micromamba ( const struct MicromambaInfo * info,
char * command,
... )

Execute micromamba

Parameters
infoMicromambaInfo data structure (must be populated before use)
commandprintf-style formatter string
...variadic arguments
Returns
exit code
Here is the call graph for this function:

◆ micromamba_install()

int micromamba_install ( const struct MicromambaInfo * info)

Download and install Micromamba

Parameters
infoMicromambaInfo data structure (must be populated before use)
Returns
0 on successful installation
Here is the call graph for this function:

◆ pip_exec()

int pip_exec ( const char * args)

Execute Pip Pip is determined by PATH

if (pip_exec("freeze")) {
fprintf(stderr, "pip freeze failed\n");
exit(1);
}
int pip_exec(const char *args)
Definition conda.c:182
Parameters
argsarguments to pass to Pip
Returns
exit code from Pip

◆ pkg_index_provides()

int pkg_index_provides ( int mode,
const char * index,
const char * spec,
const char * logdir )

Determine whether a package index contains a package

int result = pkg_index_provides(USE_PIP, NULL, "numpy>1.26");
if (PKG_INDEX_PROVIDES_FAILED(result)) {
fprintf(stderr, "failed: %s\n", pkg_index_provides_strerror(result));
exit(1);
} else if (result == PKG_NOT_FOUND) {
// package does not exist upstream
} else {
// package exists upstream
}
int pkg_index_provides(int mode, const char *index, const char *spec, const char *logdir)
Definition conda.c:236
Parameters
modeUSE_PIP
modeUSE_CONDA
indexa file system path or url pointing to a simple index or conda channel
speca pip package specification (e.g. name==1.2.3)
logdirthe directory to store the output log
speca conda package specification (e.g. name=1.2.3)
Returns
PKG_NOT_FOUND, if not found
PKG_FOUND, if found
PKG_E_INDEX_PROVIDES_{ERROR}, on error (see conda.h)
Here is the call graph for this function:

◆ python_exec()

int python_exec ( const char * args)

Execute Python Python interpreter is determined by PATH

if (python_exec("-c 'printf(\"Hello world\")'")) {
fprintf(stderr, "Hello world failed\n");
exit(1);
}
int python_exec(const char *args)
Definition conda.c:167
Parameters
argsarguments to pass to interpreter
Returns
exit code from python interpreter

◆ python_importlib_metadata_version()

char * python_importlib_metadata_version ( const char * package_name)

Use importlib to resolve the version of an installed package

char *numpy_version = python_importlib_metadata_version("numpy");
if (!numpy_version) {
fprintf(stderr, "failed to get numpy version\n");
exit(1);
}
printf("numpy version: %s\n", numpy_version);
free(numpy_version);
char * python_importlib_metadata_version(const char *package_name)
Definition conda.c:197
Parameters
package_nameof installed python package
Returns
Here is the call graph for this function: