does anyone have an example `FixTargetsRequest` th...
# plugins
f
does anyone have an example
FixTargetsRequest
that operates on a target instead of per-file? I was able to make
LintTargetsRequest
work per target fairly easily, but Fix is setting
by_file=True
for some reason. I need all the source files in the target for my particular lint/fix rule https://github.com/pantsbuild/pants/blob/e44697e5dc57e80c91ba7396f46fe044ea40ba40/src/python/pants/core/goals/fix.py#L173
c
perhaps @bitter-ability-32190 has some recollections for this?
b
I don't quite remember 🫤
c
it was a long shot 😝
f
I was able to get this working using a custom partition rule. Take the field sets and return a partition per field set, along with the field set so I have access to it in the fix rule. Definitely more awkward than the LintTargetsRequest though, which doesn’t require the custom partitioner for the equivalent thing
Copy code
class MyFixRequest(FixTargetsRequest):
    field_set_type = MyLintFieldSet
    tool_subsystem = MySubsystem
    partitioner_type = PartitionerType.CUSTOM

@rule
async def fix_partition_inputs(
    request: MyFixRequest.PartitionRequest,
    subsystem: MySubsystem,
) -> Partitions[str, PartitionMetadata]:
    if subsystem.skip:
        return Partitions()

    all_sources_paths = await MultiGet(
        Get(SourcesPaths, SourcesPathsRequest(getattr(field_set, "sources")))
        for field_set in request.field_sets
    )

    # zip up the field sets with the sources paths. field set is the metadata
    partitions = Partitions(
        Partition(sources_paths.files, field_set)
        for field_set, sources_paths in zip(request.field_sets, all_sources_paths)
    )
    return partitions
We recently realized this was causing our fix rule to be invoked multiple times when the target had more than
batch_size
files, which isn't ideal. Opened an issue for it here https://github.com/pantsbuild/pants/issues/21935