-
Notifications
You must be signed in to change notification settings - Fork 34
Add support for Marimo notebooks #73
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8fe991f
feat: add Marimo integration files and tests, update dependencies, an…
N283T 08b87b5
feat: Improve Marimo integration by delaying widget display and retur…
N283T ae971a7
refactor: make marimo an optional dependency
N283T 44e087f
refactor: Consolidate Marimo display logic to use iframes and update …
N283T 62f3990
feat: update Marimo examples.
N283T a69f372
feat: update Marimo examples.
N283T 018fe7e
feat: Add `MolGrid.get_selection_state` for Marimo integration and up…
N283T 34f8c54
refactor: combine patch contexts in Marimo integration test
N283T 597da3c
refactor: improve Marimo integration by relocating grid overwrite war…
N283T ff3aeb0
docs: mention Marimo compatibility and add contributor
N283T File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,9 @@ dynamic = ["version"] | |
| [project.license] | ||
| file = "LICENSE" | ||
|
|
||
| [project.optional-dependencies] | ||
| marimo = ["marimo>=0.18.4"] | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to declare it as an optional dependency either, move to |
||
| [dependency-groups] | ||
| build = ["build", "watchfiles", "jupyterlab"] | ||
| tests = [ | ||
|
|
@@ -235,4 +238,4 @@ sequence = [{ ref = "style-check" }, { ref = "tests" }, { ref = "docs" }] | |
|
|
||
| [tool.poe.tasks.build] | ||
| help = "Builds the package" | ||
| cmd = "python -m build" | ||
| cmd = "python -m build" | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import marimo | ||
|
|
||
| __generated_with = "0.18.4" | ||
| app = marimo.App(width="medium") | ||
|
|
||
|
|
||
| @app.cell | ||
| def _(): | ||
| import marimo as mo | ||
| from rdkit import Chem | ||
| import mols2grid | ||
| import pandas as pd | ||
| from io import StringIO | ||
| return StringIO, mols2grid, pd | ||
|
|
||
|
|
||
| @app.cell | ||
| def _(): | ||
| smiles = """SMILES NAME | ||
| CCO Ethanol | ||
| CC(=O)O Acetic_acid | ||
| CCC Propane | ||
| C1=CC=CC=C1 Benzene | ||
| COC Dimethyl_ether | ||
| CCN Ethylamine | ||
| C(CO)O Ethylene_glycol | ||
| CCOCC Diethyl_ether | ||
| OC=O Formic_acid | ||
| CCOC(=O)C Ethyl_acetate | ||
| """ | ||
| return (smiles,) | ||
|
|
||
|
|
||
| @app.cell | ||
| def _(StringIO, pd, smiles): | ||
| df = pd.read_csv(StringIO(smiles), delimiter="\t") | ||
| df | ||
| return (df,) | ||
|
|
||
|
|
||
| @app.cell | ||
| def _(df, mols2grid): | ||
| mols2grid.display(df) | ||
| return | ||
|
|
||
|
|
||
| @app.cell | ||
| def _(mols2grid): | ||
| mols2grid.get_selection() | ||
| return | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app.run() |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
|
|
||
| import sys | ||
| import pytest | ||
| from unittest.mock import patch, MagicMock | ||
| import pandas as pd | ||
| from mols2grid import MolGrid | ||
| from mols2grid.utils import is_running_within_marimo | ||
|
|
||
| @pytest.fixture | ||
| def mock_marimo_module(): | ||
| with patch.dict(sys.modules, {"marimo": MagicMock()}): | ||
| yield | ||
|
|
||
| def test_is_running_within_marimo_true(mock_marimo_module): | ||
| assert is_running_within_marimo() is True | ||
|
|
||
| def test_is_running_within_marimo_false(): | ||
| # Ensure marimo is not in sys.modules for this test | ||
| with patch.dict(sys.modules): | ||
| if "marimo" in sys.modules: | ||
| del sys.modules["marimo"] | ||
| assert is_running_within_marimo() is False | ||
|
|
||
| def test_init_in_marimo_does_not_display(mock_marimo_module): | ||
| df = pd.DataFrame({"SMILES": ["C"]}) | ||
|
|
||
| # Mock IPython.display.display which is imported as display in molgrid.py | ||
| # We need to patch it where it is used, i.e., in mols2grid.molgrid | ||
| with patch("mols2grid.molgrid.display") as mock_display: | ||
| mg = MolGrid(df, smiles_col="SMILES") | ||
| mock_display.assert_not_called() | ||
|
|
||
| def test_display_in_marimo(mock_marimo_module): | ||
| df = pd.DataFrame({"SMILES": ["C"]}) | ||
| mg = MolGrid(df, smiles_col="SMILES") | ||
|
|
||
| # Mock marimo.Html and marimo.vstack | ||
| with patch("marimo.Html") as mock_html, \ | ||
| patch("marimo.vstack") as mock_vstack: | ||
|
|
||
| result = mg.display() | ||
|
|
||
| # Verify that an iframe is being rendered inside Html | ||
| mock_html.assert_called_once() | ||
| args, _ = mock_html.call_args | ||
| html_content = args[0] | ||
| assert "<iframe" in html_content | ||
| assert 'class="mols2grid-iframe"' in html_content | ||
|
|
||
| # Verify vstack was called with [widget, html] | ||
| mock_vstack.assert_called_once() | ||
| vstack_args = mock_vstack.call_args[0][0] | ||
| assert len(vstack_args) == 2 | ||
| assert vstack_args[0] == mg.widget | ||
| assert vstack_args[1] == mock_html.return_value | ||
|
|
||
| # Ensure the result is the return value of marimo.vstack | ||
| assert result == mock_vstack.return_value |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldn't repeat the
use_iframeblock below, instead do somethiing like this to keep it DRY: