We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
add `pipeline show --tree`
Unfold dependencies into a tree same way it is done in npm:

```
│ │ │   └── ms@2.0.0
  │ │ ├── lru-cache@4.1.1 deduped
  │ │ ├── mississippi@1.3.0 deduped
  │ │ ├─┬ node-fetch-npm@2.0.2
  │ │ │ ├─┬ encoding@0.1.12
  │ │ │ │ └── iconv-lite@0.4.19
  │ │ │ ├── json-parse-better-errors@1.0.1
  │ │ │ └── safe-buffer@5.1.1 deduped
  │ │ ├── promise-retry@1.1.1 deduped
  │ │ ├─┬ socks-proxy-agent@3.0.1
  │ │ │ ├─┬ agent-base@4.1.2
  │ │ │ │ └─┬ es6-promisify@5.0.0
  │ │ │ │   └── es6-promise@4.1.1
  │ │ │ └─┬ socks@1.1.10
  │ │ │   ├── ip@1.1.5
  │ │ │   └── smart-buffer@1.1.15
  │ │ └── ssri@5.0.0 deduped
  │ ├─┬ minimatch@3.0.4
```

Kudos @shcheklein 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `dvc/command/pipeline.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 from dvc.utils.compat import str
4 
5 import os
6 
7 import dvc.logger as logger
8 from dvc.exceptions import DvcException
9 from dvc.command.base import CmdBase, fix_subparsers
10 
11 
12 class CmdPipelineShow(CmdBase):
13     def _show(self, target, commands, outs):
14         import networkx
15         from dvc.stage import Stage
16 
17         stage = Stage.load(self.repo, target)
18         G = self.repo.graph()[0]
19         stages = networkx.get_node_attributes(G, "stage")
20         node = os.path.relpath(stage.path, self.repo.root_dir)
21 
22         for n in networkx.dfs_postorder_nodes(G, node):
23             if commands:
24                 logger.info(stages[n].cmd)
25             elif outs:
26                 for out in stages[n].outs:
27                     logger.info(str(out))
28             else:
29                 logger.info(n)
30 
31     def __build_graph(self, target, commands, outs):
32         import networkx
33         from dvc.stage import Stage
34 
35         stage = Stage.load(self.repo, target)
36         node = os.path.relpath(stage.path, self.repo.root_dir)
37 
38         pipelines = list(
39             filter(lambda g: node in g.nodes(), self.repo.pipelines())
40         )
41 
42         assert len(pipelines) == 1
43         G = pipelines[0]
44         stages = networkx.get_node_attributes(G, "stage")
45 
46         nodes = []
47         for n in G.nodes():
48             stage = stages[n]
49             if commands:
50                 if stage.cmd is None:
51                     continue
52                 nodes.append(stage.cmd)
53             elif outs:
54                 for out in stage.outs:
55                     nodes.append(str(out))
56             else:
57                 nodes.append(stage.relpath)
58 
59         edges = []
60         for e in G.edges():
61             from_stage = stages[e[0]]
62             to_stage = stages[e[1]]
63             if commands:
64                 if to_stage.cmd is None:
65                     continue
66                 edges.append((from_stage.cmd, to_stage.cmd))
67             elif outs:
68                 for from_out in from_stage.outs:
69                     for to_out in to_stage.outs:
70                         edges.append((str(from_out), str(to_out)))
71             else:
72                 edges.append((from_stage.relpath, to_stage.relpath))
73 
74         return nodes, edges
75 
76     def _show_ascii(self, target, commands, outs):
77         from dvc.dagascii import draw
78 
79         nodes, edges = self.__build_graph(target, commands, outs)
80 
81         if not nodes:
82             return
83 
84         draw(nodes, edges)
85 
86     def __write_dot(self, target, commands, outs, filename):
87         import networkx
88         from networkx.drawing.nx_pydot import write_dot
89 
90         _, edges = self.__build_graph(target, commands, outs)
91         edges = [edge[::-1] for edge in edges]
92 
93         simple_g = networkx.DiGraph()
94         simple_g.add_edges_from(edges)
95         write_dot(simple_g, filename)
96 
97     def run(self, unlock=False):
98         if not self.args.targets:
99             self.args.targets = self.default_targets
100 
101         for target in self.args.targets:
102             try:
103                 if self.args.ascii:
104                     self._show_ascii(
105                         target, self.args.commands, self.args.outs
106                     )
107                 elif self.args.dot:
108                     self.__write_dot(
109                         target,
110                         self.args.commands,
111                         self.args.outs,
112                         self.args.dot,
113                     )
114                 else:
115                     self._show(target, self.args.commands, self.args.outs)
116             except DvcException:
117                 msg = "failed to show pipeline for '{}'".format(target)
118                 logger.error(msg)
119                 return 1
120         return 0
121 
122 
123 class CmdPipelineList(CmdBase):
124     def run(self):
125         import networkx
126 
127         pipelines = self.repo.pipelines()
128         for p in pipelines:
129             stages = networkx.get_node_attributes(p, "stage")
130             for stage in stages:
131                 logger.info(stage)
132             if len(stages) != 0:
133                 logger.info("=" * 80)
134         logger.info("{} pipeline(s) total".format(len(pipelines)))
135 
136         return 0
137 
138 
139 def add_parser(subparsers, parent_parser):
140     PIPELINE_HELP = (
141         "Manage pipeline.\ndocumentation: https://man.dvc.org/pipeline"
142     )
143     pipeline_parser = subparsers.add_parser(
144         "pipeline",
145         parents=[parent_parser],
146         description=PIPELINE_HELP,
147         help=PIPELINE_HELP,
148     )
149 
150     pipeline_subparsers = pipeline_parser.add_subparsers(
151         dest="cmd",
152         help="Use dvc pipeline CMD --help for command-specific help.",
153     )
154 
155     fix_subparsers(pipeline_subparsers)
156 
157     PIPELINE_SHOW_HELP = "Show pipeline."
158     pipeline_show_parser = pipeline_subparsers.add_parser(
159         "show",
160         parents=[parent_parser],
161         description=PIPELINE_SHOW_HELP,
162         help=PIPELINE_SHOW_HELP,
163     )
164     pipeline_show_group = pipeline_show_parser.add_mutually_exclusive_group()
165     pipeline_show_group.add_argument(
166         "-c",
167         "--commands",
168         action="store_true",
169         default=False,
170         help="Print commands instead of paths to DVC files.",
171     )
172     pipeline_show_group.add_argument(
173         "-o",
174         "--outs",
175         action="store_true",
176         default=False,
177         help="Print output files instead of paths to DVC files.",
178     )
179     pipeline_show_parser.add_argument(
180         "--ascii",
181         action="store_true",
182         default=False,
183         help="Output DAG as ASCII.",
184     )
185     pipeline_show_parser.add_argument(
186         "--dot", help="Write DAG in .dot format."
187     )
188     pipeline_show_parser.add_argument(
189         "targets", nargs="*", help="DVC files. 'Dvcfile' by default."
190     )
191     pipeline_show_parser.set_defaults(func=CmdPipelineShow)
192 
193     PIPELINE_LIST_HELP = "List pipelines."
194     pipeline_list_parser = pipeline_subparsers.add_parser(
195         "list",
196         parents=[parent_parser],
197         description=PIPELINE_LIST_HELP,
198         help=PIPELINE_LIST_HELP,
199     )
200     pipeline_list_parser.set_defaults(func=CmdPipelineList)
201
```

Path: `setup.py`
Content:
```
1 from setuptools import setup, find_packages
2 from dvc import VERSION
3 
4 
5 install_requires = [
6     "ply>=3.9",  # See https://github.com/pyinstaller/pyinstaller/issues/1945
7     "configparser>=3.5.0",
8     "zc.lockfile>=1.2.1",
9     "future>=0.16.0",
10     "colorama>=0.3.9",
11     "configobj>=5.0.6",
12     "networkx>=2.1",
13     "pyyaml>=3.12",
14     "gitpython>=2.1.8",
15     "setuptools>=34.0.0",
16     "nanotime>=0.5.2",
17     "pyasn1>=0.4.1",
18     "schema>=0.6.7",
19     "jsonpath-rw==1.4.0",
20     "requests>=2.18.4",
21     "grandalf==0.6",
22     "asciimatics>=1.10.0",
23     "distro>=1.3.0",
24     "appdirs>=1.4.3",
25 ]
26 
27 # Extra dependencies for remote integrations
28 gs = ["google-cloud-storage==1.13.0"]
29 s3 = ["boto3==1.9.115"]
30 azure = ["azure-storage-blob==1.3.0"]
31 ssh = ["paramiko>=2.4.1"]
32 all_remotes = gs + s3 + azure + ssh
33 
34 setup(
35     name="dvc",
36     version=VERSION,
37     description="Git for data scientists - manage your code and data together",
38     long_description=open("README.rst", "r").read(),
39     author="Dmitry Petrov",
40     author_email="dmitry@dataversioncontrol.com",
41     download_url="https://github.com/iterative/dvc",
42     license="Apache License 2.0",
43     install_requires=install_requires,
44     extras_require={
45         "all": all_remotes,
46         "gs": gs,
47         "s3": s3,
48         "azure": azure,
49         "ssh": ssh,
50         # NOTE: https://github.com/inveniosoftware/troubleshooting/issues/1
51         ':python_version=="2.7"': ["futures"],
52     },
53     keywords="data science, data version control, machine learning",
54     classifiers=[
55         "Development Status :: 4 - Beta",
56         "Programming Language :: Python :: 2",
57         "Programming Language :: Python :: 3",
58     ],
59     packages=find_packages(exclude=["tests"]),
60     include_package_data=True,
61     url="http://dataversioncontrol.com",
62     entry_points={"console_scripts": ["dvc = dvc.main:main"]},
63     zip_safe=False,
64 )
65
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/dvc/command/pipeline.py b/dvc/command/pipeline.py
--- a/dvc/command/pipeline.py
+++ b/dvc/command/pipeline.py
@@ -71,23 +71,47 @@
             else:
                 edges.append((from_stage.relpath, to_stage.relpath))
 
-        return nodes, edges
+        return nodes, edges, networkx.is_tree(G)
 
     def _show_ascii(self, target, commands, outs):
         from dvc.dagascii import draw
 
-        nodes, edges = self.__build_graph(target, commands, outs)
+        nodes, edges, _ = self.__build_graph(target, commands, outs)
 
         if not nodes:
             return
 
         draw(nodes, edges)
 
+    def _show_dependencies_tree(self, target, commands, outs):
+        from treelib import Tree
+
+        nodes, edges, is_tree = self.__build_graph(target, commands, outs)
+        if not nodes:
+            return
+        if not is_tree:
+            raise DvcException(
+                "DAG is not a tree, can not print it in tree-structure way, "
+                "please use --ascii instead"
+            )
+
+        tree = Tree()
+        tree.create_node(target, target)  # Root node
+        observe_list = [target]
+        while len(observe_list) > 0:
+            current_root = observe_list[0]
+            for edge in edges:
+                if edge[0] == current_root:
+                    tree.create_node(edge[1], edge[1], parent=current_root)
+                    observe_list.append(edge[1])
+            observe_list.pop(0)
+        tree.show()
+
     def __write_dot(self, target, commands, outs, filename):
         import networkx
         from networkx.drawing.nx_pydot import write_dot
 
-        _, edges = self.__build_graph(target, commands, outs)
+        _, edges, _ = self.__build_graph(target, commands, outs)
         edges = [edge[::-1] for edge in edges]
 
         simple_g = networkx.DiGraph()
@@ -111,6 +135,10 @@
                         self.args.outs,
                         self.args.dot,
                     )
+                elif self.args.tree:
+                    self._show_dependencies_tree(
+                        target, self.args.commands, self.args.outs
+                    )
                 else:
                     self._show(target, self.args.commands, self.args.outs)
             except DvcException:
@@ -185,6 +213,12 @@
     pipeline_show_parser.add_argument(
         "--dot", help="Write DAG in .dot format."
     )
+    pipeline_show_parser.add_argument(
+        "--tree",
+        action="store_true",
+        default=False,
+        help="Output DAG as Dependencies Tree.",
+    )
     pipeline_show_parser.add_argument(
         "targets", nargs="*", help="DVC files. 'Dvcfile' by default."
     )
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -22,6 +22,7 @@
     "asciimatics>=1.10.0",
     "distro>=1.3.0",
     "appdirs>=1.4.3",
+    "treelib>=1.5.5",
 ]
 
 # Extra dependencies for remote integrations

{"golden_diff": "diff --git a/dvc/command/pipeline.py b/dvc/command/pipeline.py\n--- a/dvc/command/pipeline.py\n+++ b/dvc/command/pipeline.py\n@@ -71,23 +71,47 @@\n             else:\n                 edges.append((from_stage.relpath, to_stage.relpath))\n \n-        return nodes, edges\n+        return nodes, edges, networkx.is_tree(G)\n \n     def _show_ascii(self, target, commands, outs):\n         from dvc.dagascii import draw\n \n-        nodes, edges = self.__build_graph(target, commands, outs)\n+        nodes, edges, _ = self.__build_graph(target, commands, outs)\n \n         if not nodes:\n             return\n \n         draw(nodes, edges)\n \n+    def _show_dependencies_tree(self, target, commands, outs):\n+        from treelib import Tree\n+\n+        nodes, edges, is_tree = self.__build_graph(target, commands, outs)\n+        if not nodes:\n+            return\n+        if not is_tree:\n+            raise DvcException(\n+                \"DAG is not a tree, can not print it in tree-structure way, \"\n+                \"please use --ascii instead\"\n+            )\n+\n+        tree = Tree()\n+        tree.create_node(target, target)  # Root node\n+        observe_list = [target]\n+        while len(observe_list) > 0:\n+            current_root = observe_list[0]\n+            for edge in edges:\n+                if edge[0] == current_root:\n+                    tree.create_node(edge[1], edge[1], parent=current_root)\n+                    observe_list.append(edge[1])\n+            observe_list.pop(0)\n+        tree.show()\n+\n     def __write_dot(self, target, commands, outs, filename):\n         import networkx\n         from networkx.drawing.nx_pydot import write_dot\n \n-        _, edges = self.__build_graph(target, commands, outs)\n+        _, edges, _ = self.__build_graph(target, commands, outs)\n         edges = [edge[::-1] for edge in edges]\n \n         simple_g = networkx.DiGraph()\n@@ -111,6 +135,10 @@\n                         self.args.outs,\n                         self.args.dot,\n                     )\n+                elif self.args.tree:\n+                    self._show_dependencies_tree(\n+                        target, self.args.commands, self.args.outs\n+                    )\n                 else:\n                     self._show(target, self.args.commands, self.args.outs)\n             except DvcException:\n@@ -185,6 +213,12 @@\n     pipeline_show_parser.add_argument(\n         \"--dot\", help=\"Write DAG in .dot format.\"\n     )\n+    pipeline_show_parser.add_argument(\n+        \"--tree\",\n+        action=\"store_true\",\n+        default=False,\n+        help=\"Output DAG as Dependencies Tree.\",\n+    )\n     pipeline_show_parser.add_argument(\n         \"targets\", nargs=\"*\", help=\"DVC files. 'Dvcfile' by default.\"\n     )\ndiff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -22,6 +22,7 @@\n     \"asciimatics>=1.10.0\",\n     \"distro>=1.3.0\",\n     \"appdirs>=1.4.3\",\n+    \"treelib>=1.5.5\",\n ]\n \n # Extra dependencies for remote integrations\n", "issue": "add `pipeline show --tree`\nUnfold dependencies into a tree same way it is done in npm:\r\n\r\n```\r\n\u2502 \u2502 \u2502   \u2514\u2500\u2500 ms@2.0.0\r\n  \u2502 \u2502 \u251c\u2500\u2500 lru-cache@4.1.1 deduped\r\n  \u2502 \u2502 \u251c\u2500\u2500 mississippi@1.3.0 deduped\r\n  \u2502 \u2502 \u251c\u2500\u252c node-fetch-npm@2.0.2\r\n  \u2502 \u2502 \u2502 \u251c\u2500\u252c encoding@0.1.12\r\n  \u2502 \u2502 \u2502 \u2502 \u2514\u2500\u2500 iconv-lite@0.4.19\r\n  \u2502 \u2502 \u2502 \u251c\u2500\u2500 json-parse-better-errors@1.0.1\r\n  \u2502 \u2502 \u2502 \u2514\u2500\u2500 safe-buffer@5.1.1 deduped\r\n  \u2502 \u2502 \u251c\u2500\u2500 promise-retry@1.1.1 deduped\r\n  \u2502 \u2502 \u251c\u2500\u252c socks-proxy-agent@3.0.1\r\n  \u2502 \u2502 \u2502 \u251c\u2500\u252c agent-base@4.1.2\r\n  \u2502 \u2502 \u2502 \u2502 \u2514\u2500\u252c es6-promisify@5.0.0\r\n  \u2502 \u2502 \u2502 \u2502   \u2514\u2500\u2500 es6-promise@4.1.1\r\n  \u2502 \u2502 \u2502 \u2514\u2500\u252c socks@1.1.10\r\n  \u2502 \u2502 \u2502   \u251c\u2500\u2500 ip@1.1.5\r\n  \u2502 \u2502 \u2502   \u2514\u2500\u2500 smart-buffer@1.1.15\r\n  \u2502 \u2502 \u2514\u2500\u2500 ssri@5.0.0 deduped\r\n  \u2502 \u251c\u2500\u252c minimatch@3.0.4\r\n```\r\n\r\nKudos @shcheklein \n", "before_files": [{"content": "from __future__ import unicode_literals\n\nfrom dvc.utils.compat import str\n\nimport os\n\nimport dvc.logger as logger\nfrom dvc.exceptions import DvcException\nfrom dvc.command.base import CmdBase, fix_subparsers\n\n\nclass CmdPipelineShow(CmdBase):\n    def _show(self, target, commands, outs):\n        import networkx\n        from dvc.stage import Stage\n\n        stage = Stage.load(self.repo, target)\n        G = self.repo.graph()[0]\n        stages = networkx.get_node_attributes(G, \"stage\")\n        node = os.path.relpath(stage.path, self.repo.root_dir)\n\n        for n in networkx.dfs_postorder_nodes(G, node):\n            if commands:\n                logger.info(stages[n].cmd)\n            elif outs:\n                for out in stages[n].outs:\n                    logger.info(str(out))\n            else:\n                logger.info(n)\n\n    def __build_graph(self, target, commands, outs):\n        import networkx\n        from dvc.stage import Stage\n\n        stage = Stage.load(self.repo, target)\n        node = os.path.relpath(stage.path, self.repo.root_dir)\n\n        pipelines = list(\n            filter(lambda g: node in g.nodes(), self.repo.pipelines())\n        )\n\n        assert len(pipelines) == 1\n        G = pipelines[0]\n        stages = networkx.get_node_attributes(G, \"stage\")\n\n        nodes = []\n        for n in G.nodes():\n            stage = stages[n]\n            if commands:\n                if stage.cmd is None:\n                    continue\n                nodes.append(stage.cmd)\n            elif outs:\n                for out in stage.outs:\n                    nodes.append(str(out))\n            else:\n                nodes.append(stage.relpath)\n\n        edges = []\n        for e in G.edges():\n            from_stage = stages[e[0]]\n            to_stage = stages[e[1]]\n            if commands:\n                if to_stage.cmd is None:\n                    continue\n                edges.append((from_stage.cmd, to_stage.cmd))\n            elif outs:\n                for from_out in from_stage.outs:\n                    for to_out in to_stage.outs:\n                        edges.append((str(from_out), str(to_out)))\n            else:\n                edges.append((from_stage.relpath, to_stage.relpath))\n\n        return nodes, edges\n\n    def _show_ascii(self, target, commands, outs):\n        from dvc.dagascii import draw\n\n        nodes, edges = self.__build_graph(target, commands, outs)\n\n        if not nodes:\n            return\n\n        draw(nodes, edges)\n\n    def __write_dot(self, target, commands, outs, filename):\n        import networkx\n        from networkx.drawing.nx_pydot import write_dot\n\n        _, edges = self.__build_graph(target, commands, outs)\n        edges = [edge[::-1] for edge in edges]\n\n        simple_g = networkx.DiGraph()\n        simple_g.add_edges_from(edges)\n        write_dot(simple_g, filename)\n\n    def run(self, unlock=False):\n        if not self.args.targets:\n            self.args.targets = self.default_targets\n\n        for target in self.args.targets:\n            try:\n                if self.args.ascii:\n                    self._show_ascii(\n                        target, self.args.commands, self.args.outs\n                    )\n                elif self.args.dot:\n                    self.__write_dot(\n                        target,\n                        self.args.commands,\n                        self.args.outs,\n                        self.args.dot,\n                    )\n                else:\n                    self._show(target, self.args.commands, self.args.outs)\n            except DvcException:\n                msg = \"failed to show pipeline for '{}'\".format(target)\n                logger.error(msg)\n                return 1\n        return 0\n\n\nclass CmdPipelineList(CmdBase):\n    def run(self):\n        import networkx\n\n        pipelines = self.repo.pipelines()\n        for p in pipelines:\n            stages = networkx.get_node_attributes(p, \"stage\")\n            for stage in stages:\n                logger.info(stage)\n            if len(stages) != 0:\n                logger.info(\"=\" * 80)\n        logger.info(\"{} pipeline(s) total\".format(len(pipelines)))\n\n        return 0\n\n\ndef add_parser(subparsers, parent_parser):\n    PIPELINE_HELP = (\n        \"Manage pipeline.\\ndocumentation: https://man.dvc.org/pipeline\"\n    )\n    pipeline_parser = subparsers.add_parser(\n        \"pipeline\",\n        parents=[parent_parser],\n        description=PIPELINE_HELP,\n        help=PIPELINE_HELP,\n    )\n\n    pipeline_subparsers = pipeline_parser.add_subparsers(\n        dest=\"cmd\",\n        help=\"Use dvc pipeline CMD --help for command-specific help.\",\n    )\n\n    fix_subparsers(pipeline_subparsers)\n\n    PIPELINE_SHOW_HELP = \"Show pipeline.\"\n    pipeline_show_parser = pipeline_subparsers.add_parser(\n        \"show\",\n        parents=[parent_parser],\n        description=PIPELINE_SHOW_HELP,\n        help=PIPELINE_SHOW_HELP,\n    )\n    pipeline_show_group = pipeline_show_parser.add_mutually_exclusive_group()\n    pipeline_show_group.add_argument(\n        \"-c\",\n        \"--commands\",\n        action=\"store_true\",\n        default=False,\n        help=\"Print commands instead of paths to DVC files.\",\n    )\n    pipeline_show_group.add_argument(\n        \"-o\",\n        \"--outs\",\n        action=\"store_true\",\n        default=False,\n        help=\"Print output files instead of paths to DVC files.\",\n    )\n    pipeline_show_parser.add_argument(\n        \"--ascii\",\n        action=\"store_true\",\n        default=False,\n        help=\"Output DAG as ASCII.\",\n    )\n    pipeline_show_parser.add_argument(\n        \"--dot\", help=\"Write DAG in .dot format.\"\n    )\n    pipeline_show_parser.add_argument(\n        \"targets\", nargs=\"*\", help=\"DVC files. 'Dvcfile' by default.\"\n    )\n    pipeline_show_parser.set_defaults(func=CmdPipelineShow)\n\n    PIPELINE_LIST_HELP = \"List pipelines.\"\n    pipeline_list_parser = pipeline_subparsers.add_parser(\n        \"list\",\n        parents=[parent_parser],\n        description=PIPELINE_LIST_HELP,\n        help=PIPELINE_LIST_HELP,\n    )\n    pipeline_list_parser.set_defaults(func=CmdPipelineList)\n", "path": "dvc/command/pipeline.py"}, {"content": "from setuptools import setup, find_packages\nfrom dvc import VERSION\n\n\ninstall_requires = [\n    \"ply>=3.9\",  # See https://github.com/pyinstaller/pyinstaller/issues/1945\n    \"configparser>=3.5.0\",\n    \"zc.lockfile>=1.2.1\",\n    \"future>=0.16.0\",\n    \"colorama>=0.3.9\",\n    \"configobj>=5.0.6\",\n    \"networkx>=2.1\",\n    \"pyyaml>=3.12\",\n    \"gitpython>=2.1.8\",\n    \"setuptools>=34.0.0\",\n    \"nanotime>=0.5.2\",\n    \"pyasn1>=0.4.1\",\n    \"schema>=0.6.7\",\n    \"jsonpath-rw==1.4.0\",\n    \"requests>=2.18.4\",\n    \"grandalf==0.6\",\n    \"asciimatics>=1.10.0\",\n    \"distro>=1.3.0\",\n    \"appdirs>=1.4.3\",\n]\n\n# Extra dependencies for remote integrations\ngs = [\"google-cloud-storage==1.13.0\"]\ns3 = [\"boto3==1.9.115\"]\nazure = [\"azure-storage-blob==1.3.0\"]\nssh = [\"paramiko>=2.4.1\"]\nall_remotes = gs + s3 + azure + ssh\n\nsetup(\n    name=\"dvc\",\n    version=VERSION,\n    description=\"Git for data scientists - manage your code and data together\",\n    long_description=open(\"README.rst\", \"r\").read(),\n    author=\"Dmitry Petrov\",\n    author_email=\"dmitry@dataversioncontrol.com\",\n    download_url=\"https://github.com/iterative/dvc\",\n    license=\"Apache License 2.0\",\n    install_requires=install_requires,\n    extras_require={\n        \"all\": all_remotes,\n        \"gs\": gs,\n        \"s3\": s3,\n        \"azure\": azure,\n        \"ssh\": ssh,\n        # NOTE: https://github.com/inveniosoftware/troubleshooting/issues/1\n        ':python_version==\"2.7\"': [\"futures\"],\n    },\n    keywords=\"data science, data version control, machine learning\",\n    classifiers=[\n        \"Development Status :: 4 - Beta\",\n        \"Programming Language :: Python :: 2\",\n        \"Programming Language :: Python :: 3\",\n    ],\n    packages=find_packages(exclude=[\"tests\"]),\n    include_package_data=True,\n    url=\"http://dataversioncontrol.com\",\n    entry_points={\"console_scripts\": [\"dvc = dvc.main:main\"]},\n    zip_safe=False,\n)\n", "path": "setup.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nfrom dvc.utils.compat import str\n\nimport os\n\nimport dvc.logger as logger\nfrom dvc.exceptions import DvcException\nfrom dvc.command.base import CmdBase, fix_subparsers\n\n\nclass CmdPipelineShow(CmdBase):\n    def _show(self, target, commands, outs):\n        import networkx\n        from dvc.stage import Stage\n\n        stage = Stage.load(self.repo, target)\n        G = self.repo.graph()[0]\n        stages = networkx.get_node_attributes(G, \"stage\")\n        node = os.path.relpath(stage.path, self.repo.root_dir)\n\n        for n in networkx.dfs_postorder_nodes(G, node):\n            if commands:\n                logger.info(stages[n].cmd)\n            elif outs:\n                for out in stages[n].outs:\n                    logger.info(str(out))\n            else:\n                logger.info(n)\n\n    def __build_graph(self, target, commands, outs):\n        import networkx\n        from dvc.stage import Stage\n\n        stage = Stage.load(self.repo, target)\n        node = os.path.relpath(stage.path, self.repo.root_dir)\n\n        pipelines = list(\n            filter(lambda g: node in g.nodes(), self.repo.pipelines())\n        )\n\n        assert len(pipelines) == 1\n        G = pipelines[0]\n        stages = networkx.get_node_attributes(G, \"stage\")\n\n        nodes = []\n        for n in G.nodes():\n            stage = stages[n]\n            if commands:\n                if stage.cmd is None:\n                    continue\n                nodes.append(stage.cmd)\n            elif outs:\n                for out in stage.outs:\n                    nodes.append(str(out))\n            else:\n                nodes.append(stage.relpath)\n\n        edges = []\n        for e in G.edges():\n            from_stage = stages[e[0]]\n            to_stage = stages[e[1]]\n            if commands:\n                if to_stage.cmd is None:\n                    continue\n                edges.append((from_stage.cmd, to_stage.cmd))\n            elif outs:\n                for from_out in from_stage.outs:\n                    for to_out in to_stage.outs:\n                        edges.append((str(from_out), str(to_out)))\n            else:\n                edges.append((from_stage.relpath, to_stage.relpath))\n\n        return nodes, edges, networkx.is_tree(G)\n\n    def _show_ascii(self, target, commands, outs):\n        from dvc.dagascii import draw\n\n        nodes, edges, _ = self.__build_graph(target, commands, outs)\n\n        if not nodes:\n            return\n\n        draw(nodes, edges)\n\n    def _show_dependencies_tree(self, target, commands, outs):\n        from treelib import Tree\n\n        nodes, edges, is_tree = self.__build_graph(target, commands, outs)\n        if not nodes:\n            return\n        if not is_tree:\n            raise DvcException(\n                \"DAG is not a tree, can not print it in tree-structure way, \"\n                \"please use --ascii instead\"\n            )\n\n        tree = Tree()\n        tree.create_node(target, target)  # Root node\n        observe_list = [target]\n        while len(observe_list) > 0:\n            current_root = observe_list[0]\n            for edge in edges:\n                if edge[0] == current_root:\n                    tree.create_node(edge[1], edge[1], parent=current_root)\n                    observe_list.append(edge[1])\n            observe_list.pop(0)\n        tree.show()\n\n    def __write_dot(self, target, commands, outs, filename):\n        import networkx\n        from networkx.drawing.nx_pydot import write_dot\n\n        _, edges, _ = self.__build_graph(target, commands, outs)\n        edges = [edge[::-1] for edge in edges]\n\n        simple_g = networkx.DiGraph()\n        simple_g.add_edges_from(edges)\n        write_dot(simple_g, filename)\n\n    def run(self, unlock=False):\n        if not self.args.targets:\n            self.args.targets = self.default_targets\n\n        for target in self.args.targets:\n            try:\n                if self.args.ascii:\n                    self._show_ascii(\n                        target, self.args.commands, self.args.outs\n                    )\n                elif self.args.dot:\n                    self.__write_dot(\n                        target,\n                        self.args.commands,\n                        self.args.outs,\n                        self.args.dot,\n                    )\n                elif self.args.tree:\n                    self._show_dependencies_tree(\n                        target, self.args.commands, self.args.outs\n                    )\n                else:\n                    self._show(target, self.args.commands, self.args.outs)\n            except DvcException:\n                msg = \"failed to show pipeline for '{}'\".format(target)\n                logger.error(msg)\n                return 1\n        return 0\n\n\nclass CmdPipelineList(CmdBase):\n    def run(self):\n        import networkx\n\n        pipelines = self.repo.pipelines()\n        for p in pipelines:\n            stages = networkx.get_node_attributes(p, \"stage\")\n            for stage in stages:\n                logger.info(stage)\n            if len(stages) != 0:\n                logger.info(\"=\" * 80)\n        logger.info(\"{} pipeline(s) total\".format(len(pipelines)))\n\n        return 0\n\n\ndef add_parser(subparsers, parent_parser):\n    PIPELINE_HELP = (\n        \"Manage pipeline.\\ndocumentation: https://man.dvc.org/pipeline\"\n    )\n    pipeline_parser = subparsers.add_parser(\n        \"pipeline\",\n        parents=[parent_parser],\n        description=PIPELINE_HELP,\n        help=PIPELINE_HELP,\n    )\n\n    pipeline_subparsers = pipeline_parser.add_subparsers(\n        dest=\"cmd\",\n        help=\"Use dvc pipeline CMD --help for command-specific help.\",\n    )\n\n    fix_subparsers(pipeline_subparsers)\n\n    PIPELINE_SHOW_HELP = \"Show pipeline.\"\n    pipeline_show_parser = pipeline_subparsers.add_parser(\n        \"show\",\n        parents=[parent_parser],\n        description=PIPELINE_SHOW_HELP,\n        help=PIPELINE_SHOW_HELP,\n    )\n    pipeline_show_group = pipeline_show_parser.add_mutually_exclusive_group()\n    pipeline_show_group.add_argument(\n        \"-c\",\n        \"--commands\",\n        action=\"store_true\",\n        default=False,\n        help=\"Print commands instead of paths to DVC files.\",\n    )\n    pipeline_show_group.add_argument(\n        \"-o\",\n        \"--outs\",\n        action=\"store_true\",\n        default=False,\n        help=\"Print output files instead of paths to DVC files.\",\n    )\n    pipeline_show_parser.add_argument(\n        \"--ascii\",\n        action=\"store_true\",\n        default=False,\n        help=\"Output DAG as ASCII.\",\n    )\n    pipeline_show_parser.add_argument(\n        \"--dot\", help=\"Write DAG in .dot format.\"\n    )\n    pipeline_show_parser.add_argument(\n        \"--tree\",\n        action=\"store_true\",\n        default=False,\n        help=\"Output DAG as Dependencies Tree.\",\n    )\n    pipeline_show_parser.add_argument(\n        \"targets\", nargs=\"*\", help=\"DVC files. 'Dvcfile' by default.\"\n    )\n    pipeline_show_parser.set_defaults(func=CmdPipelineShow)\n\n    PIPELINE_LIST_HELP = \"List pipelines.\"\n    pipeline_list_parser = pipeline_subparsers.add_parser(\n        \"list\",\n        parents=[parent_parser],\n        description=PIPELINE_LIST_HELP,\n        help=PIPELINE_LIST_HELP,\n    )\n    pipeline_list_parser.set_defaults(func=CmdPipelineList)\n", "path": "dvc/command/pipeline.py"}, {"content": "from setuptools import setup, find_packages\nfrom dvc import VERSION\n\n\ninstall_requires = [\n    \"ply>=3.9\",  # See https://github.com/pyinstaller/pyinstaller/issues/1945\n    \"configparser>=3.5.0\",\n    \"zc.lockfile>=1.2.1\",\n    \"future>=0.16.0\",\n    \"colorama>=0.3.9\",\n    \"configobj>=5.0.6\",\n    \"networkx>=2.1\",\n    \"pyyaml>=3.12\",\n    \"gitpython>=2.1.8\",\n    \"setuptools>=34.0.0\",\n    \"nanotime>=0.5.2\",\n    \"pyasn1>=0.4.1\",\n    \"schema>=0.6.7\",\n    \"jsonpath-rw==1.4.0\",\n    \"requests>=2.18.4\",\n    \"grandalf==0.6\",\n    \"asciimatics>=1.10.0\",\n    \"distro>=1.3.0\",\n    \"appdirs>=1.4.3\",\n    \"treelib>=1.5.5\",\n]\n\n# Extra dependencies for remote integrations\ngs = [\"google-cloud-storage==1.13.0\"]\ns3 = [\"boto3==1.9.115\"]\nazure = [\"azure-storage-blob==1.3.0\"]\nssh = [\"paramiko>=2.4.1\"]\nall_remotes = gs + s3 + azure + ssh\n\nsetup(\n    name=\"dvc\",\n    version=VERSION,\n    description=\"Git for data scientists - manage your code and data together\",\n    long_description=open(\"README.rst\", \"r\").read(),\n    author=\"Dmitry Petrov\",\n    author_email=\"dmitry@dataversioncontrol.com\",\n    download_url=\"https://github.com/iterative/dvc\",\n    license=\"Apache License 2.0\",\n    install_requires=install_requires,\n    extras_require={\n        \"all\": all_remotes,\n        \"gs\": gs,\n        \"s3\": s3,\n        \"azure\": azure,\n        \"ssh\": ssh,\n        # NOTE: https://github.com/inveniosoftware/troubleshooting/issues/1\n        ':python_version==\"2.7\"': [\"futures\"],\n    },\n    keywords=\"data science, data version control, machine learning\",\n    classifiers=[\n        \"Development Status :: 4 - Beta\",\n        \"Programming Language :: Python :: 2\",\n        \"Programming Language :: Python :: 3\",\n    ],\n    packages=find_packages(exclude=[\"tests\"]),\n    include_package_data=True,\n    url=\"http://dataversioncontrol.com\",\n    entry_points={\"console_scripts\": [\"dvc = dvc.main:main\"]},\n    zip_safe=False,\n)\n", "path": "setup.py"}]}