Skip to content

Commit

Permalink
Adds warning if lint/fmt/fix runs on a target using a non-local envir…
Browse files Browse the repository at this point in the history
…onment. (#17359)

This adds a warning if a target-based `fmt`/`lint`/`fix` operation runs against a target that specifies a non-local environment. 

To property use environments, we'll need a way of making the partitioning rules a bit more pluggable, or decide that individual back-end implementations will be responsible for deciding where they run (which is probably also not great).

Addresses #17129.
  • Loading branch information
Christopher Neugebauer authored Oct 28, 2022
1 parent 12e339d commit a971882
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/python/pants/core/goals/fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def activated(cls, union_membership: UnionMembership) -> bool:

class Fix(Goal):
subsystem_cls = FixSubsystem
environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY # TODO(#17129) — Migrate this.
environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY


@rule_helper
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/core/goals/fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def activated(cls, union_membership: UnionMembership) -> bool:

class Fmt(Goal):
subsystem_cls = FmtSubsystem
environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY # TODO(#17129) — Migrate this.
environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY


@goal_rule
Expand Down
5 changes: 4 additions & 1 deletion src/python/pants/core/goals/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
write_reports,
)
from pants.core.util_rules.distdir import DistDir
from pants.core.util_rules.environments import _warn_on_non_local_environments
from pants.core.util_rules.partitions import PartitionElementT, PartitionerType, PartitionMetadataT
from pants.core.util_rules.partitions import Partitions as Partitions # re-export
from pants.core.util_rules.partitions import (
Expand Down Expand Up @@ -267,7 +268,7 @@ def activated(cls, union_membership: UnionMembership) -> bool:

class Lint(Goal):
subsystem_cls = LintSubsystem
environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY # TODO(#17129) — Migrate this.
environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY


def _print_results(
Expand Down Expand Up @@ -365,6 +366,8 @@ async def _get_partitions_by_request_type(

targets, specs_paths = await MultiGet(_get_targets, _get_specs_paths)

await _warn_on_non_local_environments(targets, f"the {subsystem.name} goal")

def partition_request_get(request_type: type[LintRequest]) -> Get[Partitions]:
partition_request_type: type = getattr(request_type, "PartitionRequest")
if partition_request_type in target_partitioners:
Expand Down
7 changes: 7 additions & 0 deletions src/python/pants/core/goals/lint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
lint,
)
from pants.core.util_rules.distdir import DistDir
from pants.core.util_rules.environments import EnvironmentNameRequest
from pants.core.util_rules.partitions import Partition, PartitionerType
from pants.engine.addresses import Address
from pants.engine.environment import EnvironmentName
from pants.engine.fs import PathGlobs, SpecsPaths, Workspace
from pants.engine.internals.native_engine import EMPTY_SNAPSHOT, Snapshot
from pants.engine.rules import QueryRule
Expand Down Expand Up @@ -308,6 +310,11 @@ def run_lint_rule(
input_types=(LintTargetsRequest.PartitionRequest,),
mock=mock_target_partitioner,
),
MockGet(
output_type=EnvironmentName,
input_types=(EnvironmentNameRequest,),
mock=lambda _: EnvironmentName(None),
),
MockGet(
output_type=Partitions,
input_types=(LintFilesRequest.PartitionRequest,),
Expand Down

0 comments on commit a971882

Please sign in to comment.