From c095f3b76d3deddcf4bb5cfd775754a2f81dd79f Mon Sep 17 00:00:00 2001 From: Alex Schmitt Date: Mon, 25 Feb 2019 10:49:57 -0800 Subject: [PATCH] Update TargetFiltering args for applying criteria (#7280) Update the class to take the criteria in the constructor, and helper methods take the targets against which to apply said criteria. From suggestion https://github.com/pantsbuild/pants/pull/7275\#discussion_r259554586 --- src/python/pants/build_graph/target_filter_subsystem.py | 9 ++++----- .../build_graph/test_target_filter_subsystem.py | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/python/pants/build_graph/target_filter_subsystem.py b/src/python/pants/build_graph/target_filter_subsystem.py index af6d4b766fa..ae53b7cd743 100644 --- a/src/python/pants/build_graph/target_filter_subsystem.py +++ b/src/python/pants/build_graph/target_filter_subsystem.py @@ -31,15 +31,14 @@ def register_options(cls, register): def apply(self, targets): exclude_tags = set(self.get_options().exclude_tags) - return TargetFiltering(targets, exclude_tags).apply_tag_blacklist() + return TargetFiltering(exclude_tags).apply_tag_blacklist(targets) class TargetFiltering(object): """Apply filtering logic against targets.""" - def __init__(self, targets, exclude_tags): - self.targets = targets + def __init__(self, exclude_tags): self.exclude_tags = exclude_tags - def apply_tag_blacklist(self): - return [t for t in self.targets if not self.exclude_tags.intersection(t.tags)] + def apply_tag_blacklist(self, targets): + return [t for t in targets if not self.exclude_tags.intersection(t.tags)] diff --git a/tests/python/pants_test/build_graph/test_target_filter_subsystem.py b/tests/python/pants_test/build_graph/test_target_filter_subsystem.py index 3c9fd41c0d1..9b7cb3f8bf8 100644 --- a/tests/python/pants_test/build_graph/test_target_filter_subsystem.py +++ b/tests/python/pants_test/build_graph/test_target_filter_subsystem.py @@ -41,7 +41,7 @@ def test_filtering_single_tag(self): b = self.make_target('b', tags=['skip-me']) c = self.make_target('c', tags=['tag1', 'skip-me']) - filtered_targets = TargetFiltering([a, b, c], {'skip-me'}).apply_tag_blacklist() + filtered_targets = TargetFiltering({'skip-me'}).apply_tag_blacklist([a, b, c]) self.assertEqual([a], filtered_targets) def test_filtering_multiple_tags(self): @@ -49,7 +49,7 @@ def test_filtering_multiple_tags(self): b = self.make_target('b', tags=['tag1', 'tag2', 'skip-me']) c = self.make_target('c', tags=['tag2']) - filtered_targets = TargetFiltering([a, b, c], {'skip-me', 'tag2'}).apply_tag_blacklist() + filtered_targets = TargetFiltering({'skip-me', 'tag2'}).apply_tag_blacklist([a, b, c]) self.assertEqual([], filtered_targets) def test_filtering_no_tags(self): @@ -57,5 +57,5 @@ def test_filtering_no_tags(self): b = self.make_target('b', tags=['tag1', 'tag2']) c = self.make_target('c', tags=['tag2']) - filtered_targets = TargetFiltering([a, b, c], set()).apply_tag_blacklist() + filtered_targets = TargetFiltering(set()).apply_tag_blacklist([a, b, c]) self.assertEqual([a, b, c], filtered_targets)