Skip to content

Commit

Permalink
Merge pull request #9055 from pradyunsg/modify-assertion-in-topologic…
Browse files Browse the repository at this point in the history
…al-sort
  • Loading branch information
pradyunsg authored Oct 27, 2020
2 parents 5bfd1db + 45d3a3e commit f5ac343
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/pip/_internal/resolution/resolvelib/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ def get_installation_order(self, req_set):
assert self._result is not None, "must call resolve() first"

graph = self._result.graph
weights = get_topological_weights(graph)
weights = get_topological_weights(
graph,
expected_node_count=len(self._result.mapping) + 1,
)

sorted_items = sorted(
req_set.requirements.items(),
Expand All @@ -190,8 +193,8 @@ def get_installation_order(self, req_set):
return [ireq for _, ireq in sorted_items]


def get_topological_weights(graph):
# type: (Graph) -> Dict[Optional[str], int]
def get_topological_weights(graph, expected_node_count):
# type: (Graph, int) -> Dict[Optional[str], int]
"""Assign weights to each node based on how "deep" they are.
This implementation may change at any point in the future without prior
Expand Down Expand Up @@ -231,7 +234,7 @@ def visit(node):

# Sanity checks
assert weights[None] == 0
assert len(weights) == len(graph)
assert len(weights) == expected_node_count

return weights

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/resolution_resolvelib/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,5 @@ def test_new_resolver_get_installation_order(resolver, edges, ordered_reqs):
def test_new_resolver_topological_weights(name, edges, expected_weights):
graph = _make_graph(edges)

weights = get_topological_weights(graph)
weights = get_topological_weights(graph, len(expected_weights))
assert weights == expected_weights

0 comments on commit f5ac343

Please sign in to comment.