-
Notifications
You must be signed in to change notification settings - Fork 761
Prevent accidental overwrites and converter for non-marimo Python scripts #5686
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Oh no, potentially closed by #5677 |
|
There's actually a fair bit of other logic in here. Will do a review on merge res if you want to keep it open |
|
if it makes the review easier, i'm happy to break into two separate PRs:
|
|
Most of the logic is in the second commit for adding a new converter. The error is just adding another violation that we error on inside marimo edit. |
|
I think splitting these out make sense, will make the merge res easier |
|
Thanks @manzt @dmadisetti. Simple is fine by me. It was a bit of a surprise when it happened. As an FYI, I could see folks wanting to be able to bulk convert a directory of |
|
Thanks @willingc, hope you didn't lose any important files 😬 |
|
calling it |
|
@dmadisetti I didn't lose anything since everything is under version control. I agree with @mscolnick "unknown python script" is odd phrasing to a user. If everything is a Ultimately, I would love to see (some of which you already have):
|
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.
I love the effort here. I would be fine with a simple warning that the .py file does not include marimo notebook code. See this link on creating or converting... would be fine short term.
I don't think these changes introduce any new interactive code paths, unless I'm misunderstanding. Are you referring to improving the existing overwrite confirmation to be non-blocking in non-TTY contexts? |
Yes, related to this PR, but yes nothing this code explicitly touches |
Updates docs to reflect #5686's new `marimo convert` support for `.py` files, including automatic py:percent format detection when jupytext is available.
Updates docs to reflect #5686's new `marimo convert` support for `.py` files, including automatic py:percent format detection when jupytext is available.
Updates docs to reflect #5686's new `marimo convert` support for `.py` files, including automatic py:percent format detection when jupytext is available.
Updates docs to reflect #5686's new `marimo convert` support for `.py` files, including automatic py:percent format detection when jupytext is available.
Currently, opening an unrecognized Python script with `marimo edit script.py` overwrites the file contents with an empty marimo notebook, causing data loss. This change detects non-marimo Python scripts when the parser encounters Python code that doesn't follow the marimo notebook format, prompting the users to `marimo convert` the file first.
Enable `marimo convert script.py` to convert regular Python scripts.
Co-authored-by: Akshay Agrawal <akshay@marimo.io>
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.
Cool! See comment. I can still follow up in a PR, but let's decide and get it in before next release.
I'm happy with this PR, but LMK if you have thoughts and want to adjust the flow here
| ) from None | ||
|
|
||
| # Only show the tip if we're in an interactive terminal | ||
| if status == "invalid" and sys.stdin.isatty(): |
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.
Thanks for the rebase.
This might be dead code now? Either way the ideal behavior for molab is:
if not tty and invalid: continue # as normal (regardless of .py ending)
If this is too dangerous, we can hide behind a another flag. An auto convert flag could be reasonable
if invalid and autoconvert: convert and continue
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.
The above condition is:
if status == "invalid" and filename.endswith(".py"):I assume non-Python files could also result in an invalid notebook status, making this code not dead in that context? I don't know the molab context well enough and trust whatever you think.
Previously,
marimo edit script.pywould silently overwrite any Python file, potentially destroying user code (link).#5677 introduced a prompt asking users to confirm before overwriting invalid files. This PR takes a stronger stance by making
marimo editerror for non-marimo Python files and providing a conversion path.It introduces two key changes:
Protection against accidental overwrites:
marimo editnow errors when attempting to open a non-marimo Python file, rather than prompting for confirmation. Users are directed to usemarimo convertinstead.Python script conversion support:
marimo convert script.pynow supports converting regular Python scripts to marimo notebooks. The converter:if __name__ == "__main__":blocks into_main_()functions to maintain marimo's variable scopingImportantly the notebook pipeline reuses the ipynb converter transformations for multiple cells.
Running
marimo edit regular_script.pynow shows:Error: Python script not recognized as a marimo notebook. Tip: Try converting with marimo convert regular_script.py -o regular_script_nb.py then open with marimo edit regular_script_nb.py