pychd-pyfuzz 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,172 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+
162
+ **/logging.conf
163
+ .envrc
164
+
165
+ # Local Claude Code session state
166
+ .claude/
167
+
168
+ # Codex review scratch (transient, do not commit)
169
+ .codex
170
+
171
+ # Local PNG previews (SVGs are the committed source of truth)
172
+ assets/*.png
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: pychd-pyfuzz
3
+ Version: 0.1.0
4
+ Summary: Random syntactically-valid Python source generator — produces never-published code for contamination-free decompiler benchmarking
5
+ Author-email: 卍diohabara卍 <diohabara@users.noreply.github.com>
6
+ Requires-Python: >=3.14
7
+ Description-Content-Type: text/markdown
8
+
9
+ # pychd-pyfuzz
10
+
11
+ Random, syntactically-valid Python source generator. Built to feed
12
+ contamination-free benchmarks for `pychd` (the Python `.pyc`
13
+ decompiler) and any other decompiler that wants the same.
14
+
15
+ Every sample is constructed directly from `ast.AST` nodes (not text
16
+ templates), so it is — by construction — a code path that has never
17
+ appeared anywhere on the internet and cannot be in any LLM's training
18
+ data. Pair with `pychd-pyobf` (which strips identifiers + constants
19
+ from compiled `.pyc`) for the strongest available contamination
20
+ guarantee.
21
+
22
+ See the main [pychd README](https://github.com/diohabara/pychd) for
23
+ the broader story.
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pip install pychd-pyfuzz
29
+ ```
30
+
31
+ ## Use
32
+
33
+ ```bash
34
+ # 100 samples targeting Python 3.14:
35
+ pychd-pyfuzz generate --target 3.14 --count 100 --seed 0 --out /tmp/fuzz/
36
+ ```
37
+
38
+ Each emitted `.py` file is accompanied by a sidecar `.tags.json` with
39
+ the syntactic-feature tags the sample actually exercised (`match`,
40
+ `try_star`, `walrus`, `fstring`, `type_params`, …) so downstream
41
+ benchmarks can break recovery rates out by feature.
42
+
43
+ ## Status
44
+
45
+ Pre-release. API and CLI are still evolving with the parent project.
@@ -0,0 +1,37 @@
1
+ # pychd-pyfuzz
2
+
3
+ Random, syntactically-valid Python source generator. Built to feed
4
+ contamination-free benchmarks for `pychd` (the Python `.pyc`
5
+ decompiler) and any other decompiler that wants the same.
6
+
7
+ Every sample is constructed directly from `ast.AST` nodes (not text
8
+ templates), so it is — by construction — a code path that has never
9
+ appeared anywhere on the internet and cannot be in any LLM's training
10
+ data. Pair with `pychd-pyobf` (which strips identifiers + constants
11
+ from compiled `.pyc`) for the strongest available contamination
12
+ guarantee.
13
+
14
+ See the main [pychd README](https://github.com/diohabara/pychd) for
15
+ the broader story.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ pip install pychd-pyfuzz
21
+ ```
22
+
23
+ ## Use
24
+
25
+ ```bash
26
+ # 100 samples targeting Python 3.14:
27
+ pychd-pyfuzz generate --target 3.14 --count 100 --seed 0 --out /tmp/fuzz/
28
+ ```
29
+
30
+ Each emitted `.py` file is accompanied by a sidecar `.tags.json` with
31
+ the syntactic-feature tags the sample actually exercised (`match`,
32
+ `try_star`, `walrus`, `fstring`, `type_params`, …) so downstream
33
+ benchmarks can break recovery rates out by feature.
34
+
35
+ ## Status
36
+
37
+ Pre-release. API and CLI are still evolving with the parent project.
@@ -0,0 +1,24 @@
1
+ """pychd_pyfuzz — random syntactically-valid Python source generator.
2
+
3
+ Public API:
4
+
5
+ * :class:`Fuzzer` — construct with a target version + seed, call
6
+ :meth:`Fuzzer.generate` or :meth:`Fuzzer.generate_batch`.
7
+ * :class:`Sample` — dataclass returned by ``generate`` carrying the
8
+ source text, the syntactic-feature tags it exercised, the target
9
+ version, the seed, and the batch index.
10
+ * :class:`TagSet` — lower-level: the mutable tag accumulator
11
+ builders write into. End users rarely touch this directly.
12
+
13
+ The CLI entry point is :func:`pychd_pyfuzz.cli.main` (registered as
14
+ the ``pychd-pyfuzz`` console script).
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from .generator import Fuzzer, Sample
20
+ from .tags import TagSet
21
+
22
+ __version__ = "0.1.0"
23
+
24
+ __all__ = ["Fuzzer", "Sample", "TagSet", "__version__"]
@@ -0,0 +1,117 @@
1
+ """``pychd-pyfuzz`` command-line entry point.
2
+
3
+ Subcommands:
4
+
5
+ * ``pychd-pyfuzz generate`` — write N samples to a directory, one
6
+ ``.py`` per sample, each accompanied by a ``.tags.json`` sidecar.
7
+ * ``pychd-pyfuzz emit`` — print a single sample to stdout (no
8
+ sidecar). Handy for ad-hoc inspection.
9
+
10
+ The CLI is deliberately thin; library users should call
11
+ :class:`pychd_pyfuzz.Fuzzer` directly.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import argparse
17
+ import json
18
+ import sys
19
+ from pathlib import Path
20
+
21
+ from .generator import Fuzzer, Sample
22
+
23
+
24
+ def _parse_version(s: str) -> tuple[int, int]:
25
+ parts = s.split(".")
26
+ if len(parts) != 2:
27
+ raise argparse.ArgumentTypeError(f"--target must be MAJOR.MINOR (got {s!r})")
28
+ try:
29
+ return (int(parts[0]), int(parts[1]))
30
+ except ValueError as e:
31
+ raise argparse.ArgumentTypeError(str(e)) from e
32
+
33
+
34
+ def _write_sample(sample: Sample, out_dir: Path, stem: str) -> None:
35
+ out_dir.mkdir(parents=True, exist_ok=True)
36
+ py_path = out_dir / f"{stem}.py"
37
+ tags_path = out_dir / f"{stem}.tags.json"
38
+ py_path.write_text(sample.source)
39
+ tags_path.write_text(
40
+ json.dumps(
41
+ {
42
+ "target": f"{sample.target[0]}.{sample.target[1]}",
43
+ "seed": sample.seed,
44
+ "index": sample.index,
45
+ "length": sample.length,
46
+ "tags": sample.tags,
47
+ },
48
+ indent=2,
49
+ )
50
+ )
51
+
52
+
53
+ def _cmd_generate(args: argparse.Namespace) -> int:
54
+ fuzzer = Fuzzer(
55
+ target=args.target,
56
+ seed=args.seed,
57
+ max_depth=args.max_depth,
58
+ max_top_items=args.max_top_items,
59
+ )
60
+ out_dir = Path(args.out)
61
+ out_dir.mkdir(parents=True, exist_ok=True)
62
+ written = 0
63
+ for sample in fuzzer.generate_batch(args.count):
64
+ stem = f"sample_{sample.index:04d}"
65
+ _write_sample(sample, out_dir, stem)
66
+ written += 1
67
+ print(
68
+ f"pychd-pyfuzz: wrote {written} samples (target={args.target[0]}."
69
+ f"{args.target[1]}, seed={args.seed}) to {out_dir}",
70
+ file=sys.stderr,
71
+ )
72
+ return 0
73
+
74
+
75
+ def _cmd_emit(args: argparse.Namespace) -> int:
76
+ fuzzer = Fuzzer(
77
+ target=args.target,
78
+ seed=args.seed,
79
+ max_depth=args.max_depth,
80
+ max_top_items=args.max_top_items,
81
+ )
82
+ sample = fuzzer.generate(index=0)
83
+ sys.stdout.write(sample.source)
84
+ if not sample.source.endswith("\n"):
85
+ sys.stdout.write("\n")
86
+ return 0
87
+
88
+
89
+ def main(argv: list[str] | None = None) -> int:
90
+ parser = argparse.ArgumentParser(prog="pychd-pyfuzz", description=__doc__)
91
+ sub = parser.add_subparsers(dest="cmd", required=True)
92
+
93
+ gen = sub.add_parser(
94
+ "generate",
95
+ help="write N samples to OUT_DIR as ``sample_NNNN.py`` + ``.tags.json``",
96
+ )
97
+ gen.add_argument("--target", type=_parse_version, default=(3, 14))
98
+ gen.add_argument("--count", type=int, default=10)
99
+ gen.add_argument("--seed", type=int, default=0)
100
+ gen.add_argument("--max-depth", type=int, default=3)
101
+ gen.add_argument("--max-top-items", type=int, default=6)
102
+ gen.add_argument("--out", type=Path, required=True)
103
+ gen.set_defaults(func=_cmd_generate)
104
+
105
+ emit = sub.add_parser("emit", help="print a single sample to stdout")
106
+ emit.add_argument("--target", type=_parse_version, default=(3, 14))
107
+ emit.add_argument("--seed", type=int, default=0)
108
+ emit.add_argument("--max-depth", type=int, default=3)
109
+ emit.add_argument("--max-top-items", type=int, default=6)
110
+ emit.set_defaults(func=_cmd_emit)
111
+
112
+ args = parser.parse_args(argv)
113
+ return args.func(args)
114
+
115
+
116
+ if __name__ == "__main__":
117
+ raise SystemExit(main())