Spec.__contains__: traverse only lin/run + direct build

This commit is contained in:
Massimiliano Culpo 2024-11-12 09:20:15 +01:00
parent 3408f7ec56
commit 7ee73ed1b6
No known key found for this signature in database
GPG Key ID: 3E52BB992233066C
2 changed files with 3 additions and 9 deletions

View File

@ -225,7 +225,7 @@ def provides(self):
# All the other tokens in the hierarchy must be virtual dependencies # All the other tokens in the hierarchy must be virtual dependencies
for x in self.hierarchy_tokens: for x in self.hierarchy_tokens:
if self.spec.package.provides(x): if self.spec.package.provides(x):
provides[x] = self.spec[x] provides[x] = self.spec
return provides return provides
@property @property

View File

@ -3677,16 +3677,10 @@ def __getitem__(self, name: str):
self.edges_to_dependencies(depflag=dt.BUILD | dt.TEST), self.edges_to_dependencies(depflag=dt.BUILD | dt.TEST),
) )
# Consider runtime dependencies and direct build/test deps before transitive dependencies, # Consider runtime dependencies and direct build/test deps only
# and prefer matches closest to the root.
try: try:
child: Spec = next( child: Spec = next(
e.spec e.spec for e in order() if e.spec.name == name or name in e.virtuals
for e in itertools.chain(
(e for e in order() if e.spec.name == name or name in e.virtuals),
# for historical reasons
(e for e in order() if e.spec.concrete and e.spec.package.provides(name)),
)
) )
except StopIteration: except StopIteration:
raise KeyError(f"No spec with name {name} in {self}") raise KeyError(f"No spec with name {name} in {self}")