diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2024-08-17 17:32:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-17 17:32:20 -0400 |
commit | 04ce859e53ef28bc917d4d3a12161e1cfbfa2859 (patch) | |
tree | 1b63fc41b044e43bcb93fab2fbc9aeddca580437 | |
parent | fa22e7e9ee5b59caea2553fd747b9d46f94f3b5c (diff) | |
download | stasis-04ce859e53ef28bc917d4d3a12161e1cfbfa2859.tar.gz |
Implement TODO item (#32)
* 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.c | 36 |
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; |