def register_rules(rule_index: RuleIndex, union_membership: UnionMembership) -> PyTasks: """Create a native Tasks object loaded with given RuleIndex.""" tasks = PyTasks() def register_task(rule: TaskRule) -> None: native_engine.tasks_task_begin( tasks, rule.func, rule.output_type, side_effecting=any( issubclass(t, SideEffecting) for t in rule.input_selectors), engine_aware_return_type=issubclass(rule.output_type, EngineAwareReturnType), cacheable=rule.cacheable, name=rule.canonical_name, desc=rule.desc or "", level=rule.level.level, ) for selector in rule.input_selectors: native_engine.tasks_add_select(tasks, selector) for the_get in rule.input_gets: if is_union(the_get.input_type): # Register a union. TODO: See #12934: this should involve an explicit interface # soon, rather than one being implicitly created with only the provided Param. for union_member in union_membership.get(the_get.input_type): native_engine.tasks_add_union(tasks, the_get.output_type, (union_member, )) else: # Otherwise, the Get subject is a "concrete" type, so add a single Get edge. native_engine.tasks_add_get(tasks, the_get.output_type, the_get.input_type) native_engine.tasks_task_end(tasks) for task_rule in rule_index.rules: register_task(task_rule) for query in rule_index.queries: native_engine.tasks_add_query( tasks, query.output_type, query.input_types, ) return tasks
def register_rules(rule_index: RuleIndex, union_membership: UnionMembership) -> PyTasks: """Create a native Tasks object loaded with given RuleIndex.""" tasks = PyTasks() def register_task(rule: TaskRule) -> None: native_engine.tasks_task_begin( tasks, rule.func, rule.output_type, issubclass(rule.output_type, EngineAwareReturnType), rule.cacheable, rule.canonical_name, rule.desc or "", rule.level.level, ) for selector in rule.input_selectors: native_engine.tasks_add_select(tasks, selector) def add_get_edge(product: type, subject: type) -> None: native_engine.tasks_add_get(tasks, product, subject) for the_get in rule.input_gets: if union.is_instance(the_get.input_type): # If the registered subject type is a union, add Get edges to all registered # union members. for union_member in union_membership.get(the_get.input_type): add_get_edge(the_get.output_type, union_member) else: # Otherwise, the Get subject is a "concrete" type, so add a single Get edge. add_get_edge(the_get.output_type, the_get.input_type) native_engine.tasks_task_end(tasks) for task_rule in rule_index.rules: register_task(task_rule) for query in rule_index.queries: native_engine.tasks_add_query( tasks, query.output_type, query.input_types, ) return tasks