diff options
| author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2024-07-30 17:58:35 -0400 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-30 17:58:35 -0400 | 
| commit | 15eef8db2c06f536edee84fe524f5d8fcefd0a5f (patch) | |
| tree | 649b949c7fb4de793da311302990b25626ff7140 | |
| parent | b506bb73be5e4c8dde16c5c8bd613c00b3d75565 (diff) | |
| download | stasis-15eef8db2c06f536edee84fe524f5d8fcefd0a5f.tar.gz | |
Version in package name (#15)
* Compile test installation with debug symbols enabled
* Fix typo in environment variable name
* STASIS_GITHUB_TOKEN is supposed to be STASIS_GH_TOKEN
* Add pattern matching mode selector to get_wheel_file()
* Adds modes WHEEL_MATCH_EXACT and WHEEL_MATCH_ANY
* test block version key is now optional
* Now that *_packages lists define the package version through detection, because the end-result version cannot be guaranteed to be identical to the tag.
* Find the just-compiled package matching the name and version in the package list.
* If compiling master/main this can also match against post-commits (x.y.z.devN+hash)
* Versions are extracted from the package name in the list, only if a matching test block exists. Otherwise the string is passed through to pip directly.
* Changes indentation level of output
* Do not replace @PIP_ARGUMENTS@ with an artifactory URL unless artifactory is enabled
* Sequence change
* Build requested packages before executing tests. A necessary evil if test blocks are no longer responsible for setting the version data
* Show the delivery summary just before test execution, instead of at the start of the program
* Terminate package name at version operator when a package is filtered for testing
| -rw-r--r-- | include/wheel.h | 5 | ||||
| -rw-r--r-- | src/delivery.c | 59 | ||||
| -rw-r--r-- | src/stasis_main.c | 28 | ||||
| -rw-r--r-- | src/template_func_proto.c | 2 | ||||
| -rw-r--r-- | src/wheel.c | 8 | ||||
| -rw-r--r-- | tests/rt_generic.sh | 2 | 
6 files changed, 79 insertions, 25 deletions
| diff --git a/include/wheel.h b/include/wheel.h index 94cf46a..619e0f7 100644 --- a/include/wheel.h +++ b/include/wheel.h @@ -6,6 +6,9 @@  #include <stdio.h>  #include "str.h" +#define WHEEL_MATCH_EXACT 0 +#define WHEEL_MATCH_ANY 1 +  struct Wheel {      char *distribution;      char *version; @@ -17,5 +20,5 @@ struct Wheel {      char *file_name;  }; -struct Wheel *get_wheel_file(const char *basepath, const char *name, char *to_match[]); +struct Wheel *get_wheel_file(const char *basepath, const char *name, char *to_match[], unsigned match_mode);  #endif //STASIS_WHEEL_H diff --git a/src/delivery.c b/src/delivery.c index 8e37bc0..f9907fc 100644 --- a/src/delivery.c +++ b/src/delivery.c @@ -452,7 +452,7 @@ void validate_delivery_ini(struct INIFILE *ini) {              if (name && strlen(name) > 1) {                  name = &name[1];              } -            ini_has_key_required(ini, section->key, "version"); +            //ini_has_key_required(ini, section->key, "version");              ini_has_key_required(ini, section->key, "repository");              ini_has_key_required(ini, section->key, "script");          } @@ -606,7 +606,7 @@ static int populate_delivery_ini(struct Delivery *ctx) {              }              conv_str(&ctx->tests[z].name, val); -            ini_getval_required(ini, ini->section[i]->key, "version", INIVAL_TYPE_STR, &val); +            ini_getval(ini, ini->section[i]->key, "version", INIVAL_TYPE_STR, &val);              conv_str(&ctx->tests[z].version, val);              ini_getval_required(ini, ini->section[i]->key, "repository", INIVAL_TYPE_STR, &val); @@ -1237,9 +1237,39 @@ int delivery_install_packages(struct Delivery *ctx, char *conda_install_dir, cha                  continue;              }              if (INSTALL_PKG_PIP_DEFERRED & type) { -                const struct Test *info = requirement_from_test(ctx, name); +                struct Test *info = (struct Test *) requirement_from_test(ctx, name);                  if (info) { -                    sprintf(cmd + strlen(cmd), " '%s==%s'", info->name, info->version); +                    if (!strcmp(info->version, "HEAD")) { +                        struct StrList *tag_data = strlist_init(); +                        if (!tag_data) { +                            SYSERROR("%s", "Unable to allocate memory for tag data\n"); +                            return -1; +                        } +                        strlist_append_tokenize(tag_data, info->repository_info_tag, "-"); + +                        struct Wheel *whl = NULL; +                        char *post_commit = NULL; +                        char *hash = NULL; +                        if (strlist_count(tag_data) > 1) { +                            post_commit = strlist_item(tag_data, 1); +                            hash = strlist_item(tag_data, 2); +                        } + +                        // We can't match on version here (index 0). The wheel's version is not guaranteed to be +                        // equal to the tag; setuptools_scm auto-increments the value, the user can change it manually, +                        // etc. +                        whl = get_wheel_file(ctx->storage.wheel_artifact_dir, info->name, +                                             (char *[]) {ctx->meta.python_compact, ctx->system.arch, +                                                         "none", "any", +                                                         post_commit, hash, +                                                         NULL}, WHEEL_MATCH_ANY); + +                        guard_strlist_free(&tag_data); +                        info->version = whl->version; +                        sprintf(cmd + strlen(cmd), " '%s==%s'", info->name, whl->version); +                    } else { +                        sprintf(cmd + strlen(cmd), " '%s==%s'", info->name, info->version); +                    }                  } else {                      fprintf(stderr, "Deferred package '%s' is not present in the tested package list!\n", name);                      return -1; @@ -1507,10 +1537,27 @@ void delivery_defer_packages(struct Delivery *ctx, int type) {          // Compile a list of packages that are *also* to be tested.          char *version; +        char *spec_begin = strpbrk(name, "~=<>!"); +        char *spec_end = spec_begin; +        if (spec_end) { +            // A version is present in the package name. Jump past operator(s). +            while (*spec_end != '\0' && !isalnum(*spec_end)) { +                spec_end++; +            } +        } + +        // When spec is present in name, set ctx->tests[x].version to the version detected in the name          for (size_t x = 0; x < sizeof(ctx->tests) / sizeof(ctx->tests[0]); x++) {              version = NULL;              if (ctx->tests[x].name) {                  if (strstr(name, ctx->tests[x].name)) { +                    guard_free(ctx->tests[x].version); +                    if (spec_begin && spec_end) { +                        *spec_begin = '\0'; +                        ctx->tests[x].version = strdup(spec_end); +                    } else { +                        ctx->tests[x].version = strdup("HEAD"); +                    }                      version = ctx->tests[x].version;                      ignore_pkg = 1;                      break; @@ -1690,7 +1737,7 @@ void delivery_rewrite_spec(struct Delivery *ctx, char *filename, unsigned stage)          if (ctx->storage.wheel_staging_url) {              file_replace_text(filename, "@PIP_ARGUMENTS@", ctx->storage.wheel_staging_url, 0); -        } else if (globals.jfrog.url && globals.jfrog.repo) { +        } else if (globals.enable_artifactory && globals.jfrog.url && globals.jfrog.repo) {              sprintf(output, "--extra-index-url %s/%s/%s/%s/packages/wheels", globals.jfrog.url, globals.jfrog.repo, ctx->meta.mission, ctx->info.build_name);              file_replace_text(filename, "@PIP_ARGUMENTS@", output, 0);          } else { @@ -2180,7 +2227,7 @@ int delivery_fixup_test_results(struct Delivery *ctx) {          }          sprintf(path, "%s/%s", ctx->storage.results_dir, rec->d_name); -        msg(STASIS_MSG_L2, "%s\n", rec->d_name); +        msg(STASIS_MSG_L3, "%s\n", rec->d_name);          if (xml_pretty_print_in_place(path, STASIS_XML_PRETTY_PRINT_PROG, STASIS_XML_PRETTY_PRINT_ARGS)) {              msg(STASIS_MSG_L3 | STASIS_MSG_WARN, "Failed to rewrite file '%s'\n", rec->d_name);          } diff --git a/src/stasis_main.c b/src/stasis_main.c index 686c044..b6ffc1d 100644 --- a/src/stasis_main.c +++ b/src/stasis_main.c @@ -407,14 +407,6 @@ int main(int argc, char *argv[]) {      strcpy(env_name_testing, env_name);      strcat(env_name_testing, "-test"); -    msg(STASIS_MSG_L1, "Overview\n"); -    delivery_meta_show(&ctx); -    delivery_conda_show(&ctx); -    delivery_tests_show(&ctx); -    if (globals.verbose) { -        //delivery_runtime_show(&ctx); -    } -      // Safety gate: Avoid clobbering a delivered release unless the user wants that behavior      msg(STASIS_MSG_L1, "Checking release history\n");      if (delivery_exists(&ctx)) { @@ -509,21 +501,29 @@ int main(int argc, char *argv[]) {          exit(1);      } +    msg(STASIS_MSG_L1, "Filter deliverable packages\n"); +    delivery_defer_packages(&ctx, DEFER_CONDA); +    delivery_defer_packages(&ctx, DEFER_PIP); + +    msg(STASIS_MSG_L1, "Overview\n"); +    delivery_meta_show(&ctx); +    delivery_conda_show(&ctx); +    if (globals.verbose) { +        //delivery_runtime_show(&ctx); +    } +      // Execute configuration-defined tests      if (globals.enable_testing) { +        delivery_tests_show(&ctx); +          msg(STASIS_MSG_L1, "Begin test execution\n");          delivery_tests_run(&ctx); -        msg(STASIS_MSG_L1, "Rewriting test results\n"); +        msg(STASIS_MSG_L2, "Rewriting test results\n");          delivery_fixup_test_results(&ctx);      } else {          msg(STASIS_MSG_L1 | STASIS_MSG_WARN, "Test execution is disabled\n");      } -    msg(STASIS_MSG_L1, "Generating deferred package listing\n"); -    // Test succeeded so move on to producing package artifacts -    delivery_defer_packages(&ctx, DEFER_CONDA); -    delivery_defer_packages(&ctx, DEFER_PIP); -      if (ctx.conda.conda_packages_defer && strlist_count(ctx.conda.conda_packages_defer)) {          msg(STASIS_MSG_L2, "Building Conda recipe(s)\n");          if (delivery_build_recipes(&ctx)) { diff --git a/src/template_func_proto.c b/src/template_func_proto.c index 140a5e0..f29c103 100644 --- a/src/template_func_proto.c +++ b/src/template_func_proto.c @@ -20,7 +20,7 @@ int get_github_release_notes_auto_tplfunc_entrypoint(void *frame, void *data_out      int result = 0;      char **output = (char **) data_out;      struct tplfunc_frame *f = (struct tplfunc_frame *) frame; -    char *api_token = getenv("STASIS_GITHUB_TOKEN"); +    char *api_token = getenv("STASIS_GH_TOKEN");      if (!api_token) {          api_token = getenv("GITHUB_TOKEN");      } diff --git a/src/wheel.c b/src/wheel.c index 8f48828..b96df57 100644 --- a/src/wheel.c +++ b/src/wheel.c @@ -1,6 +1,6 @@  #include "wheel.h" -struct Wheel *get_wheel_file(const char *basepath, const char *name, char *to_match[]) { +struct Wheel *get_wheel_file(const char *basepath, const char *name, char *to_match[], unsigned match_mode) {      DIR *dp;      struct dirent *rec;      struct Wheel *result = NULL; @@ -38,7 +38,11 @@ struct Wheel *get_wheel_file(const char *basepath, const char *name, char *to_ma              }          } -        if (!startswith(rec->d_name, name) || match != pattern_count) { +        if (!startswith(rec->d_name, name)) { +            continue; +        } + +        if (match_mode == WHEEL_MATCH_EXACT && match != pattern_count) {              continue;          } diff --git a/tests/rt_generic.sh b/tests/rt_generic.sh index 200f66f..600e501 100644 --- a/tests/rt_generic.sh +++ b/tests/rt_generic.sh @@ -20,7 +20,7 @@ bdir="$ws"/build  mkdir -p "$bdir"  pushd "$bdir" -cmake -DCMAKE_INSTALL_PREFIX="$prefix" "${topdir}"/../.. +cmake -DCMAKE_INSTALL_PREFIX="$prefix" -DCMAKE_BUILD_TYPE=Debug "${topdir}"/../..  make install  export PATH="$prefix/bin:$PATH"  popd | 
