marimo icon indicating copy to clipboard operation
marimo copied to clipboard

Automatically import marimo as mo on markdown fail?

Open MartinBernstorff opened this issue 1 year ago • 9 comments

Describe the bug

image

Environment

{
  "marimo": "0.4.0",
  "OS": "Windows",
  "OS Version": "10",
  "Processor": "Intel64 Family 6 Model 106 Stepping 6, GenuineIntel",
  "Python Version": "3.10.9",
  "Binaries": {
    "Browser": "111.0.5563.147",
    "Node": "--"
  },
  "Requirements": {
    "click": "8.1.7",
    "importlib-resources": "missing",
    "jedi": "0.19.1",
    "markdown": "3.5.1",
    "pymdown-extensions": "10.7.1",
    "pygments": "2.17.2",
    "tomlkit": "0.12.4",
    "uvicorn": "0.29.0",
    "starlette": "0.37.2",
    "websocket": "missing",
    "typing-extensions": "4.7.1",
    "black": "23.12.0"
  }
}

Code to reproduce

No response

MartinBernstorff avatar Apr 18 '24 11:04 MartinBernstorff

You'll need to import marimo as mo first. Markdown is written with Python in marimo (mo.md).

akshayka avatar Apr 18 '24 12:04 akshayka

Ah, excellent! From an engineering perspective, it makes a lot of sense to have all cells be Python.

  • I expected that when I activated "view as markdown", the cell would just need markdown in it, and not depend on other Python state. Might just be habit from Jupyter.
  • To make this more user-friendly, we could:
    • Print a more user-friendly error (i.e. you still need to import mo), or
    • Automatically import marimo as mo when running as an mo

MartinBernstorff avatar Apr 18 '24 13:04 MartinBernstorff

(Feel free to close if you think no more work is needed here 👍 )

MartinBernstorff avatar Apr 18 '24 13:04 MartinBernstorff

Ah, excellent! From an engineering perspective, it makes a lot of sense to have all cells be Python.

  • I expected that when I activated "view as markdown", the cell would just need markdown in it, and not depend on other Python state. Might just be habit from Jupyter.

  • To make this more user-friendly, we could:

    • Print a more user-friendly error (i.e. you still need to import mo), or
    • Automatically import marimo as mo when running as an mo

I suppose one thing we could do is automatically add a cell that imports marimo as mo, if marimo hasn't already been imported.

akshayka avatar Apr 18 '24 13:04 akshayka

Should this functionality be extended to import any module on NameError?

wasimxyz avatar Apr 21 '24 02:04 wasimxyz

Maybe. I think any auto-importing may be too magical though; even auto-importing marimo.

akshayka avatar Apr 22 '24 15:04 akshayka

Most IDEs have an auto-import feature (mine auto-imports on save), I don't think it is too magical, especially for mo which is quite common

mscolnick avatar Apr 22 '24 21:04 mscolnick

Most IDEs have an auto-import feature (mine auto-imports on save), I don't think it is too magical, especially for mo which is quite common

Okay yea mine does too, good point. Where would the import go, new cell at the bottom of the file?

akshayka avatar Apr 22 '24 22:04 akshayka

Bottom of the file and new cell would be my opinion. I thought trying to merge with existing imports, but could cause noisy/unwanted re-renders.

mscolnick avatar Apr 23 '24 02:04 mscolnick

Implemented in #1404.

wasimxyz avatar Jun 06 '24 23:06 wasimxyz