mirror of
https://github.com/astral-sh/ruff
synced 2026-01-11 00:24:13 -05:00
7359e862c1b82b3ce86e8b2d8eaff4aa11c76e50
rust-python-linter
A performance-focused, Pyflakes-inspired Python linter, written in Rust.
Features:
- Python 3.8 compatibility
- ESLint-inspired cache semantics
- TypeScript
-inspired
--watchsemantics
Installation
Available as rust-python-linter on PyPI:
pip install rust-python-linter
Usage
To run the linter, try any of the following:
rust_python_linter path/to/code/to/check.py
# ...or...
rust_python_linter path/to/code/
# ...or...
rust_python_linter path/to/code/*.py
You can also run in --watch mode to automatically re-run the linter on-change with, e.g.:
rust_python_linter path/to/code/ --watch
Development
As the name suggests, rust-python-linter is implemented in Rust:
cargo fmt
cargo clippy
cargo run resources/test/src
Deployment
rust-python-linter is released for Python using maturin:
maturin publish --skip-existing --target x86_64-apple-darwin
maturin publish --skip-existing --target aarch64-apple-darwin
Benchmarking
First, clone CPython. It's a large and diverse Python codebase,
which makes it a good target for benchmarking. Note that we clone v3.9, as RustPython doesn't yet
support pattern matching, which was introduced in v3.10.
git clone --branch 3.9 https://github.com/python/cpython.git resources/test/cpython
Next, to benchmark the release build:
cargo build --release
hyperfine --warmup 5 \
"./target/release/rust_python_linter ./resources/test/cpython/ --no-cache" \
"./target/release/rust_python_linter ./resources/test/cpython/"
Benchmark 1: ./target/release/rust_python_linter ./resources/test/cpython/ --no-cache
Time (mean ± σ): 353.6 ms ± 7.6 ms [User: 2868.8 ms, System: 171.5 ms]
Range (min … max): 344.4 ms … 367.3 ms 10 runs
Benchmark 2: ./target/release/rust_python_linter ./resources/test/cpython/
Time (mean ± σ): 59.6 ms ± 2.5 ms [User: 36.4 ms, System: 345.6 ms]
Range (min … max): 55.9 ms … 67.0 ms 48 runs
Languages
Rust
96.1%
Python
2.6%
TypeScript
0.9%
RenderScript
0.2%
Shell
0.1%