-
Notifications
You must be signed in to change notification settings - Fork 4
Add Marimo project support with detection and parsing capabilities #35
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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,132 @@ | ||
| import os | ||
| import tempfile | ||
|
|
||
| import projspec | ||
| from projspec.proj.webapp import Marimo | ||
|
|
||
|
|
||
| # Sample marimo notebook content | ||
| MARIMO_NOTEBOOK = b"""import marimo | ||
|
|
||
| __generated_with = "0.18.4" | ||
| app = marimo.App() | ||
|
|
||
|
|
||
| @app.cell | ||
| def _(): | ||
| import pandas as pd | ||
| return (pd,) | ||
|
|
||
|
|
||
| @app.cell | ||
| def _(pd): | ||
| df = pd.DataFrame({"a": [1, 2, 3]}) | ||
| df | ||
| return (df,) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app.run() | ||
| """ | ||
|
|
||
| MARIMO_NOTEBOOK_ALT = b"""from marimo import App | ||
|
|
||
| app = App() | ||
|
|
||
|
|
||
| @app.cell | ||
| def _(): | ||
| print("Hello, marimo!") | ||
| return | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app.run() | ||
| """ | ||
|
|
||
| NOT_MARIMO = b"""import pandas as pd | ||
|
|
||
| def main(): | ||
| df = pd.DataFrame({"a": [1, 2, 3]}) | ||
| print(df) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| """ | ||
|
|
||
|
|
||
| def test_marimo_single_notebook(): | ||
| """Test detection of a single marimo notebook""" | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| # Create a marimo notebook | ||
| notebook_path = os.path.join(tmpdir, "notebook.py") | ||
| with open(notebook_path, "wb") as f: | ||
| f.write(MARIMO_NOTEBOOK) | ||
|
|
||
| proj = projspec.Project(tmpdir) | ||
| assert "marimo" in proj.specs | ||
| spec = proj.specs["marimo"] | ||
|
|
||
| # Should have server artifact | ||
| assert "server" in spec.artifacts | ||
| assert "notebook" in spec.artifacts["server"] | ||
|
|
||
| # Check the command | ||
| assert spec.artifacts["server"]["notebook"].cmd == [ | ||
| "marimo", | ||
| "run", | ||
| "notebook.py", | ||
| ] | ||
|
|
||
|
|
||
| def test_marimo_multiple_notebooks(): | ||
| """Test detection of multiple marimo notebooks""" | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| # Create multiple marimo notebooks | ||
| for name, content in [ | ||
| ("app1.py", MARIMO_NOTEBOOK), | ||
| ("app2.py", MARIMO_NOTEBOOK_ALT), | ||
| ]: | ||
| path = os.path.join(tmpdir, name) | ||
| with open(path, "wb") as f: | ||
| f.write(content) | ||
|
|
||
| proj = projspec.Project(tmpdir) | ||
| assert "marimo" in proj.specs | ||
| spec = proj.specs["marimo"] | ||
|
|
||
| # Should have nested artifacts for each notebook | ||
| assert isinstance(spec.artifacts["server"], dict) | ||
| assert "app1" in spec.artifacts["server"] | ||
| assert "app2" in spec.artifacts["server"] | ||
|
|
||
|
|
||
| def test_marimo_not_detected_for_regular_python(): | ||
| """Test that regular Python files are not detected as marimo""" | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| # Create a regular Python file | ||
| path = os.path.join(tmpdir, "script.py") | ||
| with open(path, "wb") as f: | ||
| f.write(NOT_MARIMO) | ||
|
|
||
| proj = projspec.Project(tmpdir) | ||
| assert "marimo" not in proj.specs | ||
|
|
||
|
|
||
| def test_marimo_match_requires_both_import_and_app(): | ||
| """Test that both import and App() are required for detection""" | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| # Create a file with just the import but no App | ||
| path = os.path.join(tmpdir, "partial.py") | ||
| with open(path, "wb") as f: | ||
| f.write(b"import marimo\n\nprint('hello')\n") | ||
|
|
||
| proj = projspec.Project(tmpdir) | ||
| # match() returns True (has import), but parse() should fail | ||
| # because there's no App pattern | ||
| assert "marimo" not in proj.specs | ||
|
|
||
|
|
||
| def test_marimo_spec_doc(): | ||
| """Test that spec_doc is set correctly""" | ||
| assert Marimo.spec_doc == "https://docs.marimo.io/" | ||
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 |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| "IntakeCatalog", | ||
| "DataPackage", | ||
| "PyScript", | ||
| "marimo", | ||
| ], | ||
| ) | ||
| def test_compliant(tmpdir, cls_name): | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.