repo.py: cleanup packages_with_tags (#42980)

This commit is contained in:
Harmen Stoppels 2024-03-04 20:50:04 +01:00 committed by GitHub
parent 5b9e207db2
commit 3b06347f65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 19 additions and 26 deletions

View File

@ -18,6 +18,7 @@
import spack.cray_manifest as cray_manifest import spack.cray_manifest as cray_manifest
import spack.detection import spack.detection
import spack.error import spack.error
import spack.repo
import spack.util.environment import spack.util.environment
from spack.cmd.common import arguments from spack.cmd.common import arguments
@ -152,9 +153,9 @@ def external_find(args):
def packages_to_search_for( def packages_to_search_for(
*, names: Optional[List[str]], tags: List[str], exclude: Optional[List[str]] *, names: Optional[List[str]], tags: List[str], exclude: Optional[List[str]]
): ):
result = [] result = list(
for current_tag in tags: {pkg for tag in tags for pkg in spack.repo.PATH.packages_with_tags(tag, full=True)}
result.extend(spack.repo.PATH.packages_with_tags(current_tag, full=True)) )
if names: if names:
# Match both fully qualified and unqualified # Match both fully qualified and unqualified

View File

@ -228,7 +228,7 @@ def create_reporter(args, specs_to_test, test_suite):
def test_list(args): def test_list(args):
"""list installed packages with available tests""" """list installed packages with available tests"""
tagged = set(spack.repo.PATH.packages_with_tags(*args.tag)) if args.tag else set() tagged = spack.repo.PATH.packages_with_tags(*args.tag) if args.tag else set()
def has_test_and_tags(pkg_class): def has_test_and_tags(pkg_class):
tests = spack.install_test.test_functions(pkg_class) tests = spack.install_test.test_functions(pkg_class)

View File

@ -25,7 +25,7 @@
import traceback import traceback
import types import types
import uuid import uuid
from typing import Any, Dict, List, Tuple, Union from typing import Any, Dict, List, Set, Tuple, Union
import llnl.path import llnl.path
import llnl.util.filesystem as fs import llnl.util.filesystem as fs
@ -746,19 +746,17 @@ def all_package_paths(self):
for name in self.all_package_names(): for name in self.all_package_names():
yield self.package_path(name) yield self.package_path(name)
def packages_with_tags(self, *tags, full=False): def packages_with_tags(self, *tags: str, full: bool = False) -> Set[str]:
"""Returns a list of packages matching any of the tags in input. """Returns a set of packages matching any of the tags in input.
Args: Args:
full: if True the package names in the output are fully-qualified full: if True the package names in the output are fully-qualified
""" """
r = set() return {
for repo in self.repos: f"{repo.namespace}.{pkg}" if full else pkg
current = repo.packages_with_tags(*tags) for repo in self.repos
if full: for pkg in repo.packages_with_tags(*tags)
current = [f"{repo.namespace}.{x}" for x in current] }
r |= set(current)
return sorted(r)
def all_package_classes(self): def all_package_classes(self):
for name in self.all_package_names(): for name in self.all_package_names():
@ -1169,15 +1167,10 @@ def all_package_paths(self):
for name in self.all_package_names(): for name in self.all_package_names():
yield self.package_path(name) yield self.package_path(name)
def packages_with_tags(self, *tags): def packages_with_tags(self, *tags: str) -> Set[str]:
v = set(self.all_package_names()) v = set(self.all_package_names())
index = self.tag_index v.intersection_update(*(self.tag_index[tag.lower()] for tag in tags))
return v
for t in tags:
t = t.lower()
v &= set(index[t])
return sorted(v)
def all_package_classes(self): def all_package_classes(self):
"""Iterator over all package *classes* in the repository. """Iterator over all package *classes* in the repository.

View File

@ -2287,8 +2287,7 @@ def setup(
self.possible_virtuals = node_counter.possible_virtuals() self.possible_virtuals = node_counter.possible_virtuals()
self.pkgs = node_counter.possible_dependencies() self.pkgs = node_counter.possible_dependencies()
runtimes = spack.repo.PATH.packages_with_tags("runtime") self.pkgs.update(spack.repo.PATH.packages_with_tags("runtime"))
self.pkgs.update(set(runtimes))
# Fail if we already know an unreachable node is requested # Fail if we already know an unreachable node is requested
for spec in specs: for spec in specs:

View File

@ -117,7 +117,7 @@ def _compute_cache_values(self):
self._possible_dependencies = set(self._link_run) | set(self._total_build) self._possible_dependencies = set(self._link_run) | set(self._total_build)
def possible_packages_facts(self, gen, fn): def possible_packages_facts(self, gen, fn):
build_tools = set(spack.repo.PATH.packages_with_tags("build-tools")) build_tools = spack.repo.PATH.packages_with_tags("build-tools")
gen.h2("Packages with at most a single node") gen.h2("Packages with at most a single node")
for package_name in sorted(self.possible_dependencies() - build_tools): for package_name in sorted(self.possible_dependencies() - build_tools):
gen.fact(fn.max_dupes(package_name, 1)) gen.fact(fn.max_dupes(package_name, 1))
@ -142,7 +142,7 @@ def possible_packages_facts(self, gen, fn):
class FullDuplicatesCounter(MinimalDuplicatesCounter): class FullDuplicatesCounter(MinimalDuplicatesCounter):
def possible_packages_facts(self, gen, fn): def possible_packages_facts(self, gen, fn):
build_tools = set(spack.repo.PATH.packages_with_tags("build-tools")) build_tools = spack.repo.PATH.packages_with_tags("build-tools")
counter = collections.Counter( counter = collections.Counter(
list(self._link_run) + list(self._total_build) + list(self._direct_build) list(self._link_run) + list(self._total_build) + list(self._direct_build)
) )