Skip to content

Commit

Permalink
Tweak DescendantAddresses so that call sites can no-op when no matc…
Browse files Browse the repository at this point in the history
…hes (#10012)

For dep inference, we need to use `DescendantAddress(src_root)` for every source root, but this will sometimes fail. For example, Pants has a source root `3rdparty/protobuf`, but doesn't have any BUILD files in it.

We may end up wanting to change the overall CI behavior so that `./pants list ::` would stop failing when no targets exist, but we do not yet want to change the CI behavior until further discussion.

So, this adds an optional field to `DescendantAddresses` so that call sites can determine the behavior they want.

[ci skip-rust-tests]
[ci skip-jvm-tests]
  • Loading branch information
Eric-Arellano authored Jun 10, 2020
1 parent c7923f1 commit a38bd7d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/python/pants/base/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class DescendantAddresses(AddressSpec):
"""An AddressSpec representing all addresses located recursively under the given directory."""

directory: str
error_if_no_matches: bool = True

def to_spec_string(self) -> str:
return f"{self.directory}::"
Expand All @@ -206,9 +207,9 @@ def address_target_pairs_from_address_families(
self, address_families: Sequence["AddressFamily"]
):
addr_tgt_pairs = self.all_address_target_pairs(address_families)
if len(addr_tgt_pairs) == 0:
if self.error_if_no_matches and len(addr_tgt_pairs) == 0:
raise self.AddressResolutionError(
"AddressSpec {} does not match any targets.".format(self)
f"Address spec {repr(self.to_spec_string())} does not match any targets."
)
return addr_tgt_pairs

Expand Down

0 comments on commit a38bd7d

Please sign in to comment.