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

Package example notebooks in JupyterLite #3491

Merged
merged 26 commits into from
Jul 11, 2022

Conversation

jasongrout
Copy link
Member

@jasongrout jasongrout commented Jun 17, 2022

This packages many of the example notebooks in a live JupyterLite instance available from the documentation.

CC @martinRenou

@github-actions
Copy link

Binder 👈 Launch a binder notebook on branch jasongrout/ipywidgets/jlite2

@martinRenou
Copy link
Member

It seems that nbsphinx and jupyterlite-sphinx both claim to render ipynb files, and it seemed I was getting some conflicts, so for now I disabled nbsphinx.

Indeed, this is a known issue. I pushed a PR to nbsphinx to try to fix. It probably needs updating: spatialaudio/nbsphinx#637

@martinRenou
Copy link
Member

A workaround is to not use the custom parser, and instead use the directives directly

@jasongrout
Copy link
Member Author

A workaround is to not use the custom parser, and instead use the directives directly

Oh, right, and manually override the parser for ipynb files. Nice!

@martinRenou
Copy link
Member

You might want to give xeus-python a try in this PR :) Using https://xeus-python-kernel.readthedocs.io/en/latest/configuration.html to pre-install ipywidgets will allow to remove the first

import piplite
await piplite.install('ipywidgets')

cell from the notebooks

@jasongrout
Copy link
Member Author

You might want to give xeus-python a try in this PR :) Using https://xeus-python-kernel.readthedocs.io/en/latest/configuration.html to pre-install ipywidgets will allow to remove the first

Good point. I hear that soon we'll be able to set up an environment soon anyway.

Are there any incompatibilities still with xeus-python vs ipykernel?

@jasongrout
Copy link
Member Author

@martinRenou - I tried switching to xeus-python, but it still seems to require the importing and using piplite (in the current doc build in CI). Is there something wrong with my config now?

@martinRenou
Copy link
Member

Are there any incompatibilities still with xeus-python vs ipykernel?

xeus-python is pretty close to ipykernel now, there are no big differences that I'm aware of. But note that ipykernel is not used in JupyterLite. The default kernel in JupyterLite is named pyolite, it's backed by pyodide, not ipykernel.

When it comes to differences between xeus-python and JupyterLite's default kernel "pyolite":

@martinRenou
Copy link
Member

@martinRenou - I tried switching to xeus-python, but it still seems to require the importing and using piplite (in the current doc build in CI). Is there something wrong with my config now?

Maybe it's a cache issue? Do you not see xeus-python in the JupyterLab launcher?

@jasongrout
Copy link
Member Author

Maybe it's a cache issue? Do you not see xeus-python in the JupyterLab launcher?

No, I don't. Here's the latest readthedocs CI build from this PR: https://ipywidgets--3491.org.readthedocs.build/en/3491/

Does the jupyterlite config look right? https://github.com/jupyter-widgets/ipywidgets/blob/d0e0c6f5b21d77322d0c0aac7db40500faf4f534/docs/source/jupyterlite_config.json

@jasongrout
Copy link
Member Author

@martinRenou - ah, got it working: I had to install jupyterlite-xeus-python

@jasongrout
Copy link
Member Author

Current state:

  • widgets won't render in xeus-python kernel (import ipywidgets does work, though)
  • there seems to be no way to install a dev install of ipywidgets in jupyterlite, so this is limited use for building latest docs?
  • the default kernel seems to still be pyolite - is there a way to disable the pyolite kernel and just use xeus-python?

@martinRenou
Copy link
Member

widgets won't render in xeus-python kernel (import ipywidgets does work, though)

I'll give it a try locally.

there seems to be no way to install a dev install of ipywidgets in jupyterlite, so this is limited use for building latest docs?

Using a dev installation might be tricky indeed, but probably not impossible. I wonder if we could make this case easier on the jupyterlite-xeus-python front.

the default kernel seems to still be pyolite - is there a way to disable the pyolite kernel and just use xeus-python?

Yes. I've done it in the ipycanvas documentation: https://github.com/martinRenou/ipycanvas/blob/master/docs/jupyter-lite.json#L6, you must tell jupyterlite-sphinx that the build directory is the local one https://github.com/martinRenou/ipycanvas/blob/master/docs/conf.py#L9 for it to find this config file.

@bollwyvl
Copy link
Contributor

bollwyvl commented Jun 22, 2022

there seems to be no way to install a dev install of ipywidgets in jupyterlite, so this is limited use for building latest docs?

yeah, that was the explicit goal of the build-time --piplite-wheels and piplite... i haven't been able to invest any effort in getting up to speed on the xeus kernels. maybe you could conda-build it? that seems extra heavy for a per-push docs build.

https://jupyterlite.readthedocs.io/en/latest/howto/python/wheels.html

In pyolite, it's now also theoretically possible to create an ipython profile, though the hard-coded path to /drive might behave in ways we don't expect... we might need some way to do additional mounts into emscripten.

@jasongrout
Copy link
Member Author

I rebased and consolidated a lot of commits to clean things up a bit.

Add back nbsphinx, with ipynb files explicitly using the jupyter_notebook renderer from nbsphinx.

Update ipywidgets in jupyterlite to 7.7.0

Add xeus-python config for jupyterlite
Experimental tagging of cells to the Widget List notebook for jupyterlite.
Revert "Experimental tagging of cells to the Widget List notebook for jupyterlite."

This reverts commit 29a3515.
Update docs conda env

Install the dev version of ipywidgets in readthedocs
@jasongrout jasongrout force-pushed the jlite2 branch 3 times, most recently from 2eb68c5 to 81c345b Compare July 6, 2022 23:22
@jasongrout jasongrout changed the title Initial jupyterlite implementation Package example notebooks in JupyterLite Jul 7, 2022
@jasongrout
Copy link
Member Author

jasongrout commented Jul 7, 2022

Interestingly, the output widget cannot capture exceptions in JupyterLite, even though it does in ipykernel:

from ipywidgets import Output
out = Output(layout={'border': '1px solid red'})
display(out)

with out:
    print('This output is captured')
    raise Exception('This exception is captured in ipykernel, but not in pyolite')

(#3417 tries to enable this in general, but it was surprising that output widgets behave like this anyway in JupyterLite)

@martinRenou @jtpio @bollwyvl - is this expected? If not, I can file an issue somewhere.

@bollwyvl
Copy link
Contributor

bollwyvl commented Jul 7, 2022

output widgets behave

Yeah... no two Output implementations appear to work the same way 😿. I don't know where I'd start looking into this, but having upstream testing our stuff will certainly give us a goal.

@jasongrout
Copy link
Member Author

I'm trying to skip some example notebook files. I have two attempts that are failing:

First, I tried giving an array of files to jupyterlite_contents option of jupyterlite_sphinx, which is translated into command-line --contents options, one for each entry. However, this merges the examples files and the images directory, where I'd like the images directory to be a subdirectory of the top-level directory rather than merged with it.

jupyterlite_contents = [
"examples/Beat Frequencies.ipynb",
...
"examples/images",
]

(i.e., the assets in examples/images are copied to the top-level filesystem, but I'd like them to actually be a subdirectory images).

I also tried going back to the jupyterlite_contents = "examples" option (i.e., --contents examples that preserved the examples/images subdirectory as a subdirectory, but also giving the following config in jupyter_lite_config.json:

  "LiteBuildConfig": {
    "ignore_contents": [
      "examples/Layout Example.ipynb",
      "examples/Layout Templates.ipynb",
      "examples/Variable Inspector.ipynb"
    ],
...

This preserved the examples/images directory as a subdirectory in JupyterLite, but it seems that the ignored_contents directory was ignored, i.e., I still see those files in my contents.

Any suggestions on how I can ignore three specific files in my contents directory?

@jtpio
Copy link
Member

jtpio commented Jul 8, 2022

Right the file hierarchy appears to be flatten when specifying multiple contents options (also noticed elsewhere). Probably this is an issue with jupyterlite-sphinx.

Any suggestions on how I can ignore three specific files in my contents directory?

I would expect this to work based on the reply in jupyterlite/jupyterlite#709 (comment).

Or maybe it's because it should be a list of regex and some characters must be escaped. For example like with the dynamic default: https://github.com/jupyterlite/jupyterlite/blob/fc5875f0ba8ed34c4d78f6c82d98691eab95ee8b/py/jupyterlite/src/jupyterlite/config.py#L183-L207

@bollwyvl
Copy link
Contributor

Tried out some stuff mentioned above over on #3517:

jasongrout/ipywidgets@jlite2...bollwyvl:ipywidgets:jlite2

@jasongrout
Copy link
Member Author

Tried out some stuff mentioned above over on #3517:

I merged Nick's changes into this PR. Thanks Nick!

@bollwyvl
Copy link
Contributor

Add JupyterLab Github extension

Good luck! I don't know if that's going to work out-of-the-box...

@jasongrout jasongrout marked this pull request as ready for review July 11, 2022 20:35
@jasongrout
Copy link
Member Author

I think this PR is at a good place to merge, and future iteration can be on a different PR. CC @ibdafna

Copy link
Member

@ibdafna ibdafna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excited for this one 😍

@ibdafna ibdafna merged commit c1510d4 into jupyter-widgets:master Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants