Skip to content

Commit

Permalink
Always match source globs using the any conjunction.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaos committed May 27, 2024
1 parent 57a230c commit 4b734d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/notes/2.22.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ We offer [formal sponsorship tiers for companies](https://www.pantsbuild.org/spo
### Highlights

- A new implementation of the options system.
- Source globs are now less strict, using a "match any" conjunction rather than the previous "match all".

### New options system

Expand Down
14 changes: 5 additions & 9 deletions src/python/pants/engine/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -2190,23 +2190,19 @@ def path_globs(self, unmatched_build_file_globs: UnmatchedBuildFileGlobs) -> Pat
[self.default] if self.default and isinstance(self.default, str) else self.default
)

# Match any if we use default globs, else match all.
conjunction = (
GlobExpansionConjunction.all_match
if not default_globs or (set(self.globs) != set(default_globs))
else GlobExpansionConjunction.any_match
)
using_default_globs = default_globs and (set(self.globs) == set(default_globs)) or False

# Use fields default error behavior if defined, if we use default globs else the provided
# error behavior.
error_behavior = (
unmatched_build_file_globs.error_behavior
if conjunction == GlobExpansionConjunction.all_match
or self.default_glob_match_error_behavior is None
if not using_default_globs or self.default_glob_match_error_behavior is None
else self.default_glob_match_error_behavior
)

return PathGlobs(
(self._prefix_glob_with_address(glob) for glob in self.globs),
conjunction=conjunction,
conjunction=GlobExpansionConjunction.any_match,
glob_match_error_behavior=error_behavior,
description_of_origin=(
f"{self.address}'s `{self.alias}` field"
Expand Down
6 changes: 3 additions & 3 deletions src/python/pants/engine/target_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ class GenSources(GenerateSourcesRequest):
"test/b",
),
glob_match_error_behavior=GlobMatchErrorBehavior.warn,
conjunction=GlobExpansionConjunction.all_match,
conjunction=GlobExpansionConjunction.any_match,
description_of_origin="test:test's `sources` field",
),
id="provided value warns on glob match error",
Expand Down Expand Up @@ -1108,7 +1108,7 @@ class TestMultipleSourcesField(MultipleSourcesField):
expected_path_globs(
globs=("test/other_file",),
glob_match_error_behavior=GlobMatchErrorBehavior.warn,
conjunction=GlobExpansionConjunction.all_match,
conjunction=GlobExpansionConjunction.any_match,
description_of_origin="test:test's `source` field",
),
id="provided value warns on glob match error",
Expand All @@ -1119,7 +1119,7 @@ class TestMultipleSourcesField(MultipleSourcesField):
expected_path_globs(
globs=("test/life",),
glob_match_error_behavior=GlobMatchErrorBehavior.warn,
conjunction=GlobExpansionConjunction.all_match,
conjunction=GlobExpansionConjunction.any_match,
description_of_origin="test:test's `source` field",
),
id="default glob conjunction",
Expand Down

0 comments on commit 4b734d8

Please sign in to comment.