Vendor CPython stdlib modules as Python source (#1275, step 1)

Merged
R3
12d ago
+6643-1050

First step of #1275: the §2 vendoring pipeline, with three modules that load today.

  • crates/monty/stdlib/vendor.toml pins CPython v3.14.10 and lists the Lib/ files to vendor. make vendor-stdlib downloads them and CPython's LICENSE, applies patches/*.patch in order (git apply, no fuzz), and generates crates/monty/src/modules/bundled/sources.rs. make check-stdlib (CI) fails on any drift.
  • scripts/vendor_stdlib.py --make-patch NAME --reason '...' saves edits to Lib/ as a patch. A patch must start with its reason and may only touch listed files.
  • An import finds a vendored module after the native StandardLib modules and before the host (module_finder.rs). It runs like a module from a file: compiled per session, cached by name, no OS call.
  • Vendors colorsys unmodified. keyword and stat get one patch each, to work around Monty gaps: bound-method access on builtins, and from m import *.
  • make stdlib-candidates runs each #1275 candidate module through monty and groups them by first blocker. Today, 23 modules are blocked by inheritance, 9 by del, 5 by relative imports (including all of unittest), 5 by from m import * and 5 by method decorators. It runs the release binary: debug builds cap source nesting at 30 levels (release: 200), which real stdlib code exceeds.
  • Divergences are in limitations/modules.md under "Vendored CPython modules".

Not included: packages with relative imports, a shared compile cache, and the remaining §2 items.