From 868d5389585c41ff7ebe4ec18ba8b4a8489d2352 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 25 Apr 2025 11:48:36 +0200 Subject: [PATCH] simplify and speed up external list --- lib/spack/spack/cmd/external.py | 14 ++++++++------ lib/spack/spack/package_base.py | 8 -------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/spack/spack/cmd/external.py b/lib/spack/spack/cmd/external.py index 7650306bd19..510233b1460 100644 --- a/lib/spack/spack/cmd/external.py +++ b/lib/spack/spack/cmd/external.py @@ -5,7 +5,7 @@ import errno import os import re -import sys +from collections import defaultdict from typing import List, Optional, Set import llnl.util.tty as tty @@ -17,7 +17,6 @@ import spack.cray_manifest as cray_manifest import spack.detection import spack.error -import spack.package_base import spack.repo import spack.spec from spack.cmd.common import arguments @@ -246,13 +245,16 @@ def _collect_and_consume_cray_manifest_files( def external_list(args): - # Trigger a read of all packages, might take a long time. - list(spack.repo.PATH.all_package_classes()) # Print all the detectable packages tty.msg("Detectable packages per repository") - for namespace, pkgs in sorted(spack.package_base.detectable_packages.items()): + repo_to_packages = defaultdict(list) + for fullname in spack.repo.PATH.packages_with_tags("detectable", full=True): + repo, _, pkg = fullname.rpartition(".") + repo_to_packages[repo].append(pkg) + + for namespace in sorted(repo_to_packages): print("Repository:", namespace) - colify.colify(pkgs, indent=4, output=sys.stdout) + colify.colify(repo_to_packages[namespace], indent=4) def external(parser, args): diff --git a/lib/spack/spack/package_base.py b/lib/spack/spack/package_base.py index cf2ca6c8de6..c33fe0baf0d 100644 --- a/lib/spack/spack/package_base.py +++ b/lib/spack/spack/package_base.py @@ -132,11 +132,6 @@ def windows_establish_runtime_linkage(self): win_rpath.establish_link() -#: Registers which are the detectable packages, by repo and package name -#: Need a pass of package repositories to be filled. -detectable_packages = collections.defaultdict(list) - - class DetectablePackageMeta(type): """Check if a package is detectable and add default implementations for the detection function. @@ -242,9 +237,6 @@ def determine_spec_details(cls, prefix, objs_in_prefix): def determine_variants(cls, objs, version_str): return "" - # Register the class as a detectable package - detectable_packages[cls.namespace].append(cls.name) - # Attach function implementations to the detectable class default = False if not hasattr(cls, "determine_spec_details"):