[Bug]: AssertionError in nbclient when jupyter-book build run from GHA
What happened, and what did you expect to happen?
I'm honestly not sure whether this should be reported to jupyter_core, jupyter_book or Sphinx, but as this is an attempt to run a jupiter-book build I'll start here.
I am trying to create a Github Action workflow that runs jupyter-book build. The workflow runs on one of Github's ubuntu-latest public runners.
The issue is when a build command is run, jupyter_core hits an assertion error in nbclient, which causes jupyter_core to raise an assertion error (see log output below).
The same set of commands runs without issue in my local devcontainer that runs on Debian 12.6.
Unfortunately I cannot get hold of the outputted sphinx log file because this error is causing my action step to be terminated before I can get to recovering any logs.
I have tried to force the build to continue using the following settings in my _config.yml
execute:
execute_notebooks: auto
timeout: -1
allow_errors: true
But to no avail (anything to allow me to try and get better logs).
I have also tried increasing verbosity whilst running a build, but it still fails immediately after hitting the first ipynb file.
Has anyone successfully run this in a Github Action environment before? I'm guessing this software is not optimized for CI environments?
What version of Jupyter Book are you running?
1.0.4.post1
What Operating System are you using?
Linux
Relevant log output
reading sources... [ 12%] create_features_for_expression
/home/runner/work/foo/foo/create_features_for_expression.ipynb: Executing notebook using local CWD [mystnb]
Exception occurred:
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/nbclient/client.py", line 504, in _async_cleanup_kernel
assert self.km is not None
^^^^^^^^^^^^^^^^^^^
AssertionError
The full traceback has been saved in /tmp/sphinx-err-ezp5sbw6.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/jupyter_core/utils/__init__.py", line 154, in wrapped
asyncio.get_running_loop()
RuntimeError: no running event loop
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/jupyter_book/sphinx.py", line 167, in build_sphinx
app.build(force_all, filenames)
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/sphinx/application.py", line 378, in build
self.builder.build_update()
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 297, in build_update
self.build(to_build,
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 318, in build
updated_docnames = set(self.read())
^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 425, in read
self._read_serial(docnames)
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 477, in _read_serial
self.read_doc(docname)
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 536, in read_doc
publisher.publish()
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/docutils/core.py", line 234, in publish
self.document = self.reader.read(self.source, self.parser,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/sphinx/io.py", line 106, in read
self.parse()
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/docutils/readers/__init__.py", line 76, in parse
self.parser.parse(self.input, document)
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/myst_nb/sphinx_.py", line 152, in parse
with create_client(
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/myst_nb/core/execute/base.py", line 79, in __enter__
self.start_client()
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/myst_nb/core/execute/direct.py", line 40, in start_client
result = single_nb_execution(
^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/jupyter_cache/executors/utils.py", line 58, in single_nb_execution
executenb(
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/nbclient/client.py", line 1319, in execute
return NotebookClient(nb=nb, resources=resources, km=km, **kwargs).execute()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/jupyter_core/utils/__init__.py", line 158, in wrapped
return loop.run_until_complete(inner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/nbclient/client.py", line 693, in async_execute
async with self.async_setup_kernel(**kwargs):
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/contextlib.py", line 231, in __aexit__
await self.gen.athrow(typ, value, traceback)
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/nbclient/client.py", line 660, in async_setup_kernel
await self._async_cleanup_kernel()
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/nbclient/client.py", line 504, in _async_cleanup_kernel
assert self.km is not None
^^^^^^^^^^^^^^^^^^^
AssertionError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.11.12/x64/bin/jupyter-book", line 8, in <module>
sys.exit(main())
^^^^^^
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/click/core.py", line 1442, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/click/core.py", line 1363, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/click/core.py", line 1830, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/click/core.py", line 1226, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/click/core.py", line 794, in invoke
return callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/jupyter_book/cli/main.py", line 317, in build
builder_specific_actions(
File "/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/jupyter_book/cli/main.py", line 528, in builder_specific_actions
raise RuntimeError(_message_box(msg, color="red", doprint=False)) from result
RuntimeError:
===============================================================================
There was an error in building your book. Look above for the cause.
===============================================================================
Error: The operation was canceled.
I am facing the same issue. Have you found any solution in the meantime?