From 9214f0f423232e5bce21f87137638635a0e5e6ff Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Wed, 30 Oct 2024 12:00:00 +0000 Subject: [PATCH] Fix -s to not add deprecated versions to the specs to build --- cli/check.py | 79 ++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/cli/check.py b/cli/check.py index 430405e..be6526c 100755 --- a/cli/check.py +++ b/cli/check.py @@ -536,30 +536,6 @@ def setup_github_cli_fzf_aliases() -> ExitCode: return Success -def get_safe_versions(spec): - """Find the safe versions of the specs. Parse the output of `bin/spack versions --safe`: - bin/spack versions --safe wget - ==> Safe versions (already checksummed): - master 2.4.1 2.3 2.2 2.1 2.0 1.3 - """ - safe_versions = [] - # FIXME: The spec may contain variants, etc, use a regex to remove them. - recipe = spec.split("+")[0] # Remove variants, and more as they are added to the spec. - err, stdout, _ = run(["bin/spack", "versions", "--safe", recipe]) - if err == 0: - for line in stdout.split("\n"): - if line.startswith("==> Safe versions"): - continue - safe_versions.extend(line.split()) - - # Remove the versions that should be skipped (development branches often fail to build): - for skip_version in ["master", "develop", "main"]: - if skip_version in safe_versions: - safe_versions.remove(skip_version) - - return safe_versions - - def find_already_installed(specs_to_check: List[str]) -> Tuple[List[str], List[str]]: """List the installed packages.""" installed = [] @@ -870,17 +846,46 @@ def recipes_of_specs(specs: Strs) -> Strs: return list(set(recipes)) -def expand_specs_to_check_package_versions(specs_to_check, max_versions) -> List[str]: +def get_preferred_version(output: str) -> str: + """Extract the preferred version of the package""" + + preferred_group = re.search(r"Preferred version:\s+(\S+)", output) + return preferred_group.group(1) if preferred_group else "" + + +def get_safe_versions(output: str) -> List[str]: + """Find the not deprecated safe versions of the specs.""" + + safe_versions = [] + version_match = re.search(r"Safe versions:\n(.*)\n\n", output + "\n\n", re.DOTALL) + if version_match: + for version_line in version_match.group(1).split("\n\n")[0].split("\n"): + safe_versions.append(version_line.split()[0]) + + # Remove the versions that should be skipped (development branches often fail to build): + for skip_version in ["master", "develop", "main"]: + if skip_version in safe_versions: + safe_versions.remove(skip_version) + + return safe_versions + + +def expand_specs_to_check_package_versions(specs, max_versions) -> None: """Expand the specs to check by adding the safe versions of the packages.""" - for recipe in recipes_of_specs(specs_to_check): - versions = get_safe_versions(recipe) - if not versions: - continue - if recipe in specs_to_check: - specs_to_check.remove(recipe) - specs_to_check.extend([recipe + "@" + version for version in versions[:max_versions]]) + for recipe in recipes_of_specs(specs): + exitcode, stdout, stderr = run(["bin/spack", "info", recipe]) # Get the info of the recipe + if exitcode: + raise ChildProcessError(f"spack info {recipe} failed: {stderr or stdout}") + versions = get_safe_versions(stdout) + if versions: + specs.extend([recipe + "@" + version for version in versions[:max_versions]]) + # Always add the preferred version to the list of specs to check: + versions.append(get_preferred_version(stdout)) - return specs_to_check + # Remove duplicates from the list of specs to check and update the list: + new_specs = list(set(specs)) + specs.clear() + specs.extend(new_specs) def check_all_downloads(specs) -> ExitCode: @@ -1343,12 +1348,8 @@ def check_and_build(args: argparse.Namespace) -> ExitCode: print("Specs to check:", " ".join(specs_to_check)) - # Check if the specs have versions and add the versions to the specs to check. - - if args.safe_versions: - print("Checking for existing safe versions of the packages to build or download") - # Limit the number of versions to check to 6. - specs_to_check = expand_specs_to_check_package_versions(specs_to_check, args.safe_versions) + # Always check the preferred version of the package as well: + expand_specs_to_check_package_versions(specs_to_check, args.safe_versions) specs_to_check = add_compiler_to_specs(specs_to_check, args)