diff --git a/Cargo.lock b/Cargo.lock index ed9d844..ceaabb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1022,7 +1022,7 @@ checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" [[package]] name = "ruff-format" -version = "0.5.0" +version = "0.5.1" dependencies = [ "pyo3", "ruff_python_formatter", diff --git a/Cargo.toml b/Cargo.toml index 109ab50..bad0eaf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ruff-format" -version = "0.5.0" +version = "0.5.1" edition = "2024" license = "MIT" readme = "README.md" diff --git a/README.md b/README.md index 951ba70..ea26ecf 100644 --- a/README.md +++ b/README.md @@ -15,17 +15,26 @@ pip install ruff-format ## Usage ```python -from ruff_format import format_string, is_valid_syntax +from ruff_format import format_string, is_valid_syntax, parse_code code = """ def hello( x,y, z ): print( x+y+z ) """ +# Check if code has valid syntax assert is_valid_syntax(code) +# Parse code (raises RuntimeError on syntax errors) +parse_code(code) + +# Format code (default line width: 80) formatted = format_string(code) print(formatted) + +# Format with a custom line width +formatted = format_string(code, line_width=120) +print(formatted) ``` ## Development diff --git a/pyproject.toml b/pyproject.toml index a21156f..af98f7a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,7 @@ build-backend = "maturin" [project] name = "ruff-format" +description = "Python bindings for the Ruff code formatter, built with Rust and PyO3." requires-python = ">=3.8" license = { text = "MIT" } classifiers = [ diff --git a/ruff_format.pyi b/ruff_format.pyi index 467ddb1..e9c0672 100644 --- a/ruff_format.pyi +++ b/ruff_format.pyi @@ -18,7 +18,7 @@ def is_valid_syntax(code: str) -> bool: True if the code has valid syntax, False otherwise. """ -def format_string(code: str, *, line_width: int) -> str: +def format_string(code: str, *, line_width: int = 80) -> str: """Format a Python code string using Ruff. Args: