https://github.com/15r10nk/pysource-minimize
minimize python source code to find bugs more easily
https://github.com/15r10nk/pysource-minimize
code-generation codegenerator python testing
Last synced: 6 months ago
JSON representation
minimize python source code to find bugs more easily
- Host: GitHub
- URL: https://github.com/15r10nk/pysource-minimize
- Owner: 15r10nk
- License: mit
- Created: 2022-11-28T22:36:12.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-15T04:18:09.000Z (about 1 year ago)
- Last Synced: 2024-10-20T12:35:07.713Z (about 1 year ago)
- Topics: code-generation, codegenerator, python, testing
- Language: Python
- Homepage:
- Size: 801 KB
- Stars: 30
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[](https://pypi.org/project/pysource-minimize/)


[](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.
## 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"""```