aboutsummaryrefslogtreecommitdiff
path: root/include/conda.h
blob: 169bc5847bd2e584af6192302441dd0e59cf61b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//! @file conda.h
#ifndef STASIS_CONDA_H
#define STASIS_CONDA_H

#include <stdio.h>
#include <string.h>
#include "core.h"

#define CONDA_INSTALL_PREFIX "conda"
#define PYPI_INDEX_DEFAULT "https://pypi.org/simple"

struct MicromambaInfo {
    char *micromamba_prefix;
    char *conda_prefix;
};

/**
 * Execute micromamba
 * @param info MicromambaInfo data structure (must be populated before use)
 * @param command printf-style formatter string
 * @param ... variadic arguments
 * @return exit code
 */
int micromamba(struct MicromambaInfo *info, char *command, ...);

/**
 * Execute Python
 * Python interpreter is determined by PATH
 *
 * ```c
 * if (python_exec("-c 'printf(\"Hello world\")'")) {
 *     fprintf(stderr, "Hello world failed\n");
 *     exit(1);
 * }
 * ```
 *
 * @param args arguments to pass to interpreter
 * @return exit code from python interpreter
 */
int python_exec(const char *args);

/**
 * Execute Pip
 * Pip is determined by PATH
 *
 * ```c
 * if (pip_exec("freeze")) {
 *     fprintf(stderr, "pip freeze failed\n");
 *     exit(1);
 * }
 * ```
 *
 * @param args arguments to pass to Pip
 * @return exit code from Pip
 */
int pip_exec(const char *args);

/**
 * Execute conda (or if possible, mamba)
 * Conda/Mamba is determined by PATH
 *
 * ```c
 * if (conda_exec("env list")) {
 *     fprintf(stderr, "Failed to list conda environments\n");
 *     exit(1);
 * }
 * ```
 *
 * @param args arguments to pass to Conda
 * @return exit code from Conda
 */
int conda_exec(const char *args);

/**
 * Configure the runtime environment to use Conda/Mamba
 *
 * ```c
 * if (conda_activate("/path/to/conda/installation", "base")) {
 *     fprintf(stderr, "Failed to activate conda's base environment\n");
 *     exit(1);
 * }
 * ```
 *
 * @param root directory where conda is installed
 * @param env_name the conda environment to activate
 * @return 0 on success, -1 on error
 */
int conda_activate(const char *root, const char *env_name);

/**
 * Configure the active conda installation for headless operation
 */
int conda_setup_headless();

/**
 * Creates a Conda environment from a YAML config
 *
 * ```c
 * if (conda_env_create_from_uri("myenv", "https://myserver.tld/environment.yml")) {
 *     fprintf(stderr, "Environment creation failed\n");
 *     exit(1);
 * }
 * ```
 *
 * @param name Name of new environment to create
 * @param uri /path/to/environment.yml
 * @param uri file:///path/to/environment.yml
 * @param uri http://myserver.tld/environment.yml
 * @param uri https://myserver.tld/environment.yml
 * @param uri ftp://myserver.tld/environment.yml
 * @return exit code from "conda"
 */
int conda_env_create_from_uri(char *name, char *uri);

/**
 * Create a Conda environment using generic package specs
 *
 * ```c
 * // 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);
 * }
 * ```
 *
 * @param name Environment name
 * @param python_version Desired version of Python
 * @param packages Packages to install (or NULL)
 * @return exit code from "conda"
 */
int conda_env_create(char *name, char *python_version, char *packages);

/**
 * Remove a Conda environment
 *
 * ```c
 * if (conda_env_remove("myenv")) {
 *     fprintf(stderr, "Unable to remove conda environment\n");
 *     exit(1);
 * }
 * ```
 *
 * @param name Environment name
 * @return exit code from "conda"
 */
int conda_env_remove(char *name);

/**
 * Export a Conda environment in YAML format
 *
 * ```c
 * if (conda_env_export("myenv", "./", "myenv.yml")) {
 *     fprintf(stderr, "Unable to export environment\n");
 *     exit(1);
 * }
 * ```
 *
 * @param name Environment name to export
 * @param output_dir Destination directory
 * @param output_filename Destination file name
 * @return exit code from "conda"
 */
int conda_env_export(char *name, char *output_dir, char *output_filename);

/**
 * Run "conda index" on a local conda channel
 *
 * ```c
 * if (conda_index("/path/to/channel")) {
 *     fprintf(stderr, "Unable to index requested path\n");
 *     exit(1);
 * }
 * ```
 *
 * @param path Top-level directory of conda channel
 * @return exit code from "conda"
 */
int conda_index(const char *path);

int python_package_exists(const char *index_url, const char *name, const char *version);

#endif //STASIS_CONDA_H