Fix circular dependency error message to show actual cycle path

The error was hardcoding [pkg_key, pkg_key] regardless of actual cycle.
Now tracks the path through dependencies to report the real cycle.
This commit is contained in:
Mondo Diaz
2026-02-02 20:43:05 -06:00
parent ac3477ff22
commit 34ff9caa08

View File

@@ -698,6 +698,8 @@ def resolve_dependencies(
# Track visiting/visited for cycle detection
visiting: Set[str] = set()
visited: Set[str] = set()
# Track the current path for cycle reporting (artifact_id -> pkg_key)
current_path: Dict[str, str] = {}
# Resolution order (topological)
resolution_order: List[str] = []
@@ -719,8 +721,10 @@ def resolve_dependencies(
# Cycle detection (at artifact level)
if artifact_id in visiting:
# Build cycle path
raise CircularDependencyError([pkg_key, pkg_key])
# Build cycle path from current_path
cycle_start = current_path.get(artifact_id, pkg_key)
cycle = [cycle_start, pkg_key]
raise CircularDependencyError(cycle)
# Conflict detection - check if we've seen this package before with a different version
if pkg_key in version_requirements:
@@ -751,6 +755,7 @@ def resolve_dependencies(
return
visiting.add(artifact_id)
current_path[artifact_id] = pkg_key
# Track version requirement
if pkg_key not in version_requirements:
@@ -807,6 +812,7 @@ def resolve_dependencies(
)
visiting.remove(artifact_id)
del current_path[artifact_id]
visited.add(artifact_id)
# Add to resolution order (dependencies before dependents)