aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-08-17 16:46:03 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-08-17 16:46:03 -0400
commit89f5eb7c4698c62d147122fdc3ea38c07eb01149 (patch)
tree1b63fc41b044e43bcb93fab2fbc9aeddca580437
parentfa22e7e9ee5b59caea2553fd747b9d46f94f3b5c (diff)
downloadstasis-minimum-viable-tools.tar.gz
Implement TODO itemminimum-viable-tools
* The array of packages now used to check the runtime environment instead of two separate scanning methods * Renamed tools array to: conda_minimum_viable_tools
-rw-r--r--src/conda.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/conda.c b/src/conda.c
index 7aaec77..6ed96c7 100644
--- a/src/conda.c
+++ b/src/conda.c
@@ -213,15 +213,29 @@ int conda_activate(const char *root, const char *env_name) {
int conda_check_required() {
int status = 0;
- char *tools[] = {
- "boa",
- "conda-build",
- "conda-verify",
- NULL
- };
struct StrList *result = NULL;
- // TODO: Generate the command based on tools array
- char *cmd_out = shell_output("conda list '^boa|^conda-build|^conda-verify' | cut -d ' ' -f 1", &status);
+ char cmd[PATH_MAX] = {0};
+ const char *conda_minimum_viable_tools[] = {
+ "boa",
+ "conda-build",
+ "conda-verify",
+ NULL
+ };
+
+ // Construct a "conda list" command that searches for all required packages
+ // using conda's (python's) regex matching
+ strcat(cmd, "conda list '");
+ for (size_t i = 0; conda_minimum_viable_tools[i] != NULL; i++) {
+ strcat(cmd, "^");
+ strcat(cmd, conda_minimum_viable_tools[i]);
+ if (conda_minimum_viable_tools[i + 1] != NULL) {
+ strcat(cmd, "|");
+ }
+ }
+ strcat(cmd, "' | cut -d ' ' -f 1");
+
+ // Verify all required packages are installed
+ char *cmd_out = shell_output(cmd, &status);
if (cmd_out) {
size_t found = 0;
result = strlist_init();
@@ -232,13 +246,13 @@ int conda_check_required() {
continue;
}
- for (size_t x = 0; tools[x] != NULL; x++) {
- if (!strcmp(item, tools[x])) {
+ for (size_t x = 0; conda_minimum_viable_tools[x] != NULL; x++) {
+ if (!strcmp(item, conda_minimum_viable_tools[x])) {
found++;
}
}
}
- if (found < (sizeof(tools) / sizeof(*tools)) - 1) {
+ if (found < (sizeof(conda_minimum_viable_tools) / sizeof(*conda_minimum_viable_tools)) - 1) {
guard_free(cmd_out);
guard_strlist_free(&result);
return 1;