diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2025-04-02 14:49:33 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2025-04-02 14:49:33 -0400 |
commit | 27bd4bf8abd7e9a29ca89f67503fd9291757a97b (patch) | |
tree | f963b3776ee7f1b4dca399a41dbc2f1222c6c694 /src/lib | |
parent | e817b38090defab01e64bc3516ea474215bfcb09 (diff) | |
download | stasis-27bd4bf8abd7e9a29ca89f67503fd9291757a97b.tar.gz |
base and "based_on" installations shall hardcode the requested python version in the YAML config instead of trusting it
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/core/conda.c | 29 | ||||
-rw-r--r-- | src/lib/core/include/conda.h | 2 |
2 files changed, 27 insertions, 4 deletions
diff --git a/src/lib/core/conda.c b/src/lib/core/conda.c index 9b5c77c..c81e6cc 100644 --- a/src/lib/core/conda.c +++ b/src/lib/core/conda.c @@ -498,10 +498,11 @@ int conda_setup_headless() { return 0; } -int conda_env_create_from_uri(char *name, char *uri) { +int conda_env_create_from_uri(char *name, char *uri, char *python_version) { char env_command[PATH_MAX]; char *uri_fs = NULL; + // Convert a bare system path to a file:// path if (!strstr(uri, "://")) { uri_fs = calloc(strlen(uri) + strlen("file://") + 1, sizeof(*uri_fs)); @@ -510,9 +511,31 @@ int conda_env_create_from_uri(char *name, char *uri) { } snprintf(uri_fs, strlen(uri) + strlen("file://") + 1, "%s%s", "file://", uri); } - sprintf(env_command, "env create -n '%s' --file='%s'", name, uri_fs ? uri_fs : uri); + + char tempfile[PATH_MAX] = {0}; + sprintf(tempfile, "%s/remote_XXXXXX", globals.tmpdir); + + // Touch a temporary file + int fd = mkstemp(tempfile); + close(fd); + unlink(tempfile); + + // We'll create a new file with the same random bits, ending with .yml + strcat(tempfile, ".yml"); + char *errmsg = NULL; + download(uri_fs ? uri_fs : uri, tempfile, &errmsg); guard_free(uri_fs); - return conda_exec(env_command); + + // Rewrite python version + char spec[255] = {0}; + snprintf(spec, sizeof(spec) - 1, "- python=%s\n", python_version); + file_replace_text(tempfile, "- python\n", spec, 0); + + sprintf(env_command, "env create -n '%s' --file='%s'", name, tempfile); + int status = conda_exec(env_command); + unlink(tempfile); + + return status; } int conda_env_create(char *name, char *python_version, char *packages) { diff --git a/src/lib/core/include/conda.h b/src/lib/core/include/conda.h index 8b4a0bd..ea8613f 100644 --- a/src/lib/core/include/conda.h +++ b/src/lib/core/include/conda.h @@ -127,7 +127,7 @@ int conda_setup_headless(); * @param uri ftp://myserver.tld/environment.yml * @return exit code from "conda" */ -int conda_env_create_from_uri(char *name, char *uri); +int conda_env_create_from_uri(char *name, char *uri, char *python_version); /** * Create a Conda environment using generic package specs |