From ddaa95d11b650000e30da2b621c0a18fa88941b4 Mon Sep 17 00:00:00 2001 From: Sebastian Bank Date: Wed, 27 Apr 2016 10:01:04 +0200 Subject: [PATCH] move rendered filename prediction to command --- .gitattributes | 1 + graphviz/backend.py | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..3ae87b238e --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.ipynb text eol=lf diff --git a/graphviz/backend.py b/graphviz/backend.py index df6e66d6e5..3f92a6dd3d 100644 --- a/graphviz/backend.py +++ b/graphviz/backend.py @@ -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): @@ -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) @@ -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,