Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: offline=True kwarg in embed_html was failing to save dependency jupyter-threejs.js #198

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
4 changes: 3 additions & 1 deletion ipyvolume/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
__version__ = '0.5.2-dev.1'
__version_tuple_js__ = (0, 5, 2, 'dev.1')
__version_js__ = '0.5.2-dev.1'
__version_threejs__ = '0.91' # kept for embedding in offline mode, we don't care about the patch version since it should be compatible
__version_threejs__ = '2.0.1'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

threejs is at version 98 btw: https://threejs.org/
pythreejs is what you meant, I know, it is confusing.
I'll talk with @vidartf about it, how we can get the right threejs version that matches the pythreejs one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I've updated the variable name to be clearer: __version_pythreejs__. The actual __version_threejs__ never got used (the master branch has some stuff commented out) so I haven't included that in _version.py

Yes, it would be good to know what you and @vidartf decide is the best way to keep threejs/pythreejs in sync.

__version_requirejs__ = '2.3.4'
__version_fontawesome__ = '4.7.0'
45 changes: 28 additions & 17 deletions ipyvolume/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

import ipyvolume
from ipyvolume.utils import download_to_file, download_to_bytes
from ipyvolume._version import __version_threejs__
from ipyvolume._version import (__version_js__,
__version_threejs__,
__version_requirejs__,
__version_fontawesome__)

html_template = u"""<!DOCTYPE html>
<html lang="en">
Expand All @@ -26,17 +29,14 @@


def save_ipyvolumejs(target="", devmode=False,
version=ipyvolume._version.__version_js__, version3js=__version_threejs__):
""" output the ipyvolume javascript to a local file
version=__version_js__):
"""Output the ipyvolume javascript to a local file.

:type target: str
:type devmode: bool
:param devmode: if True get index.js from js/dist directory
:type version: str
:param version: version number of ipyvolume
:type version3js: str
:param version3js: version number of threejs

"""
url = "https://unpkg.com/ipyvolume@{version}/dist/index.js".format(version=version)
pyv_filename = 'ipyvolume_v{version}.js'.format(version=version)
Expand All @@ -51,18 +51,10 @@ def save_ipyvolumejs(target="", devmode=False,
shutil.copy(devfile, pyv_filepath)
else:
download_to_file(url, pyv_filepath)
return pyv_filename

# TODO: currently not in use, think about this if we want to have this external for embedding,
# see also https://github.com/jovyan/pythreejs/issues/109
# three_filename = 'three_v{version}.js'.format(version=__version_threejs__)
# three_filepath = os.path.join(target, three_filename)
# threejs = os.path.join(os.path.abspath(ipyvolume.__path__[0]), "static", "three.js")
# shutil.copy(threejs, three_filepath)

return pyv_filename#, three_filename


def save_requirejs(target="", version="2.3.4"):
def save_requirejs(target="", version=__version_requirejs__):
""" download and save the require javascript to a local file

:type target: str
Expand All @@ -75,6 +67,24 @@ def save_requirejs(target="", version="2.3.4"):
return filename


def save_jupyterthreejs(target="", devmode=False,
version=__version_threejs__):
""" Output the jupyter-threejs javascript to a local file.

:type target: str
:type devmode: bool
:param devmode: if True get jupyter-threejs.js from js/dist directory
:type version: str
:param version: version number of jupyter-threejs

"""
url = "https://unpkg.com/jupyter-threejs@{version}/dist/index.js".format(version=version)
filename = 'jupyter-threejs.js'
filepath = os.path.join(target, filename)
download_to_file(url, filepath)
return filename


def save_embed_js(target="", version=wembed.__html_manager_version__):
""" download and save the ipywidgets embedding javascript to a local file

Expand All @@ -93,7 +103,7 @@ def save_embed_js(target="", version=wembed.__html_manager_version__):


# TODO this may be able to get directly taken from embed-amd.js in the future jupyter-widgets/ipywidgets#1650
def save_font_awesome(dirpath='', version="4.7.0"):
def save_font_awesome(dirpath='', version=__version_fontawesome__):
""" download and save the font-awesome package to a local directory

:type dirpath: str
Expand Down Expand Up @@ -179,6 +189,7 @@ def embed_html(filepath, widgets, makedirs=True, title=u'IPyVolume Widget', all_

fname_pyv = save_ipyvolumejs(scripts_path, devmode=devmode)
fname_require = save_requirejs(os.path.join(scripts_path))
fname_threejs = save_jupyterthreejs(os.path.join(scripts_path))
fname_embed = save_embed_js(os.path.join(scripts_path))
fname_fontawe = save_font_awesome(os.path.join(scripts_path))

Expand Down