App: Return cycle path from find_circular_deps()
The __find_circular_deps() and find_circular_deps() methods now return list[str] instead of bool. On a cycle, the path builds up the dependency chain in __find_circular_deps_recursive(), and __find_circular_deps() appends the closing project to complete the cycle. An empty list means no cycle found.
CmdDep prints the cycle as 'a -> b -> c -> a' instead of a generic message.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL and pi.devSigned-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
fdae5ad122
commit
24d67a5ec0
2 changed files with 15 additions and 7 deletions
|
|
@ -315,7 +315,8 @@ class App(Base):
|
||||||
temp.remove(project)
|
temp.remove(project)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def __find_circular_deps(self, projects: list[str], flavours: list[str]) -> bool:
|
def __find_circular_deps(self, projects: list[str],
|
||||||
|
flavours: list[str]) -> list[str]:
|
||||||
graph: Graph = {}
|
graph: Graph = {}
|
||||||
ret: list[str] = []
|
ret: list[str] = []
|
||||||
self.__read_dep_graph(projects, flavours, graph)
|
self.__read_dep_graph(projects, flavours, graph)
|
||||||
|
|
@ -330,8 +331,9 @@ class App(Base):
|
||||||
)
|
)
|
||||||
if last is not None:
|
if last is not None:
|
||||||
log(DEBUG, f'Found circular dependency below {project}, last is {last}')
|
log(DEBUG, f'Found circular dependency below {project}, last is {last}')
|
||||||
return True
|
ret.append(last)
|
||||||
return False
|
return ret
|
||||||
|
return []
|
||||||
|
|
||||||
def __init__(self, distro: Distro | None = None) -> None:
|
def __init__(self, distro: Distro | None = None) -> None:
|
||||||
|
|
||||||
|
|
@ -627,5 +629,5 @@ class App(Base):
|
||||||
return ', '.join(intersection)
|
return ', '.join(intersection)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def find_circular_deps(self, projects: list[str], flavours: list[str]) -> bool:
|
def find_circular_deps(self, projects: list[str], flavours: list[str]) -> list[str]:
|
||||||
return self.__find_circular_deps(projects, flavours)
|
return self.__find_circular_deps(projects, flavours)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from ....lib.log import NOTICE, log
|
from ....lib.log import NOTICE, log
|
||||||
from .Cmd import Cmd, Parent
|
from .Cmd import Cmd, Parent
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from argparse import ArgumentParser, Namespace
|
from argparse import ArgumentParser, Namespace
|
||||||
|
|
@ -22,8 +23,13 @@ class CmdDep(Cmd): # export
|
||||||
parser.add_argument('-f', '--flavour', nargs = '?', default = 'build')
|
parser.add_argument('-f', '--flavour', nargs = '?', default = 'build')
|
||||||
|
|
||||||
async def _run(self, args: Namespace) -> None:
|
async def _run(self, args: Namespace) -> None:
|
||||||
if self.app.find_circular_deps(args.module, args.flavour):
|
cycle = self.app.find_circular_deps(args.module, args.flavour)
|
||||||
log(NOTICE, f'Found circular dependency in flavour {args.flavour}')
|
if cycle:
|
||||||
|
log(
|
||||||
|
NOTICE,
|
||||||
|
f'Found circular dependency in flavour {args.flavour}: '
|
||||||
|
' -> '.join(cycle)
|
||||||
|
)
|
||||||
exit(1)
|
exit(1)
|
||||||
log(
|
log(
|
||||||
NOTICE,
|
NOTICE,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue