Skip to content

fix: _isnotebook() recognises JupyterLite, and Colab by its module - #167

Closed
petercorke wants to merge 1 commit into
mainfrom
fix/isnotebook-jupyterlite
Closed

petercorke wants to merge 1 commit into
mainfrom
fix/isnotebook-jupyterlite

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Closes #166.

_isnotebook() in base/imageio.py only matched a shell class named Shell or ZMQInteractiveShell. It had no JupyterLite check, so Camera would take its desktop image-plane branch in the browser if the Pyodide shell has another name. It now returns True for sys.platform == "emscripten" (JupyterLite) and for google.colab in sys.modules (Colab), then falls back to the ZMQInteractiveShell test. This is the same logic RTB uses, and the same as spatialmath's environment() (rai-opensource/spatialmath-python#271, open); this could use that once it is released.

One behaviour change: a shell class that is merely named Shell outside Colab is no longer treated as a notebook.

Does this change numerical results or public behaviour? No numerical results change. Camera's image-plane reuse follows the notebook branch in JupyterLite where it may not have before. I have not checked what get_ipython().__class__.__name__ is in the MVTB Lite site, so I do not know whether it did before.

Tested: new tests/test_isnotebook.py (6 tests) with a fake get_ipython and patched sys.modules and sys.platform; no real notebook frontend is exercised. tests/test_image_io.py and tests/test_camera.py pass. ruff format reports imageio.py as unformatted at line 495, which is not part of this change.

This change was written with Claude Code (Claude Sonnet 5.5).

🤖 Generated with Claude Code

It matched a shell class named Shell or ZMQInteractiveShell and had no JupyterLite
check, so Camera took its desktop image-plane branch in the browser if the Pyodide
shell has another name. Test for emscripten and for google.colab first, as RTB does
and as spatialmath's environment() does (rai-opensource/spatialmath-python#271).

Closes #166

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 8 complexity · 0 duplication

Metric Results
Complexity 8
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke

Copy link
Copy Markdown
Owner Author

Closing: this was opened by mistake. The Issue (#166) stays open for discussion.

@petercorke petercorke closed this Nov 1, 2026
@petercorke
petercorke deleted the fix/isnotebook-jupyterlite branch November 1, 2026 07:02
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.

_isnotebook() does not recognise JupyterLite

1 participant