I want to add a goal called `check` that runs `lin...
# general
p
I want to add a goal called
check
that runs
lint
,
typecheck
, etc. I know with a macro you can create multiple targets but it doesn't look like macros let you combine goals. I can create a custom rule but (1) is that necessary and (2) if so, I think I need to do some
await Get(LintResult, Target, target)
like calls, once for each target, but I'm not sure what the right types to
await
are for the other goals -- how do I find those?
h
Hey Oliver, yeah this is indeed somewhere that you would write a custom goal. What specifically do you want it to run?
typecheck
and
lint
, or anything else too? You would basically copy and paste this: https://github.com/pantsbuild/pants/blob/860908b2828031f2cb0a03e05cc252df8d3aaf1a/src/python/pants/core/goals/typecheck.py#L134-L187 Except add in an equivalent block for
LintRequest
and
EnrichedLintResults
. Note that
lint.py
has a lot of extra things going on to support an option
--per-file-caching
and lint reports - you can ignore that code
h
Once you get this working it might be a cool example for us to add to the documentation!
🙌 1
h
Indeed! A couple folks have wanted goals that act like a pipeline like this. I think it'd be great to have a guide on how to chain together multiple goals
p
Thanks. Will let you know how it does.
FWIW, since this is common I'd vote to make it easier. Seems like you could have an
alias
method that could go in
BUILD
files or
pants.toml
to define these kinds of things.
h
Yes, that could probably be done.
Good starter project for a new contributor.
h
@plain-carpet-73994 once you get things working, here's an optimization to get linters and typecheckers to run in parallel. Naively, you'll have something like
Copy code
all_typecheck_results = await MultiGet(
        Get(EnrichedTypecheckResults, TypecheckRequest, request) for request in valid_typecheck_requests
    )
all_lint_results = await MultiGet(
        Get(EnrichedLintResults, LintRequest, request) for request in valid_lint_requests
    )
Those evaluate sequentially. Instead, you can create a dedicated rule like this:
Copy code
class AllLintResults(Collection[EnrichedLintResults]):
  pass

class AllLintRequests(Collection[LintRequest]):
  pass

@rule
def all_lint_results(requests: AllLintRequests) -> AllLintResults:
   return await MultiGet(
        Get(EnrichedLintResults, LintRequest, request) for request in requests
    )
Ditto for typecheck. Then, you can now do in your `@goal_rule`:
Copy code
all_lint_results, all_typecheck_results = await MultiGet(
  Get(AllLintResults, AllLintRequests(valid_lint_requests)),
Get(AllTypecheckResults, AllTypecheckRequests(valid_lint_requests)),
)
👍 1