Metadata-Version: 2.4
Name: prune-source
Version: 0.1.6
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Rust
Classifier: Topic :: Software Development :: Libraries :: Python Modules
License-File: LICENSE
License-File: licenses/ruff.LICENSE
Summary: Prune Python function bodies before compiling abstract syntax trees.
Keywords: ast,parser,python,ruff,static-analysis
Author-email: Timothée Mazzucotelli <dev@pawamoy.fr>
License-Expression: ISC
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# prune-source

`prune-source` is a small Rust/Ruff accelerator for static API analysis. It lexes Python source and
removes function implementation suites that an API visitor does not need, allowing CPython to
construct and walk a much smaller abstract syntax tree. It does not build an intermediate Ruff AST.

```bash
pip install prune-source
```

```python
import ast

from prune_source import prune_source

source = "def answer() -> int:\n    return 42\n"
pruned = prune_source(source)
tree = compile(
    source if pruned is None else pruned,
    "example.py",
    "exec",
    ast.PyCF_ONLY_AST,
    optimize=1,
)
```

The pruner preserves function signatures, decorators, docstrings, class bodies, and class
`__init__` implementations. Other function suites are replaced by `pass` while physical line
layout is retained. Removed multiline content is collapsed to empty lines rather than padded with
spaces; for indented suites, the `pass` remains on the original final implementation line so
definition end-line metadata stays stable. Nested function suites inside `__init__` are pruned as
well.

The input is expected to be valid for the Python interpreter that will compile it. The lexer does
not perform grammar or version validation. `prune_source` returns `None` when there is nothing to
prune; callers should compile their original source in that case.

The pruner uses Ruff's published parser crate to read token ranges and flags without constructing a syntax tree. Ruff's Rust API is unstable, so its component crates are pinned to the same version.

Building from source requires Rust 1.96 or newer.

