Skip to content

Commit

Permalink
Merge pull request #3839 from jguice/master
Browse files Browse the repository at this point in the history
Resolution speed improvement
  • Loading branch information
sdispater authored Jul 11, 2021
2 parents b2ac34e + c1891c7 commit 40dc3ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 11 additions & 1 deletion poetry/puzzle/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,10 @@ def _solve(self, use_latest: List[str] = None) -> Tuple[List[Package], List[int]
except SolveFailure as e:
raise SolverProblemError(e)

# NOTE passing explicit empty array for seen to reset between invocations during update + install cycle
results = dict(
depth_first_search(
PackageNode(self._package, packages), aggregate_package_nodes
PackageNode(self._package, packages, seen=[]), aggregate_package_nodes
)
)

Expand Down Expand Up @@ -390,6 +391,7 @@ def __init__(
self,
package: Package,
packages: List[Package],
seen: List[Package],
previous: Optional["PackageNode"] = None,
previous_dep: Optional[
Union[
Expand All @@ -412,6 +414,7 @@ def __init__(
) -> None:
self.package = package
self.packages = packages
self.seen = seen

self.previous = previous
self.previous_dep = previous_dep
Expand All @@ -434,6 +437,12 @@ def __init__(
def reachable(self) -> List["PackageNode"]:
children: List[PackageNode] = []

# skip already traversed packages
if self.package in self.seen:
return []
else:
self.seen.append(self.package)

if (
self.previous_dep
and self.previous_dep is not self.dep
Expand Down Expand Up @@ -470,6 +479,7 @@ def reachable(self) -> List["PackageNode"]:
PackageNode(
pkg,
self.packages,
self.seen,
self,
dependency,
self.dep or dependency,
Expand Down
10 changes: 5 additions & 5 deletions tests/puzzle/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,14 +866,14 @@ def test_solver_with_dependency_in_both_main_and_dev_dependencies(
],
)

d = ops[0].package
b = ops[1].package
c = ops[2].package
d = ops[0].package
a = ops[3].package

assert d.category == "dev"
assert c.category == "dev"
assert b.category == "main"
assert c.category == "dev"
assert a.category == "main"


Expand Down Expand Up @@ -925,15 +925,15 @@ def test_solver_with_dependency_in_both_main_and_dev_dependencies_with_one_more_
)

b = ops[0].package
c = ops[3].package
d = ops[1].package
a = ops[2].package
c = ops[3].package
e = ops[4].package

assert d.category == "dev"
assert c.category == "dev"
assert b.category == "main"
assert d.category == "dev"
assert a.category == "main"
assert c.category == "dev"
assert e.category == "main"


Expand Down

0 comments on commit 40dc3ad

Please sign in to comment.