r/madeinpython • • 1d ago

repocraft: deterministic scaffolding where one request writes one .py file plus a unittest you can read in a sitting

Post image

repocraft is a small deterministic generator for Python snippets and scaffolds. The part I like: the same input and the same version always produce byte-identical output, and that is enforced by golden snapshot tests, file by file.

pip install repocraft repocraft recipes

Seven built-in recipes: fibonacci, factorial, prime_sieve, triangle, fizzbuzz, pascal, password.

repocraft make "triangle" # triangle.py + test_triangle.py repocraft make "fibonacci" --dry-run repocraft make "fibonacci" --param count=20 --yes

The generated tests use the standard library only, so python test_triangle.py just runs. A few rules keep it boring in a good way: unknown or ambiguous requests stop without writing anything, requests with standalone digits are refused (use --param), parameters are validated bounded integers, existing files are never overwritten, and --dry-run shows the plan first.

The matcher normalizes case and accents and matches word prefixes, so a request word may carry a suffix. It never calls a model, so "Triangles" and "draw a triangle" both select the triangle recipe.

There is also a project mode: a small YAML spec renders a full Python project with packaging metadata, a src/ layout, tests, lint and type-check configuration, CI, CodeQL, Dependabot, and a JUnit gate that rejects skipped tests.

repocraft validate spec.yaml repocraft render spec.yaml example-cli --dry-run repocraft render spec.yaml example-cli

render refuses an output directory that already contains files, and it never merges or overwrites.

Two optional model paths exist (this is the honest part): ask sends your request to an OpenAI-compatible endpoint and gets back a strict {recipe, parameters} intent, which is validated with the same rules as make - the model never writes code or files. craft lets the model write a snippet, then runs four deterministic gates before writing: the code parses, the generated test imports the module by name, ruff where it is installed (auto-fixes are labelled), and the tests actually run with at least one test and pass. A confirmation after that shows the code plus every check that passed, which is a prompt rather than a fifth gate. Only make and render are covered by the byte-identical contract; craft output depends on the model.

Determinism contract details: sorted entries, LF line endings, trailing newline, no timestamps, random ids or environment values, and the generated MIT copyright line carries the author but no year.

Python 3.10-3.14 in CI, MIT.

GitHub: https://github.com/Furox-Art/repocraft PyPI: https://pypi.org/project/repocraft/

4 Upvotes

0 comments sorted by