aloof-angle-91616
11/10/2019, 4:33 AM--query
today in https://github.com/pantsbuild/pants/pull/7356 and i'm about to drop it into our internal CI to see if we can shave a cool 7-10 minutes off of every CI run in the monorepo. there's absolutely cleanup to do, so i'm not looking for review quite yet, but one thing i'd like to note is adding a new query operator (e.g. to filter by target alias, to filter by tag, to filter by regex) can be done ludicrously quickly now, see https://github.com/pantsbuild/pants/blob/ef9cea0e17f842ea6bc83675be4d0519a3b600de/src/python/pants/engine/query.py#L175-L225 in particular. once i got it working again, adding these filters took literally 5 minutes, because all that's needed here is to create a class and register it with a UnionRule(QueryParser, ...)
to add new query operations, e.g.: @dataclass(frozen=True)
class TypeFilter(QueryParser):
allowed_type_aliases: Tuple[str, ...]
function_name = 'type-filter'
@classmethod
def parse_from_args(cls, *allowed_type_aliases):
return cls(allowed_type_aliases=tuple(allowed_type_aliases))
def quick_operator(self):
return FilterOperator(
lambda t: t.type_alias in self.allowed_type_aliases
)
...
def rules():
return [
...,
UnionRule(QueryParser, TypeFilter),
]