Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Commit

Permalink
Add transitive parameter to UnionProducts.get_for_target[s]
Browse files Browse the repository at this point in the history
Testing Done:
CI is baking: https://travis-ci.org/pantsbuild/pants/builds/78112646

Added tests for the new parameter to:
  * `tests/python/pants_test/goal/test_union_products.py:test_get_for_target`.

Reviewed at https://rbcommons.com/s/twitter/r/2741/
  • Loading branch information
Patrick Lawson committed Aug 31, 2015
1 parent 3a715bc commit f5ff8d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/python/pants/goal/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,21 @@ def remove_for_target(self, target, products):
for product in products:
self._products_by_target[target].discard(product)

def get_for_target(self, target):
def get_for_target(self, target, transitive=True):
"""Gets the transitive product deps for the given target."""
return self.get_for_targets([target])
return self.get_for_targets([target], transitive=transitive)

def get_for_targets(self, targets):
def get_for_targets(self, targets, transitive=True):
"""Gets the transitive product deps for the given targets, in order."""
products = OrderedSet()
visited = set()
# Walk the targets transitively to aggregate their products. We do a breadth-first
for target in targets:
for dep in target.closure(bfs=True):
if transitive:
deps = target.closure(bfs=True)
else:
deps = [target]
for dep in deps:
if dep not in visited:
products.update(self._products_by_target[dep])
visited.add(dep)
Expand Down
3 changes: 3 additions & 0 deletions tests/python/pants_test/goal/test_union_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def test_get_for_target(self):
self.assertEquals(self.products.get_for_target(a), OrderedSet([1, 2, 3]))
self.assertEquals(self.products.get_for_target(b), OrderedSet([2, 3]))
self.assertEquals(self.products.get_for_target(c), OrderedSet([3]))
self.assertEquals(self.products.get_for_target(a, transitive=False), OrderedSet([1]))
self.assertEquals(self.products.get_for_target(b, transitive=False), OrderedSet([2]))
self.assertEquals(self.products.get_for_target(c, transitive=False), OrderedSet([3]))

def test_remove_for_target(self):
c = self.make_target('c')
Expand Down

0 comments on commit f5ff8d0

Please sign in to comment.