From 9ddf6bbeecdcdb5488826ab508d8fc67dc0d2613 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Sat, 2 Apr 2022 17:49:52 -0700 Subject: [PATCH] Don't warn if no relevant targets in glob or --changed. 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] --- src/python/pants/base/specs.py | 1 + src/python/pants/engine/internals/graph.py | 13 ++++++++++++- src/python/pants/init/specs_calculator.py | 6 +++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/python/pants/base/specs.py b/src/python/pants/base/specs.py index 296b44856db..1fb404d38fb 100644 --- a/src/python/pants/base/specs.py +++ b/src/python/pants/base/specs.py @@ -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: diff --git a/src/python/pants/engine/internals/graph.py b/src/python/pants/engine/internals/graph.py index ea0fad1d0e8..293e1b040ef 100644 --- a/src/python/pants/engine/internals/graph.py +++ b/src/python/pants/engine/internals/graph.py @@ -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) diff --git a/src/python/pants/init/specs_calculator.py b/src/python/pants/init/specs_calculator.py index 4443f9b605f..8e5dbc0c89a 100644 --- a/src/python/pants/init/specs_calculator.py +++ b/src/python/pants/init/specs_calculator.py @@ -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():