Repository navigation
feat(base): add environment() and move isnotebook out of the matplotlib block - #271
Open
petercorke wants to merge 1 commit into
Open
petercorke wants to merge 1 commit into
petercorke wants to merge 1 commit into
Conversation
…ib block isnotebook() lived inside graphics.py's matplotlib try-block, so it vanished when matplotlib was missing, and it reported False for Google Colab and JupyterLite. RTB, MVTB and bdsim each grew their own copy as a result. Add environment(), returning "terminal", "ipython", "jupyter", "colab" or "jupyterlite", in a new matplotlib-free module, and make isnotebook() a thin wrapper that is True for jupyter, colab and jupyterlite. smb.isnotebook is still exported. Tests use a faked get_ipython/sys.modules/sys.platform. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
isnotebook()lived insidegraphics.py's matplotlibtry:block, so it disappeared when matplotlib was not installed, and it returnedFalseon Google Colab and JupyterLite. RTB, MVTB and bdsim have each grown their own copy of the check as a result.spatialmath/base/_environment.py.environment()returns one of"terminal","ipython","jupyter","colab","jupyterlite".isnotebook()is now a thin wrapper,Trueforjupyter,colabandjupyterlite.smb.isnotebookis still exported, andsmb.environmentis new. Nothing in SMTB calledisnotebook().JupyterLab, classic Notebook, VS Code and Jupyter Desktop all report
"jupyter": they cannot be told apart reliably from inside the kernel, and how figures render depends on the matplotlib backend rather than the front end. The docstring says so.Behaviour change
isnotebook()now returnsTrueon Colab and JupyterLite (previouslyFalse).Testing
Full suite: 416 passed, 3 skipped (was 413 on current master). Black 23.10.0 clean on the touched files.
New
tests/base/test_environment.pycovers all five values plus an unknown shell. These tests are mocked only: a fakeget_ipython()and patchedsys.modules/sys.platformstand in for the real front ends. No real Jupyter, Colab or JupyterLite kernel is exercised in CI.Follow-ups (not in this PR)
RTB and MVTB can drop their private
_isnotebookcopies in favour of this once it lands.🤖 Generated with Claude Code