From 4d98eacf4e92ab533633aabdd4c7a8ed8a343cdb Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Fri, 6 Oct 2023 13:55:06 +0200 Subject: [PATCH] feat: support solara When using the solara server, the popout url is be the root url of the solara server. Also, the kernel id is retrieved from the solara server. --- .github/workflows/main.yml | 4 ---- ipypopout/popout_button.py | 11 +++++++++++ ipypopout/popout_button.vue | 3 +++ tests/ui/popout_test.py | 7 +++++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 53a9fd0..528d3c8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -90,9 +90,6 @@ jobs: run: playwright install chromium - name: Run ui-tests - env: - # do not run solara (yet) - SOLARA_TEST_RUNNERS: "jupyter_lab,jupyter_notebook,voila" run: pytest tests/ui/ --video=retain-on-failure --solara-update-snapshots-ci -s - name: Upload Test artifacts @@ -128,4 +125,3 @@ jobs: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} run: twine upload --skip-existing dist/* - diff --git a/ipypopout/popout_button.py b/ipypopout/popout_button.py index 8949230..1d2c402 100644 --- a/ipypopout/popout_button.py +++ b/ipypopout/popout_button.py @@ -4,9 +4,20 @@ import traitlets import ipywidgets import ipyvuetify as v +import sys def get_kernel_id(): + if "solara" in sys.modules: + import solara + if solara._using_solara_server(): + try: + import solara.server.kernel_context + + context = solara.server.kernel_context.get_current_context() + return context.id + except RuntimeError: + pass ipython = IPython.get_ipython() if not ipython or not hasattr(ipython, 'kernel'): return '' diff --git a/ipypopout/popout_button.vue b/ipypopout/popout_button.vue index 4bcdf45..3f03cd6 100644 --- a/ipypopout/popout_button.vue +++ b/ipypopout/popout_button.vue @@ -65,6 +65,9 @@ module.exports = { }, computed: { popoutPageUrl() { + if (window.solara && (solara.rootPath !== undefined)) { + return solara.rootPath; + } return 'voila/templates/ipypopout/static/popout.html' } } diff --git a/tests/ui/popout_test.py b/tests/ui/popout_test.py index c3c7472..7da0a0b 100644 --- a/tests/ui/popout_test.py +++ b/tests/ui/popout_test.py @@ -28,4 +28,11 @@ def kernel_code(): new_page.locator("text=Test ipypopout").wait_for() # the button should not be on the page new_page.locator("_vue=v-btn").wait_for(state="detached") + # if we do not go to a blank page, on solara, the server will not get the close beacon + # and the kernel will not shut down + new_page.goto("about:blank") + # wait for the kernel to shut down, if we close the page to early + # it seem again the server will not get the close beacon + # and solara's test framework fails + new_page.wait_for_timeout(1000) new_page.close()