Reduce verbosity of patches=... variant (#29015)

* reduce verbosity of patches=... variant

* Special-case prefix-matches for satisfies of patches variant
This commit is contained in:
Harmen Stoppels 2022-02-17 11:06:32 +01:00 committed by GitHub
parent fa132614e0
commit d93f9b82ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -403,15 +403,32 @@ def satisfies(self, other):
""" """
super_sat = super(MultiValuedVariant, self).satisfies(other) super_sat = super(MultiValuedVariant, self).satisfies(other)
if not super_sat:
return False
if '*' in other or '*' in self:
return True
# allow prefix find on patches
if self.name == 'patches':
return all(any(w.startswith(v) for w in self.value) for v in other.value)
# Otherwise we want all the values in `other` to be also in `self` # Otherwise we want all the values in `other` to be also in `self`
return super_sat and (all(v in self.value for v in other.value) or return all(v in self.value for v in other.value)
'*' in other or '*' in self)
def append(self, value): def append(self, value):
"""Add another value to this multi-valued variant.""" """Add another value to this multi-valued variant."""
self._value = tuple(sorted((value,) + self._value)) self._value = tuple(sorted((value,) + self._value))
self._original_value = ",".join(self._value) self._original_value = ",".join(self._value)
def __str__(self):
# Special-case patches to not print the full 64 character hashes
if self.name == 'patches':
values_str = ','.join(x[:7] for x in self.value)
else:
values_str = ','.join(str(x) for x in self.value)
return '{0}={1}'.format(self.name, values_str)
class SingleValuedVariant(AbstractVariant): class SingleValuedVariant(AbstractVariant):
"""A variant that can hold multiple values, but one at a time.""" """A variant that can hold multiple values, but one at a time."""