diff --git a/docs/notes/2.22.x.md b/docs/notes/2.22.x.md index 616cf26f603..6eba05c7fe2 100644 --- a/docs/notes/2.22.x.md +++ b/docs/notes/2.22.x.md @@ -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 diff --git a/src/python/pants/engine/target.py b/src/python/pants/engine/target.py index 028ddfa5ce1..1ed2b2a034a 100644 --- a/src/python/pants/engine/target.py +++ b/src/python/pants/engine/target.py @@ -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" diff --git a/src/python/pants/engine/target_test.py b/src/python/pants/engine/target_test.py index 74cb89d2edd..af4381f7815 100644 --- a/src/python/pants/engine/target_test.py +++ b/src/python/pants/engine/target_test.py @@ -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", @@ -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", @@ -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",