diff options
Diffstat (limited to 'buildscripts/libdeps/libdeps/analyzer.py')
-rw-r--r-- | buildscripts/libdeps/libdeps/analyzer.py | 101 |
1 files changed, 44 insertions, 57 deletions
diff --git a/buildscripts/libdeps/libdeps/analyzer.py b/buildscripts/libdeps/libdeps/analyzer.py index 756d410d4e8..c440fcf7d8f 100644 --- a/buildscripts/libdeps/libdeps/analyzer.py +++ b/buildscripts/libdeps/libdeps/analyzer.py @@ -115,17 +115,14 @@ class Analyzer: """Base class for different types of analyzers.""" # pylint: disable=too-many-instance-attributes - def __init__(self, graph, progress=True): + def __init__(self, dependency_graph, progress=True): """Store the graph and extract the build_dir from the graph.""" - self.graph_schema = graph.graph.get('graph_schema_version') - if self.graph_schema == 1: - self._dependents_graph = graph - else: - self._dependency_graph = graph + self.graph_schema = dependency_graph.graph.get('graph_schema_version') + self._dependency_graph = dependency_graph - self._build_dir = Path(graph.graph['build_dir']) - self.deptypes = json.loads(graph.graph.get('deptypes', "{}")) + self._build_dir = Path(dependency_graph.graph['build_dir']) + self.deptypes = json.loads(dependency_graph.graph.get('deptypes', "{}")) self.set_progress(progress) @property @@ -153,16 +150,6 @@ class Analyzer: return int(self._dependency_graph.get_deptype(deptype)) - def _strip_build_dir(self, node): - """Small util function for making args match the graph paths.""" - - return str(Path(node).relative_to(self._build_dir)) - - def _strip_build_dirs(self, nodes): - """Small util function for making a list of nodes match graph paths.""" - - return [self._strip_build_dir(node) for node in nodes] - def set_progress(self, value=None): """Get a progress bar from the loaded graph.""" @@ -198,10 +185,10 @@ class Counter(Analyzer): class NodeCounter(Counter): """Counts and reports number of nodes in the graph.""" - def __init__(self, graph): + def __init__(self, dependency_graph): """Store graph and set type.""" - super().__init__(graph) + super().__init__(dependency_graph) self._count_type = CountTypes.NODE.name @schema_check(schema_version=1) @@ -214,10 +201,10 @@ class NodeCounter(Counter): class EdgeCounter(Counter): """Counts and reports number of edges in the graph.""" - def __init__(self, graph): + def __init__(self, dependency_graph): """Store graph and set type.""" - super().__init__(graph) + super().__init__(dependency_graph) self._count_type = CountTypes.EDGE.name @schema_check(schema_version=1) @@ -230,10 +217,10 @@ class EdgeCounter(Counter): class DirectEdgeCounter(Counter): """Counts and reports number of direct edges in the graph.""" - def __init__(self, graph): + def __init__(self, dependency_graph): """Store graph and set type.""" - super().__init__(graph) + super().__init__(dependency_graph) self._count_type = CountTypes.DIR_EDGE.name @schema_check(schema_version=1) @@ -246,10 +233,10 @@ class DirectEdgeCounter(Counter): class TransEdgeCounter(Counter): """Counts and reports number of transitive edges in the graph.""" - def __init__(self, graph): + def __init__(self, dependency_graph): """Store graph and set type.""" - super().__init__(graph) + super().__init__(dependency_graph) self._count_type = CountTypes.TRANS_EDGE.name @schema_check(schema_version=1) @@ -262,10 +249,10 @@ class TransEdgeCounter(Counter): class DirectPubEdgeCounter(Counter): """Counts and reports number of direct public edges in the graph.""" - def __init__(self, graph): + def __init__(self, dependency_graph): """Store graph and set type.""" - super().__init__(graph) + super().__init__(dependency_graph) self._count_type = CountTypes.DIR_PUB_EDGE.name @schema_check(schema_version=1) @@ -281,10 +268,10 @@ class DirectPubEdgeCounter(Counter): class PublicEdgeCounter(Counter): """Counts and reports number of public edges in the graph.""" - def __init__(self, graph): + def __init__(self, dependency_graph): """Store graph and set type.""" - super().__init__(graph) + super().__init__(dependency_graph) self._count_type = CountTypes.PUB_EDGE.name @schema_check(schema_version=1) @@ -297,10 +284,10 @@ class PublicEdgeCounter(Counter): class PrivateEdgeCounter(Counter): """Counts and reports number of private edges in the graph.""" - def __init__(self, graph): + def __init__(self, dependency_graph): """Store graph and set type.""" - super().__init__(graph) + super().__init__(dependency_graph) self._count_type = CountTypes.PRIV_EDGE.name @schema_check(schema_version=1) @@ -314,10 +301,10 @@ class PrivateEdgeCounter(Counter): class InterfaceEdgeCounter(Counter): """Counts and reports number of interface edges in the graph.""" - def __init__(self, graph): + def __init__(self, dependency_graph): """Store graph and set type.""" - super().__init__(graph) + super().__init__(dependency_graph) self._count_type = CountTypes.IF_EDGE.name @schema_check(schema_version=1) @@ -331,10 +318,10 @@ class InterfaceEdgeCounter(Counter): class LibCounter(Counter): """Counts and reports number of library nodes in the graph.""" - def __init__(self, graph): + def __init__(self, dependency_graph): """Store graph and set type.""" - super().__init__(graph) + super().__init__(dependency_graph) self._count_type = CountTypes.LIB.name @schema_check(schema_version=1) @@ -347,10 +334,10 @@ class LibCounter(Counter): class ProgCounter(Counter): """Counts and reports number of program nodes in the graph.""" - def __init__(self, graph): + def __init__(self, dependency_graph): """Store graph and set type.""" - super().__init__(graph) + super().__init__(dependency_graph) self._count_type = CountTypes.PROG.name @schema_check(schema_version=1) @@ -360,7 +347,7 @@ class ProgCounter(Counter): return self.node_type_count(NodeProps.bin_type.name, 'Program') -def counter_factory(graph, counters, progressbar=True): +def counter_factory(dependency_graph, counters, progressbar=True): """Construct counters from a list of strings.""" counter_map = { @@ -382,7 +369,7 @@ def counter_factory(graph, counters, progressbar=True): counter_objs = [] for counter in counters: if counter in counter_map: - counter_obj = counter_map[counter](graph) + counter_obj = counter_map[counter](dependency_graph) counter_obj.set_progress(progressbar) counter_objs.append(counter_obj) @@ -395,11 +382,11 @@ def counter_factory(graph, counters, progressbar=True): class CommonDependents(Analyzer): """Finds common dependent nodes for a set of given dependency nodes.""" - def __init__(self, graph, nodes): + def __init__(self, dependency_graph, nodes): """Store graph and strip the nodes.""" - super().__init__(graph) - self._nodes = self._strip_build_dirs(nodes) + super().__init__(dependency_graph) + self._nodes = nodes @schema_check(schema_version=1) def run(self): @@ -419,11 +406,11 @@ class CommonDependents(Analyzer): class DirectDependents(Analyzer): """Finds direct dependent nodes for a given dependency node.""" - def __init__(self, graph, node): + def __init__(self, dependency_graph, node): """Store graph and strip the node.""" - super().__init__(graph) - self._node = self._strip_build_dir(node) + super().__init__(dependency_graph) + self._node = node @schema_check(schema_version=1) def run(self): @@ -445,11 +432,11 @@ class DirectDependents(Analyzer): class ExcludeDependents(Analyzer): """Finds dependents which depend on the first input node, but exclude the other input nodes.""" - def __init__(self, graph, nodes): + def __init__(self, dependency_graph, nodes): """Store graph and strip the nodes.""" - super().__init__(graph) - self._nodes = self._strip_build_dirs(nodes) + super().__init__(dependency_graph) + self._nodes = nodes @schema_check(schema_version=1) def run(self): @@ -509,11 +496,11 @@ class InDegreeOne(Analyzer): class GraphPaths(Analyzer): """Finds all paths between two nodes in the graph.""" - def __init__(self, graph, from_node, to_node): + def __init__(self, dependency_graph, from_node, to_node): """Store graph and strip the nodes.""" - super().__init__(graph) - self._from_node, self._to_node = self._strip_build_dirs([from_node, to_node]) + super().__init__(dependency_graph) + self._from_node, self._to_node = from_node, to_node @schema_check(schema_version=1) def run(self): @@ -545,11 +532,11 @@ class GraphPaths(Analyzer): class CriticalEdges(Analyzer): """Finds all edges between two nodes, where removing those edges disconnects the two nodes.""" - def __init__(self, graph, from_node, to_node): + def __init__(self, dependency_graph, from_node, to_node): """Store graph and strip the nodes.""" - super().__init__(graph) - self._from_node, self._to_node = self._strip_build_dirs([from_node, to_node]) + super().__init__(dependency_graph) + self._from_node, self._to_node = from_node, to_node @schema_check(schema_version=1) def run(self): @@ -672,7 +659,7 @@ class UnusedPublicLinter(Analyzer): report[LinterTypes.PUBLIC_UNUSED.name] = self.run() -def linter_factory(graph, linters, progressbar=True): +def linter_factory(dependency_graph, linters, progressbar=True): """Construct linters from a list of strings.""" linter_map = { @@ -685,7 +672,7 @@ def linter_factory(graph, linters, progressbar=True): linters_objs = [] for linter in linters: if linter in linter_map: - linters_objs.append(linter_map[linter](graph, progressbar)) + linters_objs.append(linter_map[linter](dependency_graph, progressbar)) else: print(f"Skipping unknown counter: {linter}") |