How do I request the output of a rule with a subsy...
# development
b
How do I request the output of a rule with a subsystem input via
rule_runner
?
1
Trying to provide it as an input gives me an error about it being unhashable. Without it I'm seeing an error about no
QueryRule
f
SubsystemRule
in the list of
RuleRunner
rules should fix that
do you have a code sample?
b
Copy code
def test_default_single_partition_partitioner() -> None:
    class KitchenSubsystem(Subsystem):
        options_scope = "kitchen"
        help = "a cookbook might help"
        name = "The Kitchen"
        skip = SkipOption("lint")

    class LintKitchenRequest(LintTargetsRequest):
        field_set_type = MockLinterFieldSet
        tool_subsystem = KitchenSubsystem

    rules = list(
        LintKitchenRequest._get_registration_rules(
            partitioner_type=PartitionerType.DEFAULT_SINGLE_PARTITION
        )
    )
    rule_runner = RuleRunner(rules=rules)
    field_sets = (
        MockLinterFieldSet(Address("knife"), MultipleSourcesField(["knife"], Address("knife"))),
        MockLinterFieldSet(Address("bowl"), MultipleSourcesField(["bowl"], Address("bowl"))),
    )
    partitions = rule_runner.request(
        Partitions,
        [
            LintKitchenRequest.PartitionRequest(field_sets),
        ],
    )
Theres a task rule in there which ouputs the subsystem...
Copy code
TaskRule(_output_type=<class 'pants.core.goals.lint_test.test_default_single_partition_partitioner.<locals>.KitchenSubsystem'>, input_selectors=(), input_gets=(Get(ScopedOptions, Scope, ..),), func=functools.partial(<function _construct_subsytem at 0x7f55c29011f0>, <class 'pants.core.goals.lint_test.test_default_single_partition_partitioner.<locals>.KitchenSubsystem'>), cacheable=True, canonical_name='construct_scope_kitchen', desc=None, level=<LogLevel.TRACE: 'trace'>)
Adding
QueryRule(Partitions, [LintKitchenRequest.PartitionRequest]),
works
f
yup any call to
rule_runner.request
has to have a matching
QueryRule