| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
📝 Walkthrough
WalkthroughAdds 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
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem🚥 Pre-merge checks | ✅ 2 | ❌ 1 ❌ Failed checks (1 warning)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. ❤️ ShareComment @coderabbitai help to get the list of available commands and usage tips. |
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)src/settings.rs (1)37-56: ⚠️ Potential issue | 🟠 Major
--compile-only doesn't actually terminate option parsing, contradicting its documented behavior.
The flag only sets a boolean at line 156, allowing lexopt to continue parsing subsequent args as options. This breaks the documented "terminates option list" behavior specified at line 105 of USAGE_STRING (e.g., --compile-only -V file.py will trigger version() instead of treating -V as a filename). The fix should return early and collect remaining raw args as files, matching the pattern used by -c and -m flags. This also eliminates the unnecessary compile_only field and related conditional branches.
In `@src/lib.rs`: - Around line 292-295: The current --compile-only path returns Ok(()) when the files list is empty; change it to signal a usage error so the process exits non‑zero: in the block that checks files.is_empty() (the --compile-only handling), replace the Ok(()) return with a non‑zero failure return (e.g., return an Err or otherwise cause process exit code 1) and keep the eprintln! message; update the surrounding function’s error/return handling (the main or run function that contains files.is_empty()) so the non‑zero exit propagates to the process.
Sorry, something went wrong.
|
@Jawfish Could you tell me more about the motivation of this optimization? Usually compile step is very fast, as you described, only 55ms. Are you compiling massive amount of files before running? |
Sorry, something went wrong.
This isn't meant as a micro-optimization of compile time (55ms is totally fine). The motivation is to have a supported, side-effect-free "compile check" mode for CI/pre-commit: validate that a set of .py files reaches the compiler successfully. This brings CPython's python -m py_compile/compileall workflow as a first-class CLI flag without writing .pyc files. This flow is useful because linters and parsers are not a perfect substitute for "run the compiler". For example, Ruff doesn't catch this: [i for i in (j := [1, 2, 3])]
# SyntaxError: assignment expression cannot be used in a comprehension iterable expressionThis is a compile-phase semantic check that occurs after parsing succeeds. Linters cover many cases with lint rules, but not all compile-phase validations. |
Sorry, something went wrong.
Have you tried to add this to CPython? |
Sorry, something went wrong.
|
Could you share more what python -m py_compile cannot support but --compile-only can support? If -m py_compile is enough, rustpython -m py_compile must also fit. (otherwise it is a bug) |
Sorry, something went wrong.
@youknowone to be clearer: the motivation is specifically to guarantee compilation with no .pyc file side effects, which rustpython -m py_compile produces.
@fanninpm Per the project goals: "Full Python-3 environment entirely in Rust (not CPython bindings)". A --compile-only flag would provide compile validation as a first-class RustPython feature, without side effects. |
Sorry, something went wrong.
|
Edit: I withdraw this comment Thank you for your patient. So what you need is compiling python code and see the error output, but not actually creating .pyc, right? Because rustpython binary is a python binary, I don't think adding a niche subcommand there is ideal. Here are my 2 suggestions, which are independent each other.
|
Sorry, something went wrong.
|
@Jawfish If you don't care about performance, actually python -m dis also compile it |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Adds a --compile-only CLI flag that compiles Python files without executing them.
Use case: Catch compile-phase errors (syntax errors, duplicate parameters, break outside loop, etc.) without the overhead of execution. This is similar to python -m py_compile but leverages RustPython.
Usage:
Exits 0 on success, 1 if any file fails to compile. Errors are printed to stderr.
rustpython -m py_compile works, but there are differences:
Implementation:
Note: also documents existing --install-pip [ensurepip|get-pip] flag which was missing from help text.
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.