Skip to content

fix(convert): AST-based __main__ guard (salvage of #10237, credit @vidigoat)#10284

Closed
Bartok9 wants to merge 1 commit into
marimo-team:mainfrom
Bartok9:top10/salvage-10237-convert-main-guard
Closed

fix(convert): AST-based __main__ guard (salvage of #10237, credit @vidigoat)#10284
Bartok9 wants to merge 1 commit into
marimo-team:mainfrom
Bartok9:top10/salvage-10237-convert-main-guard

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

This pull request was authored by a coding agent.

AI-assisted; human-reviewed line-by-line.

Summary

marimo convert (and related non-marimo script paths) used a naive string split on if __name__ == "__main__":. When that text appeared inside a string literal or comment, the cell was sliced mid-token and emitted as an unparsable blob.

This salvage rebases and re-lands @vidigoat's approach from #10237: detect a real top-level ast.If main-guard and rewrite only that statement. Also covers single-quoted and reversed comparisons.

Salvage of #10237 — full credit to @vidigoat.

Tests

uv run --python 3.13 --group test pytest tests/_convert/test_convert_non_marimo_python_script.py -q
# 19 passed, 1 skipped

Checklist

  • I have read the CLA — I have read the CLA Document and I hereby sign the CLA
  • Tests added/updated
  • AI-generated code reviewed by the human author

Avoids mangling cells when the guard text appears inside a string or
comment. Also handles single-quoted and reversed comparisons.

Based on work by @vidigoat in marimo-team#10237.

Co-authored-by: Vidit Patankar <vidit.patankar16@gmail.com>
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jul 22, 2026 10:54pm

Request Review

@Bartok9

Bartok9 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@dmadisetti

Copy link
Copy Markdown
Member

I think @vidigoat is actively working on this- could you hold off "salvaging". Please remember this for other contributors and at least ask first.

@dmadisetti dmadisetti closed this Jul 22, 2026
@Bartok9

Bartok9 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Absolutely — apologies for jumping in, @dmadisetti. @vidigoat should own this; I'll close this out so #10237 has a clear path. I'll ask first before picking up in-progress work going forward. Thanks for the nudge, and sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants