Metadata-Version: 2.4
Name: pysource-minimize
Version: 0.8.0
Summary: minimize python source code
Project-URL: Documentation, https://github.com/15r10nk/pysource-minimize#readme
Project-URL: Issues, https://github.com/15r10nk/pysource-minimize/issues
Project-URL: Source, https://github.com/15r10nk/pysource-minimize
Author-email: Frank Hoffmann <15r10nk@polarbit.de>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.8
Requires-Dist: astunparse>=1.6.3; python_version < '3.9'
Provides-Extra: cli
Requires-Dist: black>=23.3.0; extra == 'cli'
Requires-Dist: click>=8.1.7; extra == 'cli'
Requires-Dist: rich>=12.6.0; extra == 'cli'
Description-Content-Type: text/markdown

[![pypi version](https://img.shields.io/pypi/v/pysource-minimize.svg)](https://pypi.org/project/pysource-minimize/)
![Python Versions](https://img.shields.io/pypi/pyversions/pysource-minimize)
![PyPI - Downloads](https://img.shields.io/pypi/dw/pysource-minimize)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/15r10nk)](https://github.com/sponsors/15r10nk)

# pysource-minimize

If you build a linter, formatter or any other tool which has to analyse python source code you might end up searching bugs in pretty large input files.

`pysource_minimize` is able to remove everything from the python source which is not related to the problem.

## CLI

You can use `pysource-minimize` from the command line like follow:

```bash
pysource-minimize --file bug.py --track "Assertion" -- python bug.py
```

This will run `python bug.py` and try to find the string "Assertion" in the output.
The `--file bug.py` gets minimized as long as "Assertion" is part of the output of the command.

> [!WARNING]
> Be careful when you execute code which gets minimized.
> It might be that some combination of the code you minimize erases your hard drive
> or does other unintended things.

![example](example.gif)



## API
Example:
``` pycon
>>> from pysource_minimize import minimize

>>> source = """
... def f():
...     print("bug"+"other string")
...     return 1+1
... f()
... """

>>> print(minimize(source, lambda new_source: "bug" in new_source))
"""bug"""

```
