提交 d8b8a536 authored 作者: Christof Angermueller's avatar Christof Angermueller

Copy dependecies to output directory by default

上级 a6635704
...@@ -5,6 +5,7 @@ Author: Christof Angermueller <cangermueller@gmail.com> ...@@ -5,6 +5,7 @@ Author: Christof Angermueller <cangermueller@gmail.com>
import os import os
import os.path as pt import os.path as pt
import shutil
from formatting import PyDotFormatter from formatting import PyDotFormatter
...@@ -25,14 +26,14 @@ def d3write(fct, path, *args, **kwargs): ...@@ -25,14 +26,14 @@ def d3write(fct, path, *args, **kwargs):
g.write_dot(path) g.write_dot(path)
def d3viz(fct, outfile, *args, **kwargs): def d3viz(fct, outfile, copy_deps=True, *args, **kwargs):
"""Create HTML file with dynamic visualizing of a Theano function graph. """Create HTML file with dynamic visualizing of a Theano function graph.
:param fct: A compiled Theano function, variable, apply or a list of :param fct: A compiled Theano function, variable, apply or a list of
variables. variables.
:param outfile: The output HTML file :param outfile: The output HTML file.
:param compact=False: if True, will remove intermediate variables without :param copy_deps: Copy javascript and CSS dependencies to output directory.
name. :param *args, **kwargs: Arguments passed to PyDotFormatter.
In the HTML file, the whole graph or single nodes can be moved by drag and In the HTML file, the whole graph or single nodes can be moved by drag and
drop. Zooming is possible via the mouse wheel. Detailed information about drop. Zooming is possible via the mouse wheel. Detailed information about
...@@ -63,10 +64,20 @@ def d3viz(fct, outfile, *args, **kwargs): ...@@ -63,10 +64,20 @@ def d3viz(fct, outfile, *args, **kwargs):
template = f.read() template = f.read()
f.close() f.close()
src_deps = __path__
if copy_deps:
dst_deps = 'd3viz'
for d in ['js', 'css']:
dep = pt.join(outdir, dst_deps, d)
if not pt.exists(dep):
shutil.copytree(pt.join(src_deps, d), dep)
else:
dst_deps = src_deps
# Replace patterns in template # Replace patterns in template
replace = { replace = {
'%% JS_DIR %%': pt.join(__path__, 'js'), '%% JS_DIR %%': pt.join(dst_deps, 'js'),
'%% CSS_DIR %%': pt.join(__path__, 'css'), '%% CSS_DIR %%': pt.join(dst_deps, 'css'),
'%% DOT_FILE %%': pt.basename(dot_file), '%% DOT_FILE %%': pt.basename(dot_file),
} }
html = replace_patterns(template, replace) html = replace_patterns(template, replace)
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
<head> <head>
<link rel="stylesheet" href="%% CSS_DIR %%/d3viz.css"/> <link rel="stylesheet" href="%% CSS_DIR %%/d3viz.css"/>
<link rel="stylesheet" href="%% CSS_DIR %%/d3-context-menu.css"/> <link rel="stylesheet" href="%% CSS_DIR %%/d3-context-menu.css"/>
<script type='text/javascript' src="%% JS_DIR %%/d3viz.js"></script> <script type="text/javascript" src="%% JS_DIR %%/d3viz.js"></script>
<script type="text/javascript" src="%% JS_DIR %%/d3.v3.min.js"></script> <script type="text/javascript" src="%% JS_DIR %%/d3.v3.min.js"></script>
<script type='text/javascript' src="%% JS_DIR %%/dagre-d3.js"></script> <script type="text/javascript" src="%% JS_DIR %%/dagre-d3.js"></script>
<script type='text/javascript' src="%% JS_DIR %%/graphlib-dot.js"></script> <script type="text/javascript" src="%% JS_DIR %%/graphlib-dot.js"></script>
<script type='text/javascript' src="%% JS_DIR %%/d3-context-menu.js"></script> <script type="text/javascript" src="%% JS_DIR %%/d3-context-menu.js"></script>
</head> </head>
<body> <body>
<div id='menu' class='menuBar'> <div id='menu' class='menuBar'>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论