◐ Shell
clean mode source ↗

add `--compile-only` flag for syntax/compile validation by Jawfish · Pull Request #6943 · RustPython/RustPython

📝 Walkthrough

Walkthrough

Adds a compile-only execution mode: a new RunMode::CompileOnly(Vec<String>), a --compile-only CLI flag, argument parsing to produce that mode, and runtime handling that compiles listed files without executing them, returning exit code 1 on any compilation/read error.

Changes

Cohort / File(s) Summary
Runtime / CLI
src/lib.rs, src/settings.rs
Added RunMode::CompileOnly(Vec<String>); CLI flag --compile-only emits that mode; runtime run_rustpython now handles CompileOnly by reading and attempting to compile each file, printing per-file errors and returning exit code 1 on any failure; sys.path initialization treats CompileOnly like Script/InstallPip.
Tests
src/lib.rs (tests module), tests/*
Added unit tests covering successful compilation and failure cases (syntax error, duplicate parameters, invalid control flow), and test coverage for compile-only CLI behavior.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant CLI
participant Runner
participant FS as Filesystem
participant VM
CLI->>Runner: parse args -> RunMode::CompileOnly(files)
Runner->>FS: read(file1)
FS-->>Runner: content or read error
Runner->>VM: compile_with_opts(content)
VM-->>Runner: success or compile error
alt compile error
Runner->>CLI: print stderr, mark failure
else success
Runner->>CLI: continue to next file
end
Note over Runner,CLI: final result -> exit code 0 (all success) or 1 (any failure)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • pythonrun #6643: Refactors/exposes compile/run helpers used by this PR to perform file compilation.

Poem

🐰 I nibble bytes and hop on keys,
I check the code with careful ease.
No running now—just tidy sights,
I catch the bugs in silent nights.
Compile-only—hooray, no fright!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a --compile-only flag for syntax validation. It is specific, directly related to the core feature, and accurately represents the primary objective of the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.