Skip to content

Commit

Permalink
disabling JS9 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
o-smirnov committed Oct 19, 2023
1 parent 5d8be5b commit 719779d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 33 deletions.
25 changes: 20 additions & 5 deletions bin/setup-radiopadre-virtualenv
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ PADRE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# JS9_VERSION = "3.3.1" ## disabling for now, helper connection issues, see https://github.com/ratt-ru/radiopadre-client/pull/36#issuecomment-809648445
#JS9_VERSION = os.environ.get("RADIOPADRE_JS9_VERSION", "3.2")
JS9_VERSION = os.environ.get("RADIOPADRE_JS9_VERSION", "3.6.1")
if os.environ.get("RADIOPADRE_INSTALL_JS9"):
JS9_VERSION = os.environ.get("RADIOPADRE_JS9_VERSION", "3.6.1")
else:
JS9_VERSION = None
JS9_IGNORE_ERRORS = os.environ.get("RADIOPADRE_JS9_IGNORE_ERRORS")

CARTA_VERSION = os.environ.get("RADIOPADRE_CARTA_VERSION", "3.0.0")
Expand Down Expand Up @@ -76,6 +79,9 @@ if not options.inside_container:
else:
PADRE_WORKDIR = "/.radiopadre"

if not JS9_VERSION:
options.no_js9 = True

def message(x, prefix='setup-radiopadre-virtualenv: '):
print(prefix + x.format(**globals()))

Expand Down Expand Up @@ -112,6 +118,7 @@ if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_pref
PADRE_VENV = sys.prefix
else:
bye("Not running in a virtualenv")
PADRE_VENV = "."

# # check for JS9 requirements
# if not options.no_js9:
Expand Down Expand Up @@ -149,7 +156,10 @@ if shell(cmd):

kerneldir = f"{PADRE_VENV}/share/jupyter/kernels/radiopadre"
message("Copying kernel.js and logos to {kerneldir}")
shutil.copy2(f"{PADRE_PATH}/radiopadre/html/radiopadre-kernel.js", f"{kerneldir}/kernel.js")
if not options.no_js9:
shutil.copy2(f"{PADRE_PATH}/radiopadre/html/radiopadre-kernel.js", f"{kerneldir}/kernel.js")
else:
shutil.copy2(f"{PADRE_PATH}/radiopadre/html/radiopadre-kernel-nojs9.js", f"{kerneldir}/kernel.js")
shutil.copy2(f"{PADRE_PATH}/icons/radiopadre-logo-32x32.png", f"{kerneldir}/logo-32x32.png")
shutil.copy2(f"{PADRE_PATH}/icons/radiopadre-logo-64x64.png", f"{kerneldir}/logo-64x64.png")

Expand Down Expand Up @@ -312,8 +322,14 @@ if PUPPETEER_VERSION:
# "'")

# install JS9
if not options.no_js9 and JS9_VERSION:
js9status = open(PADRE_VENV + "/js9status", "w")
js9_status_file = "{PADRE_VENV}/js9status"

if options.no_js9:
if os.path.exists(js9_status_file):
os.unlink(js9_status_file)
message("disabling JS9 installation")
else:
js9status = open(js9_status_file, "w")
js9_www = None
try:
# install JS9 inside venv
Expand Down Expand Up @@ -427,7 +443,6 @@ if options.no_js9:
message("Downloading socket.io.js into {notebook_socket_io}")
shell(f"wget {SOCKET_IO_LINK} -O {notebook_socket_io}")


open(complete_cookie, "w").write("installed by {__file__}".format(**globals()))

message("Installation successful!")
57 changes: 30 additions & 27 deletions radiopadre/fitsfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ def _collective_action_buttons_(fits_files, context, defaults=None):
# no buttons when converting
if radiopadre.NBCONVERT:
return None
if js9.JS9_ERROR:
return None

subs = globals().copy()
subs.update(display_id=context.div_id, **locals())
Expand Down Expand Up @@ -647,35 +649,36 @@ def _action_buttons_(self, context, defaults=None, **kw):
subs = globals().copy()
subs.update(display_id=context.div_id, **locals())

FITSFile._insert_js9_postscript(context.postscript, subs, defaults=defaults)
if not js9.JS9_ERROR:
FITSFile._insert_js9_postscript(context.postscript, subs, defaults=defaults)

# use empty display ID for JS9 scripts launched in a new tab
subs1 = subs.copy()
subs1['init_style'] = ''
subs1['display_id'] = ''
subs1['window_title'] = "JS9: {}".format(self.fullpath)
# print "making external window script",subs1['defaults']
subs['newtab_html'] = FITSFile._make_js9_external_window_script([self], self.basename, subs1,
defaults=defaults or FITSFile.make_js9_defaults(),
single_file=True)

subs['image_id'] = id(self)
subs['element_id'] = element_id = "{}_{}".format(context.div_id, id(self))
subs['launch_command'] = self._make_js9_launch_command(context.div_id)

context.postscript[element_id] = """<script type='text/javascript'>
JS9p._pd_{element_id}_load = function () {{
{launch_command}
document.getElementById("JS9load-{element_id}").innerHTML = "&#x21A1;JS9"
}}
</script>""".format(**subs)
# use empty display ID for JS9 scripts launched in a new tab
subs1 = subs.copy()
subs1['init_style'] = ''
subs1['display_id'] = ''
subs1['window_title'] = "JS9: {}".format(self.fullpath)
# print "making external window script",subs1['defaults']
subs['newtab_html'] = FITSFile._make_js9_external_window_script([self], self.basename, subs1,
defaults=defaults or FITSFile.make_js9_defaults(),
single_file=True)

subs['image_id'] = id(self)
subs['element_id'] = element_id = "{}_{}".format(context.div_id, id(self))
subs['launch_command'] = self._make_js9_launch_command(context.div_id)

context.postscript[element_id] = """<script type='text/javascript'>
JS9p._pd_{element_id}_load = function () {{
{launch_command}
document.getElementById("JS9load-{element_id}").innerHTML = "&#x21A1;JS9"
}}
</script>""".format(**subs)

code = """
<button id="JS9load-{element_id}" title="display using an inline JS9 window" style="font-size: 0.9em;"
onclick="JS9p._pd_{element_id}_load()">&#8595;JS9</button>
<button id="" title="display using JS9 in a new browser tab" style="font-size: 0.9em;"
onclick="window.open('{newtab_html}', '_blank')">&#8663;JS9</button>
""".format(**subs)
code = """
<button id="JS9load-{element_id}" title="display using an inline JS9 window" style="font-size: 0.9em;"
onclick="JS9p._pd_{element_id}_load()">&#8595;JS9</button>
<button id="" title="display using JS9 in a new browser tab" style="font-size: 0.9em;"
onclick="window.open('{newtab_html}', '_blank')">&#8663;JS9</button>
""".format(**subs)

if iglesia.CARTA_VERSION:
filepath = os.path.relpath(os.path.abspath(self.fullpath), iglesia.SERVER_BASEDIR)
Expand Down
1 change: 1 addition & 0 deletions radiopadre_kernel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def init():
message(f"registered exit handler")

# init JS9 sources

from . import js9
js9.preinit_js9()

Expand Down
7 changes: 6 additions & 1 deletion radiopadre_kernel/js9/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, os.path, traceback
import os, os.path, traceback, sys

from iglesia.utils import message, error
# init JS9 configuration
Expand All @@ -23,10 +23,15 @@ def preinit_js9():
import radiopadre_kernel
import iglesia


global JS9_HELPER_PORT, JS9_DIR
JS9_DIR = iglesia.JS9_DIR
JS9_HELPER_PORT = iglesia.JS9HELPER_PORT

if not JS9_DIR:
JS9_ERROR = "not installed"
return

try:
global JS9_ERROR
if not os.path.exists(JS9_DIR):
Expand Down

0 comments on commit 719779d

Please sign in to comment.