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

Do not fail when java is available but jmol is not. #36769

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions src/sage/interfaces/jmoldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,47 @@
java_version_number = int(re.sub(r'.*version "(0\.|1\.)?(\d*)[\s\S]*', r'\2', version, flags=re.S))
return java_version_number >= 7

def jmolpath(self):
"""
Return the path to the jar file.

EXAMPLES::

sage: from sage.interfaces.jmoldata import JmolData
sage: JData = JmolData()
sage: JData.jmolpath()
'.../JmolData.jar'

"""
jmolpath = os.path.join(JMOL_DIR, "JmolData.jar")

if sys.platform == 'cygwin':
import cygwin
jmolpath = cygwin.cygpath(jmolpath, 'w')

Check warning on line 90 in src/sage/interfaces/jmoldata.py

View check run for this annotation

Codecov / codecov/patch

src/sage/interfaces/jmoldata.py#L89-L90

Added lines #L89 - L90 were not covered by tests

return jmolpath

def is_jmol_available(self):
"""
Returns True if jmol is available and False if not.

EXAMPLES:

Check that it returns a boolean::

sage: from sage.interfaces.jmoldata import JmolData
sage: JData = JmolData()
sage: type(JData.is_jmol_available())
<... 'bool'>
"""
if not os.path.isfile(self.jmolpath()):
return False

Check warning on line 108 in src/sage/interfaces/jmoldata.py

View check run for this annotation

Codecov / codecov/patch

src/sage/interfaces/jmoldata.py#L108

Added line #L108 was not covered by tests

if not self.is_jvm_available():
return False

return True

Check warning on line 113 in src/sage/interfaces/jmoldata.py

View check run for this annotation

Codecov / codecov/patch

src/sage/interfaces/jmoldata.py#L113

Added line #L113 was not covered by tests

def export_image(self,
targetfile,
datafile, #name (path) of data file Jmol can read or script file telling it what to read or load
Expand Down Expand Up @@ -154,12 +195,11 @@
sage: archive.close()
"""
# Set up paths, file names and scripts
jmolpath = os.path.join(JMOL_DIR, "JmolData.jar")
jmolpath = self.jmolpath()

Check warning on line 198 in src/sage/interfaces/jmoldata.py

View check run for this annotation

Codecov / codecov/patch

src/sage/interfaces/jmoldata.py#L198

Added line #L198 was not covered by tests
target_native = targetfile

if sys.platform == 'cygwin':
import cygwin
jmolpath = cygwin.cygpath(jmolpath, 'w')
target_native = cygwin.cygpath(target_native, 'w')
if datafile_cmd != 'script':
datafile = cygwin.cygpath(datafile, 'w')
Expand Down
2 changes: 1 addition & 1 deletion src/sage/plot/plot3d/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ cdef class Graphics3d(SageObject):
T.export_jmol(scene_zip, **opts)
from sage.interfaces.jmoldata import JmolData
jdata = JmolData()
if not jdata.is_jvm_available():
if not jdata.is_jmol_available():
# We can only use JMol to generate preview if a jvm is installed
from sage.repl.rich_output.output_graphics import OutputImagePng
tachyon = self._rich_repr_tachyon(OutputImagePng, **opts)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/repl/rich_output/backend_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def launch_jmol(self, output_jmol, plain_text):
from sage.doctest import DOCTEST_MODE
from sage.interfaces.jmoldata import JmolData
jdata = JmolData()
if not jdata.is_jvm_available() and not DOCTEST_MODE:
if not jdata.is_jmol_available() and not DOCTEST_MODE:
raise RuntimeError('jmol cannot run, no suitable java version found')
launch_script = output_jmol.launch_script_filename()
jmol_cmd = 'jmol'
Expand Down
Loading