Skip to content

Commit

Permalink
feat: use embedded qt browser for jdaviz standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Sep 12, 2024
1 parent 19548bb commit 901b68c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,36 @@ jobs:
with:
python-version: "3.11"

- uses: ConorMacBride/install-package@v1
with:
# mirrored from glue-qt
# https://github.com/glue-viz/glue-qt/blob/main/.github/workflows/ci_workflows.yml
# using
# https://github.com/OpenAstronomy/github-actions-workflows/blob/5edb24fa432c75c0ca723ddea8ea14b72582919d/.github/workflows/tox.yml#L175C15-L175C49
# Linux PyQt 5.15 and 6.x installations require apt-getting xcb and EGL deps
# and headless X11 display;
apt: '^libxcb.*-dev libxkbcommon-x11-dev libegl1-mesa libopenblas-dev libhdf5-dev'

- name: Setup headless display
uses: pyvista/setup-headless-display-action@v2

- name: Install jdaviz
run: pip install .[test]
run: pip install .[test,qt]

- name: Install pyinstaller
run: pip install "pyinstaller<6"
# see https://github.com/erocarrera/pefile/issues/420 for performance issues on
# windows for pefile == 2024.8.26
# also see https://github.com/widgetti/solara/pull/724
# or https://solara.dev/documentation/advanced/howto/standalone (currently unpublished)
run: pip install "pyinstaller" "pefile<2024.8.26"

- name: Create standalone binary
env:
DEVELOPER_ID_APPLICATION: ${{ secrets.DEVELOPER_ID_APPLICATION }}
run: (cd standalone; pyinstaller ./jdaviz.spec)

- name: Run jdaviz cmd in background
run: ./standalone/dist/jdaviz/jdaviz-cli imviz&
run: ./standalone/dist/jdaviz/jdaviz-cli imviz --port 8765 &

- name: Install playwright
run: (pip install playwright; playwright install chromium)
Expand Down
10 changes: 3 additions & 7 deletions jdaviz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,16 @@ def main(filepaths=None, layout='default', instrument=None, browser='default',
solara.theme = theme
solara.jdaviz_verbosity = verbosity
solara.jdaviz_history_verbosity = history_verbosity
args = []
if hotreload:
args += ['--auto-restart']
else:
args += ['--production']
run_solara(host=host, port=port, theme=theme, browser=browser)
run_solara(host=host, port=port, theme=theme, browser=browser, production=not hotreload)


def run_solara(host, port, theme, browser):
def run_solara(host, port, theme, browser, production: bool = True):
os.environ["SOLARA_APP"] = "jdaviz.solara"
import solara.server.starlette
import solara.server.settings
solara.server.settings.theme.variant = theme
solara.server.settings.theme.loader = "plain"
solara.server.settings.main.mode = "production" if production else "development"

server = solara.server.starlette.ServerStarlette(host="localhost", port=port)
print(f"Starting server on {server.base_url}")
Expand Down
5 changes: 5 additions & 0 deletions standalone/hooks/hook-matplotlib_inline.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

datas = collect_data_files('matplotlib_inline')
# since matplotlib 3.9 entry_points.txt is needed
datas += copy_metadata('matplotlib_inline')
17 changes: 16 additions & 1 deletion standalone/jdaviz-cli-entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,24 @@
import matplotlib_inline
import matplotlib_inline.backend_inline

# We still see the above error on CI on jdaviz, and the PyInstaller
# output recommends the following:
import matplotlib
matplotlib.use("module://matplotlib_inline.backend_inline")
# since matplotlib 3.9 (see https://github.com/matplotlib/matplotlib/pull/27948),
# it seems that matplotlib_inline.backend_inline is an alias for inline
# so we make sure to communicate that to PyInstaller
matplotlib.use("inline")

import jdaviz.cli


if __name__ == "__main__":
# should change this to _main, but now it doesn't need arguments
jdaviz.cli.main(layout="")
args = sys.argv.copy()
# change the browser to qt if not specified
if "--browser" not in args:
args.append("--browser")
args.append("qt")
sys.argv = args
jdaviz.cli._main()
2 changes: 1 addition & 1 deletion standalone/jdaviz.spec
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ exe = EXE(
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
Expand Down

0 comments on commit 901b68c

Please sign in to comment.