Skip to content

Commit b1e5577

Browse files
committed
Do not fail when java is available but jmol is not.
If java is not available, sagemath will fallback to tachyon gracefully. When java is available, sagemath will assume jmol is available and error if not. This commit fixes the issue by implementing a method `is_jmol_available()` to replace `is_jvm_available()`.
1 parent f10820f commit b1e5577

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

src/sage/interfaces/jmoldata.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,47 @@ def is_jvm_available(self):
7171
java_version_number = int(re.sub(r'.*version "(0\.|1\.)?(\d*)[\s\S]*', r'\2', version, flags=re.S))
7272
return java_version_number >= 7
7373

74+
def jmolpath(self):
75+
"""
76+
Return the path to the jar file.
77+
78+
EXAMPLES::
79+
80+
sage: from sage.interfaces.jmoldata import JmolData
81+
sage: JData = JmolData()
82+
sage: JData.jmolpath()
83+
'.../JmolData.jar'
84+
85+
"""
86+
jmolpath = os.path.join(JMOL_DIR, "JmolData.jar")
87+
88+
if sys.platform == 'cygwin':
89+
import cygwin
90+
jmolpath = cygwin.cygpath(jmolpath, 'w')
91+
92+
return jmolpath
93+
94+
def is_jmol_available(self):
95+
"""
96+
Returns True if jmol is available and False if not.
97+
98+
EXAMPLES:
99+
100+
Check that it returns a boolean::
101+
102+
sage: from sage.interfaces.jmoldata import JmolData
103+
sage: JData = JmolData()
104+
sage: type(JData.is_jmol_available())
105+
<... 'bool'>
106+
"""
107+
if not os.path.isfile(self.jmolpath()):
108+
return False
109+
110+
if not self.is_jvm_available():
111+
return False
112+
113+
return True
114+
74115
def export_image(self,
75116
targetfile,
76117
datafile, #name (path) of data file Jmol can read or script file telling it what to read or load
@@ -154,12 +195,11 @@ def export_image(self,
154195
sage: archive.close()
155196
"""
156197
# Set up paths, file names and scripts
157-
jmolpath = os.path.join(JMOL_DIR, "JmolData.jar")
198+
jmolpath = self.jmolpath()
158199
target_native = targetfile
159200

160201
if sys.platform == 'cygwin':
161202
import cygwin
162-
jmolpath = cygwin.cygpath(jmolpath, 'w')
163203
target_native = cygwin.cygpath(target_native, 'w')
164204
if datafile_cmd != 'script':
165205
datafile = cygwin.cygpath(datafile, 'w')

src/sage/plot/plot3d/base.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ cdef class Graphics3d(SageObject):
278278
T.export_jmol(scene_zip, **opts)
279279
from sage.interfaces.jmoldata import JmolData
280280
jdata = JmolData()
281-
if not jdata.is_jvm_available():
281+
if not jdata.is_jmol_available():
282282
# We can only use JMol to generate preview if a jvm is installed
283283
from sage.repl.rich_output.output_graphics import OutputImagePng
284284
tachyon = self._rich_repr_tachyon(OutputImagePng, **opts)

src/sage/repl/rich_output/backend_ipython.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def launch_jmol(self, output_jmol, plain_text):
369369
from sage.doctest import DOCTEST_MODE
370370
from sage.interfaces.jmoldata import JmolData
371371
jdata = JmolData()
372-
if not jdata.is_jvm_available() and not DOCTEST_MODE:
372+
if not jdata.is_jmol_available() and not DOCTEST_MODE:
373373
raise RuntimeError('jmol cannot run, no suitable java version found')
374374
launch_script = output_jmol.launch_script_filename()
375375
jmol_cmd = 'jmol'

0 commit comments

Comments
 (0)