Skip to content

Commit

Permalink
Merge pull request #2035 from TomHortons/master
Browse files Browse the repository at this point in the history
pipeline: show: dot: print dot
  • Loading branch information
efiop committed May 22, 2019
2 parents 3e461f8 + d9a79ce commit 6569657
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 76 deletions.
18 changes: 11 additions & 7 deletions dvc/command/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def _show_dependencies_tree(self, target, commands, outs):
observe_list.pop(0)
tree.show()

def __write_dot(self, target, commands, outs, filename):
def __write_dot(self, target, commands, outs):
from dvc.utils.compat import StringIO
import networkx
from networkx.drawing.nx_pydot import write_dot

Expand All @@ -124,7 +125,10 @@ def __write_dot(self, target, commands, outs, filename):

simple_g = networkx.DiGraph()
simple_g.add_edges_from(edges)
write_dot(simple_g, filename)

dot_file = StringIO()
write_dot(simple_g, dot_file)
logger.info(dot_file.getvalue())

def run(self):
if not self.args.targets:
Expand All @@ -138,10 +142,7 @@ def run(self):
)
elif self.args.dot:
self.__write_dot(
target,
self.args.commands,
self.args.outs,
self.args.dot,
target, self.args.commands, self.args.outs
)
elif self.args.tree:
self._show_dependencies_tree(
Expand Down Expand Up @@ -231,7 +232,10 @@ def add_parser(subparsers, parent_parser):
help="Output DAG as ASCII.",
)
pipeline_show_parser.add_argument(
"--dot", help="Write DAG in .dot format."
"--dot",
action="store_true",
default=False,
help="Print DAG with .dot format.",
)
pipeline_show_parser.add_argument(
"--tree",
Expand Down
78 changes: 9 additions & 69 deletions tests/func/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

from tests.basic_env import TestDvc
from tests.func.test_repro import TestRepro, TestReproChangedDeepData
import os


class TestPipelineShowSingle(TestDvc):
def setUp(self):
super(TestPipelineShowSingle, self).setUp()
self.stage = "foo.dvc"
self.dotFile = "graph.dot"
ret = main(["add", self.FOO])
self.assertEqual(ret, 0)

Expand All @@ -32,9 +30,8 @@ def test_ascii(self):
self.assertEqual(ret, 0)

def test_dot(self):
ret = main(["pipeline", "show", "--dot", self.dotFile, self.stage])
ret = main(["pipeline", "show", "--dot", self.stage])
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(self.dotFile))

def test_tree(self):
ret = main(["pipeline", "show", "--tree", self.stage])
Expand All @@ -49,25 +46,12 @@ def test_ascii_outs(self):
self.assertEqual(ret, 0)

def test_dot_commands(self):
ret = main(
[
"pipeline",
"show",
"--dot",
self.dotFile,
self.stage,
"--commands",
]
)
ret = main(["pipeline", "show", "--dot", self.stage, "--commands"])
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(self.dotFile))

def test_dot_outs(self):
ret = main(
["pipeline", "show", "--dot", self.dotFile, self.stage, "--outs"]
)
ret = main(["pipeline", "show", "--dot", self.stage, "--outs"])
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(self.dotFile))

def test_not_dvc_file(self):
ret = main(["pipeline", "show", self.FOO])
Expand All @@ -81,7 +65,6 @@ def test_non_existing(self):
class TestPipelineShow(TestRepro):
def setUp(self):
super(TestPipelineShow, self).setUp()
self.dotFile = "graph.dot"

def test(self):
ret = main(["pipeline", "show", self.file1_stage])
Expand All @@ -100,11 +83,8 @@ def test_ascii(self):
self.assertEqual(ret, 0)

def test_dot(self):
ret = main(
["pipeline", "show", "--dot", self.dotFile, self.file1_stage]
)
ret = main(["pipeline", "show", "--dot", self.file1_stage])
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(self.dotFile))

def test_ascii_commands(self):
ret = main(
Expand All @@ -118,31 +98,13 @@ def test_ascii_outs(self):

def test_dot_commands(self):
ret = main(
[
"pipeline",
"show",
"--dot",
self.dotFile,
self.file1_stage,
"--commands",
]
["pipeline", "show", "--dot", self.file1_stage, "--commands"]
)
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(self.dotFile))

def test_dot_outs(self):
ret = main(
[
"pipeline",
"show",
"--dot",
self.dotFile,
self.file1_stage,
"--outs",
]
)
ret = main(["pipeline", "show", "--dot", self.file1_stage, "--outs"])
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(self.dotFile))

def test_not_dvc_file(self):
ret = main(["pipeline", "show", self.file1])
Expand All @@ -169,7 +131,6 @@ def test_print_locked_stages(self):
class TestPipelineShowDeep(TestReproChangedDeepData):
def setUp(self):
super(TestPipelineShowDeep, self).setUp()
self.dotFile = "graph.dot"

def test(self):
ret = main(["pipeline", "show", self.file1_stage])
Expand All @@ -188,11 +149,8 @@ def test_ascii(self):
self.assertEqual(ret, 0)

def test_dot(self):
ret = main(
["pipeline", "show", "--dot", self.dotFile, self.file1_stage]
)
ret = main(["pipeline", "show", "--dot", self.file1_stage])
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(self.dotFile))

def test_ascii_commands(self):
ret = main(
Expand All @@ -206,31 +164,13 @@ def test_ascii_outs(self):

def test_dot_commands(self):
ret = main(
[
"pipeline",
"show",
"--dot",
self.dotFile,
self.file1_stage,
"--commands",
]
["pipeline", "show", "--dot", self.file1_stage, "--commands"]
)
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(self.dotFile))

def test_dot_outs(self):
ret = main(
[
"pipeline",
"show",
"--dot",
self.dotFile,
self.file1_stage,
"--outs",
]
)
ret = main(["pipeline", "show", "--dot", self.file1_stage, "--outs"])
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(self.dotFile))

def test_not_dvc_file(self):
ret = main(["pipeline", "show", self.file1])
Expand Down

0 comments on commit 6569657

Please sign in to comment.