Skip to content

Commit

Permalink
Don't warn if no relevant targets in glob or --changed.
Browse files Browse the repository at this point in the history
In these cases, the user intent is likely "if there are relevant
targets, act on them", so warning is just annoying.

However we still want to retain the warning if the user provided
literal addresses, filesystem specs, or no specs at all.

[ci skip-rust]

[ci skip-build-wheels]
  • Loading branch information
benjyw committed Apr 3, 2022
1 parent 529979d commit 9ddf6bb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/python/pants/base/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ def __bool__(self) -> bool:
class Specs:
address_specs: AddressSpecs
filesystem_specs: FilesystemSpecs
from_change_detection: bool = False

@property
def provided(self) -> bool:
Expand Down
13 changes: 12 additions & 1 deletion src/python/pants/engine/internals/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,18 @@ async def find_valid_field_sets_for_target_roots(
)
if request.no_applicable_targets_behavior == NoApplicableTargetsBehavior.error:
raise no_applicable_exception
if request.no_applicable_targets_behavior == NoApplicableTargetsBehavior.warn:
# We squelch the warning if the specs came from change detection or only from address globs,
# since in that case we interpret the user's intent as "if there are relevant matching
# targets, act on them". But we still want to warn if the specs were literal, or empty.
empty_ok = specs.from_change_detection or (
specs.address_specs.globs
and not specs.address_specs.literals
and not specs.filesystem_specs
)
if (
request.no_applicable_targets_behavior == NoApplicableTargetsBehavior.warn
and not empty_ok
):
logger.warning(str(no_applicable_exception))

result = TargetRootsToFieldSets(targets_to_applicable_field_sets)
Expand Down
6 changes: 5 additions & 1 deletion src/python/pants/init/specs_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ def calculate_specs(
parameters=address_input.parameters,
)
)
return Specs(AddressSpecs(address_specs, filter_by_global_options=True), FilesystemSpecs([]))
return Specs(
AddressSpecs(address_specs, filter_by_global_options=True),
FilesystemSpecs([]),
from_change_detection=True,
)


def rules():
Expand Down

0 comments on commit 9ddf6bb

Please sign in to comment.