Skip to content

Bundle Ruff for Python codegen formatting#166

Open
hardbyte wants to merge 1 commit into
mainfrom
bundled-python-formatter
Open

Bundle Ruff for Python codegen formatting#166
hardbyte wants to merge 1 commit into
mainfrom
bundled-python-formatter

Conversation

@hardbyte

@hardbyte hardbyte commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Format generated Python with a bundled dprint Ruff wasm artifact instead of shelling out to a local ruff binary
  • Add a small wasmi-based host for the dprint v3 formatter ABI with checksum validation
  • Update CLI tests/docs/CI now that Python codegen no longer depends on ruff being on PATH

Validation

  • cargo fmt --all
  • SQLX_OFFLINE=true cargo clippy --all-targets --all-features -- -D warnings
  • SQLX_OFFLINE=true cargo build --workspace
  • cargo test -p reflectapi python_formatter --features codegen
  • cargo test -p reflectapi-cli python_format
  • cargo run -p reflectapi-cli --quiet -- codegen --language python --schema reflectapi-demo/reflectapi.json --output /tmp/opencode/reflectapi-wasm-python-final --python-package-name api_client --python-sync --format=true && ruff format --check /tmp/opencode/reflectapi-wasm-python-final

Notes

  • cargo test was also run; unrelated demo run snapshots failed due JSON field ordering drift in run__json/run__msgpack, so no snapshot updates were included.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3338920c38

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const GENERATED_FILENAME: &str = "generated.py";

pub fn format_python_code(code: &str) -> Result<String> {
let mut formatter = RuffWasmFormatter::new()?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reuse the bundled formatter across generated files

For package/directory generation, render_python_file is called once per module plus support files, but each call reaches this function and recompiles/instantiates the 4 MB Ruff Wasm module (and re-hashes it) from scratch. Schemas with many namespaces will therefore pay the full Wasm startup cost hundreds of times during one codegen -l python -f run; keep one formatter/module for the generation pass or cache the compiled module so formatting scales with file count rather than repeated Wasm compilation.

Useful? React with 👍 / 👎.

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

📖 Documentation Preview: https://reflectapi-docs-preview-pr-166.partly.workers.dev

Updated automatically from commit aa1dee1

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.

1 participant