Skip to content

Commit

Permalink
Reverse direction of dependencies when determining target packages. (g…
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes authored and landrito committed Aug 21, 2017
1 parent d833cd0 commit 609873d
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion test_utils/scripts/get_target_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,37 @@ def get_changed_files():
return None


def reverse_map(dict_of_sets):
"""Reverse a map of one-to-many.
So the map::
{
'A': {'B', 'C'},
'B': {'C'},
}
becomes
{
'B': {'A'},
'C': {'A', 'B'},
}
Args:
dict_of_sets (dict[set]): A dictionary of sets, mapping
one value to many.
Returns:
dict[set]: The reversed map.
"""
result = {}
for key, values in dict_of_sets.items():
for value in values:
result.setdefault(value, set()).add(key)

return result

def get_changed_packages(file_list):
"""Return a list of changed packages based on the provided file list.
Expand All @@ -129,6 +160,7 @@ def get_changed_packages(file_list):

# Create a set based on the list of changed files.
answer = set()
reverse_deps = reverse_map(PKG_DEPENDENCIES)
for file_ in file_list:
# Ignore root directory changes (setup.py, .gitignore, etc.).
if os.path.sep not in file_:
Expand All @@ -147,7 +179,7 @@ def get_changed_packages(file_list):
# Add the package, as well as any dependencies this package has.
# NOTE: For now, dependencies only go down one level.
answer.add(package)
answer = answer.union(PKG_DEPENDENCIES.get(package, set()))
answer = answer.union(reverse_deps.get(package, set()))

# We got this far without being short-circuited; return the final answer.
return answer
Expand Down

0 comments on commit 609873d

Please sign in to comment.