Skip to content

Commit

Permalink
Always match source globs using the any conjunction. (#20958)
Browse files Browse the repository at this point in the history
Relax the glob matching conjunction to only err if none match rather
than requiring all to match.

See #20947 for background and linked alternative abandoned solution.

Closes #20947.
  • Loading branch information
kaos authored May 28, 2024
1 parent 772e321 commit 81962e6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
_SOURCES_TARGET_BASE = "testprojects/src/python/sources"

_ERR_TARGETS = {
"testprojects/src/python/sources:some-missing-some-not": 'Unmatched glob from testprojects/src/python/sources:some-missing-some-not\'s `sources` field: "testprojects/src/python/sources/*.rs"',
"testprojects/src/python/sources:missing-sources": 'Unmatched glob from testprojects/src/python/sources:missing-sources\'s `sources` field: "testprojects/src/python/sources/*.scala", excludes: ["testprojects/src/python/sources/*Spec.scala", "testprojects/src/python/sources/*Suite.scala", "testprojects/src/python/sources/*Test.scala"]',
}

Expand Down

0 comments on commit 81962e6

Please sign in to comment.