diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-10-07 12:53:35 -0400 | 
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-10-07 12:53:49 -0400 | 
| commit | 2348de4365967a7cf18400213a5a84e4da7f0491 (patch) | |
| tree | 18d508b247244fb8b3b73952bd6adca755c06bb9 | |
| parent | 4d525473d1f2b4d02e29747a45d2a02ffcff4398 (diff) | |
| download | stasis-2348de4365967a7cf18400213a5a84e4da7f0491.tar.gz | |
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
| -rw-r--r-- | include/conda.h | 2 | ||||
| -rw-r--r-- | src/conda.c | 33 | 
2 files changed, 12 insertions, 23 deletions
| diff --git a/include/conda.h b/include/conda.h index b5ea926..565b7c9 100644 --- a/include/conda.h +++ b/include/conda.h @@ -190,7 +190,7 @@ int conda_index(const char *path);   * @param version package version (may be NULL)   * @return not found = 0, found = 1, error = -1   */ -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 *conda_get_active_environment(); 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 | 
