Commit 27fa9c1e by David Hotham Committed by Bjorn Neergaard

remove special cases from depth first search

- 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
parent 3ff5a39b
...@@ -252,14 +252,11 @@ class PackageNode(DFSNode): ...@@ -252,14 +252,11 @@ class PackageNode(DFSNode):
package: Package, package: Package,
packages: list[Package], packages: list[Package],
previous: PackageNode | None = None, previous: PackageNode | None = None,
previous_dep: Dependency | None = None,
dep: Dependency | None = None, dep: Dependency | None = None,
) -> None: ) -> None:
self.package = package self.package = package
self.packages = packages self.packages = packages
self.previous = previous
self.previous_dep = previous_dep
self.dep = dep self.dep = dep
self.depth = -1 self.depth = -1
...@@ -283,44 +280,16 @@ class PackageNode(DFSNode): ...@@ -283,44 +280,16 @@ class PackageNode(DFSNode):
def reachable(self) -> list[PackageNode]: def reachable(self) -> list[PackageNode]:
children: 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: 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: for pkg in self.packages:
if ( if pkg.complete_name == dependency.complete_name and (
pkg.complete_name == dependency.complete_name dependency.constraint.allows(pkg.version)
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
)
): ):
children.append( children.append(
PackageNode( PackageNode(
pkg, pkg,
self.packages, self.packages,
self, self,
dependency,
self.dep or dependency, self.dep or dependency,
) )
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment