From 2348de4365967a7cf18400213a5a84e4da7f0491 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 7 Oct 2024 12:53:35 -0400 Subject: pip_index_provides does not need a separate version * To be more aligned with conda_provides, the version spec has been consolidated into one argument --- src/conda.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/conda.c b/src/conda.c index 43b9001..e60abc7 100644 --- a/src/conda.c +++ b/src/conda.c @@ -79,37 +79,26 @@ int pip_exec(const char *args) { return system(command); } -int pip_index_provides(const char *index_url, const char *name, const char *version) { +int pip_index_provides(const char *index_url, const char *spec) { char cmd[PATH_MAX] = {0}; - char name_local[255]; - char version_local[255] = {0}; - char spec[255] = {0}; + char spec_local[255] = {0}; - if (isempty((char *) name) < 0) { - // no package name means nothing to do. + if (isempty((char *) spec)) { + // NULL or zero-length; no package spec means there's nothing to do. return -1; } - // Fix up the package name - strncpy(name_local, name, sizeof(name_local) - 1); - tolower_s(name_local); - lstrip(name_local); - strip(name_local); - - if (version) { - // Fix up the package version - strncpy(version_local, version, sizeof(version_local) - 1); - tolower_s(version_local); - lstrip(version_local); - strip(version_local); - sprintf(spec, "==%s", version); - } + // Normalize the local spec string + strncpy(spec_local, spec, sizeof(spec_local) - 1); + tolower_s(spec_local); + lstrip(spec_local); + strip(spec_local); char logfile[] = "/tmp/STASIS-package_exists.XXXXXX"; int logfd = mkstemp(logfile); if (logfd < 0) { perror(logfile); - remove(logfile); // fail harmlessly if not present + remove(logfile); // fail harmlessly if not present return -1; } @@ -121,7 +110,7 @@ int pip_index_provides(const char *index_url, const char *name, const char *vers strcpy(proc.f_stdout, logfile); // Do an installation in dry-run mode to see if the package exists in the given index. - snprintf(cmd, sizeof(cmd) - 1, "python -m pip install --dry-run --no-deps --index-url=%s %s%s", index_url, name_local, spec); + snprintf(cmd, sizeof(cmd) - 1, "python -m pip install --dry-run --no-deps --index-url=%s %s", index_url, spec_local); status = shell(&proc, cmd); // Print errors only when shell() itself throws one -- cgit