import zipfile
from pathlib import Path
HERE = Path(__file__).parent
METADATA = "Metadata-Version: 2.1\nName: widget\nVersion: 0.1.0\n"
WHEEL = (
"Wheel-Version: 1.0\nGenerator: make_wheels.py\n"
"Root-Is-Purelib: true\nTag: py3-none-any\n"
)
SOURCE = "def add(a, b):\n return a + b\n"
TEST = "from widget.core import add\n\n\ndef test_add():\n assert add(1, 2) == 3\n"
COMMON = {
"widget/__init__.py": "",
"widget/core.py": SOURCE,
"widget-0.1.0.dist-info/METADATA": METADATA,
"widget-0.1.0.dist-info/WHEEL": WHEEL,
}
def write_wheel(path: Path, files: dict) -> None:
with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as zf:
for name, content in sorted(files.items()):
info = zipfile.ZipInfo(name, date_time=(2026, 1, 1, 0, 0, 0))
zf.writestr(info, content)
write_wheel(HERE / "red.whl", {**COMMON, "widget/core_test.py": TEST})
write_wheel(HERE / "clean.whl", COMMON)
print("wrote red.whl and clean.whl")