Coverage for src/git_dag/interfaces/dag_base.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-08 12:49 +0200

1"""Based class to interface DAG backends.""" 

2 

3from abc import ABC, abstractmethod 

4from typing import Any, Literal, Optional 

5 

6from ..constants import DictStrStr 

7 

8 

9class DagBase(ABC): 

10 """DAG base class.""" 

11 

12 def __init__(self, standalone_cluster: bool = False) -> None: 

13 self._dag: Any = None 

14 self.nodes: list[dict[str, Optional[str]]] = [] 

15 self.edges: list[tuple[str, str]] = [] 

16 self.edges_custom: list[tuple[str, str, DictStrStr]] = [] 

17 self.standalone_trees: list[dict[str, Optional[str]]] = [] 

18 self.standalone_blobs: list[dict[str, Optional[str]]] = [] 

19 self.standalone_cluster = standalone_cluster 

20 

21 @abstractmethod 

22 def edge(self, node1_name: str, node2_name: str, **attrs: str) -> None: 

23 """Add an edge.""" 

24 

25 @abstractmethod 

26 def node( # pylint: disable=too-many-positional-arguments 

27 self, 

28 name: str, 

29 label: str, 

30 color: str, 

31 tooltip: Optional[str] = None, 

32 URL: Optional[str] = None, 

33 standalone_kind: Optional[Literal["tree", "blob"]] = None, 

34 **attrs: str, 

35 ) -> None: 

36 """Add a node.""" 

37 

38 @abstractmethod 

39 def build( # pylint: disable=too-many-positional-arguments 

40 self, 

41 format: str, # pylint: disable=redefined-builtin 

42 node_attr: DictStrStr, 

43 edge_attr: DictStrStr, 

44 dag_attr: DictStrStr, 

45 filename: str, 

46 cluster_params: DictStrStr, 

47 ) -> None: 

48 """Build the graph.""" 

49 

50 @abstractmethod 

51 def render(self) -> None: 

52 """Render the graph.""" 

53 

54 @abstractmethod 

55 def source(self) -> str: 

56 """Return graph source file.""" 

57 

58 @abstractmethod 

59 def get(self) -> Any: 

60 """Return the backend graph object."""