[sagemath] 01/01: Disable Sage's JSmol features
Ximin Luo
infinity0 at debian.org
Sat Dec 3 23:56:00 UTC 2016
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch _experiment_jmol
in repository sagemath.
commit 073e2d98a8a25b1b731c4ca9a4ed8f27c6a2e4a6
Author: Ximin Luo <infinity0 at debian.org>
Date: Sun Dec 4 00:55:38 2016 +0100
Disable Sage's JSmol features
---
debian/patches/disable-jsmol.patch | 368 +++++++++++++++++++++++++++++++++++++
debian/patches/series | 2 +
debian/pruner/configure.ac | 2 +-
debian/todo-stretch.md | 6 +-
4 files changed, 372 insertions(+), 6 deletions(-)
diff --git a/debian/patches/disable-jsmol.patch b/debian/patches/disable-jsmol.patch
new file mode 100644
index 0000000..c9f6606
--- /dev/null
+++ b/debian/patches/disable-jsmol.patch
@@ -0,0 +1,368 @@
+Description: Disable JSmol features
+ Since we are having difficulty packaging that for Debian
+Author: Ximin Luo <infinity0 at debian.org>
+Forwarded: not-needed
+--- a/sage/src/doc/en/reference/repl/index.rst
++++ b/sage/src/doc/en/reference/repl/index.rst
+@@ -96,7 +96,6 @@
+ sage/repl/ipython_kernel/kernel
+ sage/repl/ipython_tests
+
+- sage/repl/display/jsmol_iframe
+ sage/repl/image
+ sage/repl/inputhook
+
+--- a/sage/src/sage/repl/ipython_kernel/install.py
++++ b/sage/src/sage/repl/ipython_kernel/install.py
+@@ -113,23 +113,6 @@
+ dst = os.path.join(self.nbextensions_dir, 'mathjax')
+ self.symlink(src, dst)
+
+- def use_local_jsmol(self):
+- """
+- Symlink jsmol to the Jupyter notebook.
+-
+- EXAMPLES::
+-
+- sage: from sage.repl.ipython_kernel.install import SageKernelSpec
+- sage: spec = SageKernelSpec()
+- sage: spec.use_local_jsmol()
+- sage: jsmol = os.path.join(spec.nbextensions_dir, 'jsmol')
+- sage: os.path.isdir(jsmol)
+- True
+- """
+- src = os.path.join(SAGE_LOCAL, 'share', 'jsmol')
+- dst = os.path.join(self.nbextensions_dir, 'jsmol')
+- self.symlink(src, dst)
+-
+ def _kernel_cmd(self):
+ """
+ Helper to construct the SageMath kernel command.
+@@ -235,7 +218,6 @@
+ """
+ instance = cls()
+ instance.use_local_mathjax()
+- instance.use_local_jsmol()
+ instance._install_spec()
+ instance._symlink_resources()
+
+--- a/sage/src/sage/repl/display/jsmol_iframe.py
++++ /dev/null
+@@ -1,302 +0,0 @@
+-"""
+-HTML Generator for JSmol
+-
+-This is all an evil iframe hack to get JSmol to display 3-d graphics
+-while separating JSmol's j2s machinery from your actual web page.
+-
+-There are some caveats for how to load JSmol, in particular it cannot
+-just load its code from a ``file://`` uri. To use a html file
+-generated by this module, you need
+-
+-* A web server,
+-
+-* The JSmol directory tree must be served by your web server,
+-
+-* The output of :meth:`JSMolHtml.inner_html` or
+- :meth:`JSMolHtml.outer_html` must be served by the same web server.
+-
+-See https://github.com/phetsims/molecule-polarity/issues/6 for a
+-discussion of loading JSMol.
+-"""
+-
+-import os
+-import zipfile
+-from six import StringIO
+-
+-from sage.env import SAGE_LOCAL
+-from sage.structure.sage_object import SageObject
+-from sage.misc.cachefunc import cached_method
+-
+-
+-INNER_HTML_TEMPLATE = \
+-"""
+-<html>
+-<head>
+- <style>
+- * {{
+- margin: 0;
+- padding: 0;
+- overflow: hidden;
+- }}
+- body, html {{
+- height: 100%;
+- width: 100%;
+- }}
+- </style>
+- <script type="text/javascript" src="{path_to_jsmol}/JSmol.min.js"></script>
+-</head>
+-<body>
+- <script type="text/javascript">
+- var script = {script};
+- var Info = {{
+- width: '{width}',
+- height: '{height}',
+- debug: false,
+- disableInitialConsole: true, // very slow when used with inline mesh
+- color: '#3131ff',
+- addSelectionOptions: false,
+- use: 'HTML5',
+- j2sPath: '{path_to_jsmol}/j2s',
+- script: script,
+- }};
+- var jmolApplet0 = Jmol.getApplet('jmolApplet0', Info);
+- </script>
+-</body>
+-</html>
+-"""
+-
+-
+-IFRAME_TEMPLATE = \
+-"""
+-<iframe srcdoc="{escaped_inner_html}"
+- width="{width}"
+- height="{height}"
+- style="border: 0;">
+-</iframe>
+-"""
+-
+-
+-OUTER_HTML_TEMPLATE = \
+-"""
+-<html>
+-<head>
+- <title>JSmol 3D Scene</title>
+-</head>
+-</body>
+- {iframe}
+-</body>
+-</html>
+-""".format(iframe=IFRAME_TEMPLATE)
+-
+-
+-class JSMolHtml(SageObject):
+-
+- def __init__(self, jmol, path_to_jsmol=None, width='100%', height='100%'):
+- """
+- INPUT:
+-
+- - ``jmol`` -- 3-d graphics or
+- :class:`sage.repl.rich_output.output_graphics3d.OutputSceneJmol`
+- instance. The 3-d scene to show.
+-
+- - ``path_to_jsmol`` -- string (optional, default is
+- ``'/nbextensions/jsmol'``). The path (relative or absolute)
+- where ``JSmol.min.js`` is served on the web server.
+-
+- - ``width`` -- integer or string (optional, default:
+- ``'100%'``). The width of the JSmol applet using CSS
+- dimensions.
+-
+- - ``height`` -- integer or string (optional, default:
+- ``'100%'``). The height of the JSmol applet using CSS
+- dimensions.
+-
+- EXAMPLES::
+-
+- sage: from sage.repl.display.jsmol_iframe import JSMolHtml
+- sage: JSMolHtml(sphere(), width=500, height=300)
+- JSmol Window 500x300
+- """
+- from sage.repl.rich_output.output_graphics3d import OutputSceneJmol
+- if not isinstance(jmol, OutputSceneJmol):
+- jmol = jmol._rich_repr_jmol()
+- self._jmol = jmol
+- self._zip = zipfile.ZipFile(StringIO(self._jmol.scene_zip.get()))
+- if path_to_jsmol is None:
+- self._path = os.path.join('/', 'nbextensions', 'jsmol')
+- else:
+- self._path = path_to_jsmol
+- self._width = width
+- self._height = height
+-
+- @cached_method
+- def script(self):
+- r"""
+- Return the JMol script file.
+-
+- This method extracts the Jmol script from the Jmol spt file (a
+- zip archive) and inlines meshes.
+-
+- OUTPUT:
+-
+- String.
+-
+- EXAMPLES::
+-
+- sage: from sage.repl.display.jsmol_iframe import JSMolHtml
+- sage: from sage.repl.rich_output.output_graphics3d import OutputSceneJmol
+- sage: jsmol = JSMolHtml(OutputSceneJmol.example(), width=500, height=300)
+- sage: jsmol.script()
+- 'data "model list"\n10\nempt...aliasdisplay on;\n'
+- """
+- script = []
+- with self._zip.open('SCRIPT') as SCRIPT:
+- for line in SCRIPT:
+- if line.startswith('pmesh'):
+- command, obj, meshfile = line.split(' ', 3)
+- assert command == 'pmesh'
+- assert meshfile.startswith('"') and meshfile.endswith('"\n')
+- meshfile = meshfile[1:-2] # strip quotes
+- script += [
+- 'pmesh {0} inline "'.format(obj),
+- self._zip.open(meshfile).read(),
+- '"\n'
+- ]
+- else:
+- script += [line]
+- return ''.join(script)
+-
+- def js_script(self):
+- r"""
+- The :meth:`script` as Javascript string.
+-
+- Since the many shortcomings of Javascript include multi-line
+- strings, this actually returns Javascript code to reassemble
+- the script from a list of strings.
+-
+- OUTPUT:
+-
+- String. Javascript code that evaluates to :meth:`script` as
+- Javascript string.
+-
+- EXAMPLES::
+-
+- sage: from sage.repl.display.jsmol_iframe import JSMolHtml
+- sage: from sage.repl.rich_output.output_graphics3d import OutputSceneJmol
+- sage: jsmol = JSMolHtml(OutputSceneJmol.example(), width=500, height=300)
+- sage: print(jsmol.js_script())
+- [
+- 'data "model list"',
+- ...
+- 'isosurface fullylit; pmesh o* fullylit; set antialiasdisplay on;',
+- ].join('\n');
+- """
+- script = [r"["]
+- for line in self.script().splitlines():
+- script += [r" '{0}',".format(line)]
+- script += [r"].join('\n');"]
+- return '\n'.join(script)
+-
+- def _repr_(self):
+- """
+- Return as string representation
+-
+- OUTPUT:
+-
+- String.
+-
+- EXAMPLES::
+-
+- sage: from sage.repl.display.jsmol_iframe import JSMolHtml
+- sage: from sage.repl.rich_output.output_graphics3d import OutputSceneJmol
+- sage: JSMolHtml(OutputSceneJmol.example(), width=500, height=300)._repr_()
+- 'JSmol Window 500x300'
+- """
+- return 'JSmol Window {0}x{1}'.format(self._width, self._height)
+-
+- def inner_html(self):
+- """
+- Return a HTML document containing a JSmol applet
+-
+- EXAMPLES::
+-
+- sage: from sage.repl.display.jsmol_iframe import JSMolHtml
+- sage: from sage.repl.rich_output.output_graphics3d import OutputSceneJmol
+- sage: jmol = JSMolHtml(OutputSceneJmol.example(), width=500, height=300)
+- sage: print(jmol.inner_html())
+- <html>
+- <head>
+- <style>
+- * {
+- margin: 0;
+- padding: 0;
+- ...
+- </html>
+- """
+- return INNER_HTML_TEMPLATE.format(
+- script=self.js_script(),
+- width=self._width,
+- height=self._height,
+- path_to_jsmol=self._path,
+- )
+-
+- def iframe(self):
+- """
+- Return HTML iframe
+-
+- OUTPUT:
+-
+- String.
+-
+- EXAMPLES::
+-
+- sage: from sage.repl.display.jsmol_iframe import JSMolHtml
+- sage: from sage.repl.rich_output.output_graphics3d import OutputSceneJmol
+- sage: jmol = JSMolHtml(OutputSceneJmol.example())
+- sage: print(jmol.iframe())
+- <iframe srcdoc="
+- ...
+- </iframe>
+- """
+- escaped_inner_html = self.inner_html().replace('"', '"')
+- iframe = IFRAME_TEMPLATE.format(
+- script=self.js_script(),
+- width=self._width,
+- height=self._height,
+- escaped_inner_html=escaped_inner_html,
+- )
+- return iframe
+-
+- def outer_html(self):
+- """
+- Return a HTML document containing an iframe with a JSmol applet
+-
+- OUTPUT:
+-
+- String
+-
+- EXAMPLES::
+-
+- sage: from sage.repl.display.jsmol_iframe import JSMolHtml
+- sage: from sage.repl.rich_output.output_graphics3d import OutputSceneJmol
+- sage: jmol = JSMolHtml(OutputSceneJmol.example(), width=500, height=300)
+- sage: print(jmol.outer_html())
+- <html>
+- <head>
+- <title>JSmol 3D Scene</title>
+- </head>
+- </body>
+- <BLANKLINE>
+- <iframe srcdoc="
+- ...
+- </html>
+- """
+- escaped_inner_html = self.inner_html().replace('"', '"')
+- outer = OUTER_HTML_TEMPLATE.format(
+- script=self.js_script(),
+- width=self._width,
+- height=self._height,
+- escaped_inner_html=escaped_inner_html,
+- )
+- return outer
+-
+--- a/sage/src/sage/repl/rich_output/backend_ipython.py
++++ b/sage/src/sage/repl/rich_output/backend_ipython.py
+@@ -521,12 +521,6 @@
+ return ({u'image/png': rich_output.png.get(),
+ u'text/plain': plain_text.text.get_unicode(),
+ }, {})
+- elif isinstance(rich_output, OutputSceneJmol):
+- from sage.repl.display.jsmol_iframe import JSMolHtml
+- jsmol = JSMolHtml(rich_output, height=500)
+- return ({u'text/html': jsmol.iframe(),
+- u'text/plain': plain_text.text.get_unicode(),
+- }, {})
+ else:
+ raise TypeError('rich_output type not supported')
+
diff --git a/debian/patches/series b/debian/patches/series
index de9b671..bb508fa 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -60,3 +60,5 @@ version-temp-singular-4-extra-fixes.patch
version-temp-glpk-4.60-extra-hacky-fixes.patch
debian-temp-r-no-readline.patch
trac_21749.patch
+
+disable-jsmol.patch
diff --git a/debian/pruner/configure.ac b/debian/pruner/configure.ac
index 7b5e128..a2fc111 100644
--- a/debian/pruner/configure.ac
+++ b/debian/pruner/configure.ac
@@ -143,7 +143,7 @@ AC_SUBST(HAS_IML)
AC_CHECK_PROG(HAS_IPYTHON, ipython, "True", "False")
AC_SUBST(HAS_IPYTHON)
-AC_CHECK_FILE(/usr/bin/jmol, HAS_JMOL="True", HAS_JMOL="False")
+AC_CHECK_FILE(/usr/share/jmol/Jmol.jar, HAS_JMOL="True", HAS_JMOL="False")
AC_SUBST(HAS_JMOL)
AC_CHECK_PROG(HAS_JUPYTER_CLIENT, jupyter-kernelspec, "True", "False")
diff --git a/debian/todo-stretch.md b/debian/todo-stretch.md
index 8e570b0..5764f22 100644
--- a/debian/todo-stretch.md
+++ b/debian/todo-stretch.md
@@ -18,11 +18,7 @@ Upload packages to NEW, ASAP
Maybe we should install most of that to /usr/share/sage/bin.
* We could create a package containing the (patched) sage sources to make
it easier to run the testsuite.
- * test with missing jmol (maybe set canvas3d as default in
- src/sage/plot/plot3d/base.pyx / src/sage/graphs/generic_graph.py ?)
- * might be possible to package jmol and disable only jsmol, if that's easier
- see https://github.com/infinity0/jmol/ and its Makefile
- we would remove JSmol, then graft the rest onto the existing debian jmol packaging
+ * test with packaged jmol, disable the ones that need jsmol
* sagetex (already in experimental, does not need to pass NEW)
* Packages that have issues preventing testing migration:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/sagemath.git
More information about the debian-science-commits
mailing list