Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: check-json
- id: end-of-file-fixer
repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
- hooks:
- args:
- --in-place
Expand All @@ -22,10 +22,10 @@ repos:
- --ignore-init-module-imports
id: autoflake
repo: https://github.com/myint/autoflake
rev: v2.3.1
rev: v2.3.3

- repo: https://github.com/asottile/reorder-python-imports
rev: v3.14.0
rev: v3.16.0
hooks:
- args:
- --py37-plus
Expand All @@ -35,32 +35,32 @@ repos:
- --py37-plus
id: pyupgrade
repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
rev: v3.21.2
- hooks:
- id: black
repo: https://github.com/psf/black
rev: 25.1.0
rev: 26.3.1
- hooks:
- id: blacken-docs
repo: https://github.com/asottile/blacken-docs
rev: 1.19.1
rev: 1.20.0

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.14.0
rev: v2.16.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '2']

- hooks:
- id: blackdoc
repo: https://github.com/keewis/blackdoc
rev: v0.3.9
rev: v0.4.6
- hooks:
- id: commitizen
stages:
- commit-msg
repo: https://github.com/commitizen-tools/commitizen
rev: v4.2.1
rev: v4.13.9

- repo: https://github.com/crate-ci/typos
rev: v1
Expand Down
26 changes: 6 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,13 @@ This example minimizes multiple files and searches for sets which have 2 common
>>> from pprint import pprint
>>> from pysource_minimize._minimize import minimize_all
>>> sources = {
... Path(
... "a.py"
... ): """\
... Path("a.py"): """\
... l={1,81894,9874,89228,897985,897498,9879,9898}
... """,
... Path(
... "b.py"
... ): """\
... Path("b.py"): """\
... l={5,81894,9274,89218,897985,897298,9879,9898}
... """,
... Path(
... "c.py"
... ): """\
... Path("c.py"): """\
... l={0,81894,9874,89218,897985,897498,9879,9298}
... """,
... }
Expand All @@ -90,7 +84,6 @@ This example minimizes multiple files and searches for sets which have 2 common
... and all(isinstance(s, set) for s in sets)
... and len(set.intersection(*sets)) >= 2
... )
...
>>> pprint(minimize_all(sources, checker=check))
{PosixPath('a.py'): None,
PosixPath('b.py'): 'l = {81894, 0}',
Expand All @@ -115,19 +108,13 @@ The worst that can happen here is that *pysource-minimize* finds another example
>>> from pprint import pprint
>>> from pysource_minimize._minimize import minimize_all
>>> sources = {
... Path(
... "a.py"
... ): """\
... Path("a.py"): """\
... l={1,81894,9874,89228,897985,897498,9879,9898}
... """,
... Path(
... "b.py"
... ): """\
... Path("b.py"): """\
... l={5,81894,9274,89218,897985,897298,9879,9898}
... """,
... Path(
... "c.py"
... ): """\
... Path("c.py"): """\
... l={0,81894,9874,89218,897985,897498,9879,9298}
... """,
... }
Expand All @@ -151,7 +138,6 @@ The worst that can happen here is that *pysource-minimize* finds another example
... and len(result := set.intersection(*sets)) >= 2
... and 0 not in result
... )
...
>>> pprint(minimize_all(sources, checker=check))
{PosixPath('a.py'): None,
PosixPath('b.py'): 'l = {81894, 89218}',
Expand Down
1 change: 0 additions & 1 deletion src/pysource_minimize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from ._minimize import minimize_all
from ._minimize_base import StopMinimization


__all__ = ("minimize", "minimize_all", "CouldNotMinimize", "StopMinimization")


Expand Down
1 change: 0 additions & 1 deletion src/pysource_minimize/_minimize_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import List
from typing import Union


TESTING = False


Expand Down
1 change: 0 additions & 1 deletion src/pysource_minimize/_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys


if sys.version_info >= (3, 9):
from ast import unparse
else:
Expand Down
26 changes: 8 additions & 18 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def test_minimize_multiple_files():
files,
track="KeyError",
minimize=["bug.py", "var_a.py"],
expected_output=snapshot(
"""\
expected_output=snapshot("""\
You can support my work by sponsoring me on GitHub ❤ github.com/sponsors/15r10nk


Expand All @@ -107,8 +106,7 @@ def test_minimize_multiple_files():
pysource-minimize to improve further.

original files restored
"""
),
"""),
expected_files=snapshot("<unchanged>"),
)

Expand All @@ -126,8 +124,7 @@ def test_format():
files,
track="sum 100",
extra_args=["--format", "-w"],
expected_output=snapshot(
"""\
expected_output=snapshot("""\
You can support my work by sponsoring me on GitHub ❤ github.com/sponsors/15r10nk


Expand All @@ -154,11 +151,8 @@ def test_format():
pysource-minimize to improve further.

minimized files saved
"""
),
expected_files=snapshot(
{
"bug.py": """\
"""),
expected_files=snapshot({"bug.py": """\
very_long_name = 10
l = [
very_long_name,
Expand All @@ -173,9 +167,7 @@ def test_format():
very_long_name,
]
print("sum", sum(l))
"""
}
),
"""}),
)


Expand All @@ -189,12 +181,10 @@ def test_no_track():
minimize_files(
files,
track="bbbb",
expected_output=snapshot(
"""\
expected_output=snapshot("""\
I don't know what you want to minimize for.
'bbbb' is not a string which in the stdout/stderr of 'python bug.py'
"""
),
"""),
expected_files=snapshot("<unchanged>"),
)

Expand Down
12 changes: 3 additions & 9 deletions tests/test_minimize_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@

def test_minimize_all():
files = {
Path(
"bug1.py"
): """\
Path("bug1.py"): """\
a=1+2+3
""",
Path(
"bug2.py"
): """\
Path("bug2.py"): """\
print(d[a],"b")
""",
Path(
"bug3.py"
): """\
Path("bug3.py"): """\
x=2
""",
}
Expand Down
1 change: 0 additions & 1 deletion tests/test_needle.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from pysource_minimize import minimize
from pysource_minimize._minimize import unparse


sample_dir = Path(__file__).parent / "needle_samples"

sample_dir.mkdir(exist_ok=True)
Expand Down
Loading