Skip to content

Commit

Permalink
issue#174 lib directory overwritten when lib directory exists. The on…
Browse files Browse the repository at this point in the history
…ly situation where there needs to be a lib directory in the root of the local deployment is when pyvis is generating the html

for a notebook and the notebook is serving the contents locally. This was some legacy code that was not as thouroughly checked when the last deployment went live and because of how it was coded
the lib directory would get overwritten only when there was already a lib directory present.
  • Loading branch information
BerserkerGaruk committed Nov 2, 2022
1 parent 05a2281 commit 58f8ecb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pyvis/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,18 @@ def write_html(self, name, local=True, notebook=False):
out.write(self.html)

if notebook:
if os.path.exists("lib"):
shutil.rmtree(f"lib")
shutil.copytree(f"{os.path.dirname(__file__)}/templates/lib", "lib")
with open(name, "w+") as out:
out.write(self.html)
return IFrame(name, width=self.width, height=self.height)
elif notebook and local:
if not os.path.exists("lib"):
os.makedirs(os.path.dirname("lib"))
if not os.path.exists("lib/bindings"):
shutil.copytree(f"{os.path.dirname(__file__)}/templates/lib/bindings", "lib/bindings")
if not os.path.exists("lib/tom-select"):
shutil.copytree(f"{os.path.dirname(__file__)}/templates/lib/tom-select", "lib/tom-select")
if not os.path.exists("lib/bindings"):
shutil.copytree(f"{os.path.dirname(__file__)}/templates/lib/vis-9.1.2", "lib/vis-9.1.2")
with open(name, "w+") as out:
out.write(self.html)
return IFrame(name, width=self.width, height=self.height)
Expand Down
1 change: 1 addition & 0 deletions pyvis/templates/lib/vis-9.1.2/vis-network.css

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions pyvis/templates/lib/vis-9.1.2/vis-network.min.js

Large diffs are not rendered by default.

0 comments on commit 58f8ecb

Please sign in to comment.