Skip to content

Commit

Permalink
Makes check a USES_ENVIRONMENTS goal (#17315)
Browse files Browse the repository at this point in the history
`check` will now run each `CheckRequest` in each specified environment per the `field_sets` in the `CheckRequest`. It looks like the remainder of the `check` infrastructure already successfully handles dealing with multiple `CheckRequest`s.

See #17129
  • Loading branch information
Christopher Neugebauer authored Oct 25, 2022
1 parent b24e742 commit 2aa289a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
26 changes: 24 additions & 2 deletions src/python/pants/core/goals/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
write_reports,
)
from pants.core.util_rules.distdir import DistDir
from pants.core.util_rules.environments import EnvironmentNameRequest
from pants.engine.collection import Collection
from pants.engine.console import Console
from pants.engine.engine_aware import EngineAwareParameter, EngineAwareReturnType
Expand Down Expand Up @@ -175,7 +176,7 @@ def activated(cls, union_membership: UnionMembership) -> bool:

class Check(Goal):
subsystem_cls = CheckSubsystem
environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY # TODO(#17129) — Migrate this.
environment_behavior = Goal.EnvironmentBehavior.USES_ENVIRONMENTS


@goal_rule
Expand All @@ -201,8 +202,29 @@ async def check(
)
for request_type in request_types
)

request_to_field_set = [
(request, field_set) for request in requests for field_set in request.field_sets
]

environment_names = await MultiGet(
Get(
EnvironmentName,
EnvironmentNameRequest,
EnvironmentNameRequest.from_field_set(field_set),
)
for (_, field_set) in request_to_field_set
)

request_to_env_name = {
(request, env_name)
for (request, _), env_name in zip(request_to_field_set, environment_names)
}

# Run each check request in each valid environment (potentially multiple runs per tool)
all_results = await MultiGet(
Get(CheckResults, CheckRequest, request) for request in requests if request.field_sets
Get(CheckResults, {request: CheckRequest, env_name: EnvironmentName})
for (request, env_name) in request_to_env_name
)

results_by_tool: dict[str, list[CheckResult]] = defaultdict(list)
Expand Down
14 changes: 12 additions & 2 deletions src/python/pants/core/goals/check_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
check,
)
from pants.core.util_rules.distdir import DistDir
from pants.core.util_rules.environments import EnvironmentNameRequest
from pants.engine.addresses import Address
from pants.engine.environment import EnvironmentName
from pants.engine.fs import EMPTY_DIGEST, EMPTY_FILE_DIGEST, Workspace
from pants.engine.platform import Platform
from pants.engine.process import FallibleProcessResult, ProcessResultMetadata
Expand Down Expand Up @@ -144,8 +146,16 @@ def run_typecheck_rule(
mock_gets=[
MockGet(
output_type=CheckResults,
input_types=(CheckRequest,),
mock=lambda field_set_collection: field_set_collection.check_results,
input_types=(
CheckRequest,
EnvironmentName,
),
mock=lambda field_set_collection, _: field_set_collection.check_results,
),
MockGet(
output_type=EnvironmentName,
input_types=(EnvironmentNameRequest,),
mock=lambda a: EnvironmentName(a.raw_value),
),
],
union_membership=union_membership,
Expand Down

0 comments on commit 2aa289a

Please sign in to comment.