Skip to content

Commit

Permalink
remove special cases from depth first search
Browse files Browse the repository at this point in the history
- regular depth-first search already handles circular dependencies and
  hitting the same package twice
  - the special cases might have saved a teensy amount of work, but the
    simplification is preferable

- pre-release handling here was not consistent with code elsewhere, and
  since "elsewhere" happens first, it wins
  - given a constraint like ">=1.0" the removed code would have allowed
    1.0rc1, but elsewhere in the codebase constraints are taken to mean
    what they say
  • Loading branch information
dimbleby authored and neersighted committed Aug 28, 2022
1 parent 3ff5a39 commit 27fa9c1
Showing 1 changed file with 2 additions and 33 deletions.
35 changes: 2 additions & 33 deletions src/poetry/puzzle/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,11 @@ def __init__(
package: Package,
packages: list[Package],
previous: PackageNode | None = None,
previous_dep: Dependency | None = None,
dep: Dependency | None = None,
) -> None:
self.package = package
self.packages = packages

self.previous = previous
self.previous_dep = previous_dep
self.dep = dep
self.depth = -1

Expand All @@ -283,44 +280,16 @@ def __init__(
def reachable(self) -> list[PackageNode]:
children: list[PackageNode] = []

if (
self.dep
and self.previous_dep
and self.previous_dep is not self.dep
and self.previous_dep.name == self.dep.name
):
return []

for dependency in self.package.all_requires:
if self.previous and self.previous.name == dependency.name:
# We have a circular dependency.
# Since the dependencies are resolved we can
# simply skip it because we already have it
# N.B. this only catches cycles of length 2;
# dependency cycles in general are handled by the DFS traversal
continue

for pkg in self.packages:
if (
pkg.complete_name == dependency.complete_name
and (
dependency.constraint.allows(pkg.version)
or dependency.allows_prereleases()
and pkg.version.is_unstable()
and dependency.constraint.allows(pkg.version.stable)
)
and not any(
child.package.complete_name == pkg.complete_name
and child.groups == dependency.groups
for child in children
)
if pkg.complete_name == dependency.complete_name and (
dependency.constraint.allows(pkg.version)
):
children.append(
PackageNode(
pkg,
self.packages,
self,
dependency,
self.dep or dependency,
)
)
Expand Down

0 comments on commit 27fa9c1

Please sign in to comment.