Skip to content

Commit

Permalink
move rendered filename prediction to command
Browse files Browse the repository at this point in the history
  • Loading branch information
xflr6 committed Apr 27, 2016
1 parent a91b5c6 commit ddaa95d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.ipynb text eol=lf
14 changes: 7 additions & 7 deletions graphviz/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,18 @@


def command(engine, format, filepath=None):
"""Return args list for rendering using subprocess.Popen."""
"""Return args list for subprocess.Popen and name of the rendered file."""
if engine not in ENGINES:
raise ValueError('unknown engine: %r' % engine)
if format not in FORMATS:
raise ValueError('unknown format: %r' % format)

result = [engine, '-T%s' % format]
args, rendered = [engine, '-T%s' % format], None
if filepath is not None:
result.extend(['-O', filepath])
args.extend(['-O', filepath])
rendered = '%s.%s' % (filepath, format)

return result
return args, rendered


def render(engine, format, filepath):
Expand All @@ -86,8 +87,7 @@ def render(engine, format, filepath):
Raises:
RuntimeError: If the Graphviz executable is not found.
"""
args = command(engine, format, filepath)
rendered = '%s.%s' % (filepath, format)
args, rendered = command(engine, format, filepath)

try:
proc = subprocess.Popen(args, startupinfo=STARTUPINFO)
Expand Down Expand Up @@ -116,7 +116,7 @@ def pipe(engine, format, data):
Raises:
RuntimeError: If the Graphviz executable is not found.
"""
args = command(engine, format)
args, _ = command(engine, format)

try:
proc = subprocess.Popen(args, stdin=subprocess.PIPE,
Expand Down

0 comments on commit ddaa95d

Please sign in to comment.