Skip to content

Commit

Permalink
feat: use solara for pyinstaller (#11)
Browse files Browse the repository at this point in the history
* feat: use solara for pyinstaller
* rich.logging hidden import
* make test run
* close when tab is closed
  • Loading branch information
maartenbreddels authored and kecnry committed Jul 30, 2024
1 parent caf9dbb commit c62c763
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defaults:
jobs:
build_binary_not_osx:
runs-on: ${{ matrix.os }}-latest
if: (github.repository == 'spacetelescope/jdaviz' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'Build standalone')))
# if: (github.repository == 'spacetelescope/jdaviz' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'Build standalone')))
strategy:
matrix:
os: [ubuntu, windows]
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Wait for Voila to get online
uses: ifaxity/wait-on-action@a7d13170ec542bdca4ef8ac4b15e9c6aa00a6866 # v1.2.1
with:
resource: tcp:8866
resource: tcp:8765
timeout: 60000

- name: Test standalone
Expand Down
15 changes: 15 additions & 0 deletions jdaviz/solara.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
from pathlib import Path
import signal

import solara
import solara.lab
import ipygoldenlayout
import ipysplitpanes
import ipyvue
Expand All @@ -16,6 +18,19 @@
jdaviz_history_verbosity = 'info'


@solara.lab.on_kernel_start
def on_kernel_start():
# at import time, solara runs with a dummy kernel
# we simply ignore that
if "dummy" in solara.get_kernel_id():
return
def on_kernel_close():
# for some reason, sys.exit(0) does not work here
# see https://github.com/encode/uvicorn/discussions/1103
signal.raise_signal(signal.SIGINT)
return on_kernel_close


@solara.component
def Page():
if config is None:
Expand Down
5 changes: 5 additions & 0 deletions standalone/hooks/hook-ipyreact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from PyInstaller.utils.hooks import collect_data_files, copy_metadata, collect_submodules

hiddenimports = collect_submodules("ipyreact")
datas = collect_data_files("ipyreact") # codespell:ignore datas
datas += copy_metadata("ipyreact") # codespell:ignore datas
5 changes: 5 additions & 0 deletions standalone/hooks/hook-ipyvuetify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from PyInstaller.utils.hooks import collect_data_files, copy_metadata, collect_submodules

hiddenimports = collect_submodules("ipyvuetify")
datas = collect_data_files('ipyvuetify')
datas += copy_metadata('ipyvuetify')
5 changes: 5 additions & 0 deletions standalone/hooks/hook-solara.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from PyInstaller.utils.hooks import collect_data_files, copy_metadata, collect_submodules

hiddenimports = collect_submodules("solara")
datas = collect_data_files('solara')
datas += collect_data_files('solara-ui')
5 changes: 5 additions & 0 deletions standalone/hooks/hook-solara_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from PyInstaller.utils.hooks import collect_data_files, copy_metadata, collect_submodules

hiddenimports = collect_submodules("solara-server")
datas = collect_data_files('solara-server')
datas += copy_metadata('solara-server')
5 changes: 5 additions & 0 deletions standalone/hooks/hook-solara_ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from PyInstaller.utils.hooks import collect_data_files, copy_metadata, collect_submodules

hiddenimports = collect_submodules("solara-ui")
datas = collect_data_files('solara-ui')
datas += copy_metadata('solara-ui')
21 changes: 3 additions & 18 deletions standalone/jdaviz-cli-entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,9 @@
import matplotlib_inline
import matplotlib_inline.backend_inline

def start_as_kernel():
# similar to https://github.com/astrofrog/voila-qt-app/blob/master/voila_demo.py
import sys

from ipykernel import kernelapp as app
app.launch_new_instance()
sys.argv = [app.__file__, sys.argv[3:]]
import jdaviz.cli


if __name__ == "__main__":
# When voila starts a kernel under pyinstaller, it will use sys.executable
# (which is this entry point again)
# if called like [sys.argv[0], "-m", "ipykernel_launcher", ...]
if len(sys.argv) >= 3 and sys.argv[1] == "-m" and sys.argv[2] == "ipykernel_launcher":
# it is important that we do not import jdaviz top level
# as that would cause it to import ipywidgets before the kernel is started
start_as_kernel()
else:
import jdaviz.cli
# should change this to _main, but now it doesn't need arguments
jdaviz.cli.main(layout="")
# should change this to _main, but now it doesn't need arguments
jdaviz.cli.main(layout="")
2 changes: 1 addition & 1 deletion standalone/jdaviz.spec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ a = Analysis(
pathex=[],
binaries=[],
datas=datas,
hiddenimports=[],
hiddenimports=["rich.logging"],
hookspath=["hooks"],
hooksconfig={},
runtime_hooks=[],
Expand Down
4 changes: 1 addition & 3 deletions standalone/test_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@


def test_voila_basics(page: Page):
page.goto("http://localhost:8866/")
page.goto("http://localhost:8765/")

# basic voila is loaded
page.locator("body.theme-light").wait_for()
# when jdaviz is loaded (button at the top left)
page.locator("text=Welcome to Jdaviz").wait_for()

0 comments on commit c62c763

Please sign in to comment.