Esempio n. 1
0
    def _build_graph(self, target, commands=False, outs=False):
        import networkx
        from dvc import dvcfile
        from dvc.repo.graph import get_pipeline
        from dvc.utils import parse_target

        path, name = parse_target(target)
        target_stage = dvcfile.Dvcfile(self.repo, path).stages[name]
        G = get_pipeline(self.repo.pipelines, target_stage)

        nodes = set()
        for stage in networkx.dfs_preorder_nodes(G, target_stage):
            if commands:
                if stage.cmd is None:
                    continue
                nodes.add(stage.cmd)
            elif not outs:
                nodes.add(stage.addressing)

        edges = []
        for from_stage, to_stage in networkx.edge_dfs(G, target_stage):
            if commands:
                if to_stage.cmd is None:
                    continue
                edges.append((from_stage.cmd, to_stage.cmd))
            elif not outs:
                edges.append((from_stage.addressing, to_stage.addressing))

        if outs:
            nodes, edges = self._build_output_graph(G, target_stage)

        return list(nodes), edges, networkx.is_tree(G)
Esempio n. 2
0
    def _show(self, target, commands, outs, locked):
        import networkx
        from dvc import dvcfile
        from dvc.utils import parse_target

        path, name, tag = parse_target(target)
        stage = dvcfile.Dvcfile(self.repo, path, tag=tag).stages[name]
        G = self.repo.graph
        stages = networkx.dfs_postorder_nodes(G, stage)
        if locked:
            stages = [s for s in stages if s.locked]

        for stage in stages:
            if commands:
                if stage.cmd is None:
                    continue
                logger.info(stage.cmd)
            elif outs:
                for out in stage.outs:
                    logger.info(str(out))
            else:
                logger.info(stage.addressing)