aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2024-10-04 10:57:09 -0400
committerGitHub <noreply@github.com>2024-10-04 10:57:09 -0400
commit6e72330a3cc8d571b14f2234ed8fc2778b5e9b86 (patch)
tree53a131a9dc69b2da1eef2eebfd2a449fcf702ce0 /src
parent204f1965caa824dda632b0887e3aa6cb805b18d5 (diff)
parent485de019d37dd712ce62ea2193d461f701a70df1 (diff)
downloadstasis-6e72330a3cc8d571b14f2234ed8fc2778b5e9b86.tar.gz
Merge pull request #50 from jhunkeler/conda-get-active-environment
Add conda_get_active_environment() function
Diffstat (limited to 'src')
-rw-r--r--src/conda.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/conda.c b/src/conda.c
index 37a7793..43b9001 100644
--- a/src/conda.c
+++ b/src/conda.c
@@ -437,6 +437,39 @@ int conda_env_export(char *name, char *output_dir, char *output_filename) {
return conda_exec(env_command);
}
+char *conda_get_active_environment() {
+ const char *name = getenv("CONDA_DEFAULT_ENV");
+ if (!name) {
+ return NULL;
+ }
+
+ char *result = NULL;
+ result = strdup(name);
+ if (!result) {
+ return NULL;
+ }
+
+ return result;
+}
+
+int conda_provides(const char *spec) {
+ struct Process proc;
+ memset(&proc, 0, sizeof(proc));
+ strcpy(proc.f_stdout, "/dev/null");
+ strcpy(proc.f_stderr, "/dev/null");
+
+ // It's worth noting the departure from using conda_exec() here:
+ // conda_exec() expects the program output to be visible to the user.
+ // For this operation we only need the exit value.
+ char cmd[PATH_MAX] = {0};
+ snprintf(cmd, sizeof(cmd) - 1, "mamba search --use-index-cache %s", spec);
+ if (shell(&proc, cmd) < 0) {
+ fprintf(stderr, "shell: %s", strerror(errno));
+ return -1;
+ }
+ return proc.returncode == 0;
+}
+
int conda_index(const char *path) {
char command[PATH_MAX];
sprintf(command, "index %s", path);