How to use the importlab.graph.Cycle function in importlab

To help you get started, we’ve selected a few importlab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / importlab / tests / test_graph.py View on Github external
def test_flatten(self):
        a = graph.Cycle([[1, 2], [2, 3], [3, 1]])
        b = graph.Cycle([[4, 5], [5, 4]])
        c = graph.Cycle([[a, 6], [6, b], [b, 7], [7, a]])
        nodes = c.flatten_nodes()
        self.assertEqual(sorted(nodes), [1, 2, 3, 4, 5, 6, 7])
github google / importlab / tests / test_graph.py View on Github external
def test_flatten(self):
        a = graph.Cycle([[1, 2], [2, 3], [3, 1]])
        b = graph.Cycle([[4, 5], [5, 4]])
        c = graph.Cycle([[a, 6], [6, b], [b, 7], [7, a]])
        nodes = c.flatten_nodes()
        self.assertEqual(sorted(nodes), [1, 2, 3, 4, 5, 6, 7])
github google / importlab / tests / test_graph.py View on Github external
def test_flatten(self):
        a = graph.Cycle([[1, 2], [2, 3], [3, 1]])
        b = graph.Cycle([[4, 5], [5, 4]])
        c = graph.Cycle([[a, 6], [6, b], [b, 7], [7, a]])
        nodes = c.flatten_nodes()
        self.assertEqual(sorted(nodes), [1, 2, 3, 4, 5, 6, 7])
github google / importlab / importlab / graph.py View on Github external
def build(self):
        """Finalise the graph, after adding all input files to it."""

        assert not self.final, 'Trying to mutate a final graph.'

        # Recursively extract cycles until the graph is cycle-free.
        while True:
            try:
                cycle = Cycle(nx.find_cycle(self.graph))
                self.extract_cycle(cycle)
            except nx.NetworkXNoCycle:
                break

        # Now that we have reduced the graph to a tree, we can flatten cycle
        # nodes into NodeSets
        def transform_node(node):
            if isinstance(node, Cycle):
                return NodeSet(node)
            else:
                return node
        self.graph = nx.relabel_nodes(self.graph, transform_node)
        self.final = True
github google / importlab / importlab / graph.py View on Github external
def transform_node(node):
            if isinstance(node, Cycle):
                return NodeSet(node)
            else:
                return node
        self.graph = nx.relabel_nodes(self.graph, transform_node)