Syngen bootstrap

From tdspora/syngen · View interactive version

Syngen bootstrap is an AI agent skill from the GitHub repository tdspora/syngen. Use to verify or set up the local Syngen development environment — creates a `.venv` if missing, installs the project and its dependencies from `pyproject.toml`, probes runtime imports, and confirms pytest collection works. Invoke this on a fresh checkout, when pytest reports `ModuleNotFoundError`,

How to use this skill

Skill file

Syngen Bootstrap

Purpose

Guarantee that the local Python environment has every dependency the test suite and quality gates need, and that pytest can collect tests without the structural break this repo had before 2026-05-27.

Historical context (load-bearing)

If either regression returns, the test suite will silently degrade — restore the fixes before further work.

Workflow

Step 0 — repo root

REPO_ROOT="$(git rev-parse --show-toplevel)"
cd "${REPO_ROOT}"

Step 1 — locate or create the project venv

The harness prefers a .venv at the repo root for parity with the other tdm-* repositories.

VENV_DIR="${REPO_ROOT}/.venv"
PY="${VENV_DIR}/bin/python"

Branch A — venv exists. Verify the interpreter still works:

test -x "${PY}" && "${PY}" --version

If the version is not 3.10.x or 3.11.x (the supported range), the venv is stale — escalate per the Approval contract before recreating.

Branch B — venv missing. Creating a venv is a workspace-state change. Emit:

APPROVAL REQUIRED: create .venv at ${REPO_ROOT}/.venv via
    python3.11 -m venv "${REPO_ROOT}/.venv"
    "${REPO_ROOT}/.venv/bin/python" -m pip install --upgrade pip
    "${REPO_ROOT}/.venv/bin/python" -m pip install -e "${REPO_ROOT}"
    "${REPO_ROOT}/.venv/bin/python" -m pip install build twine

Wait for approved per CLAUDE.md "Approval contract". After approval, run each command in order and report the result of each. Notes:

Branch C — user denies venv creation. Fall back to the system Python:

PY="$(command -v python)"
"${PY}" --version

Continue with steps 2-5; quality gates that require missing dev tools (mypy, build, twine) will be skipped with an explicit note in the handoff.

Step 2 — probe runtime imports

"${PY}" - <<'PY'
groups = [
    ("runtime",  ["syngen", "marshmallow", "pandas", "numpy", "pyarrow", "loguru", "yaml"]),
    ("ml",       ["tensorflow"]),
    ("regex",    ["exrex"]),
    ("fernet",   ["cryptography.fernet"]),
    ("logging",  ["reportportal_client"]),
    ("dev",      ["pytest", "flake8", "build", "twine"]),
]
missing = []
for label, mods in groups:
    for m in mods:
        try:
            __import__(m)
        except Exception as e:
            missing.append((label, m, f"{type(e).__name__}: {e}"))
            print(f"  FAIL {label:8s} {m:30s} {type(e).__name__}: {e}")
        else:
            print(f"  OK   {label:8s} {m}")
print()
print("missing:" if missing else "all imports OK")
for label, m, e in missing:
    print(f"  - [{label}] {m}: {e}")
PY

Each missing module that you did not just resolve via the venv creation in step 1 is an escalation. Emit:

APPROVAL REQUIRED: install missing module(s) <list> via
    "${PY}" -m pip install <list>

Step 2b — installed-vs-source version parity

This library is consumed downstream by tdm_syngen, whose tests frequently run against this source tree via PYTHONPATH=<syngen>/src rather than an install. An installed syngen wheel of a different version then silently shadows or mismatches the source you are editing, producing failures (or false passes) that have nothing to do with your change. Before trusting any test result, compare the installed version to this source tree's src/syngen/VERSION:

"${PY}" - <<'PY'
from importlib.metadata import version, PackageNotFoundError
from pathlib import Path
src = Path("src/syngen/VERSION").read_text().strip()
try:
    inst = version("syngen")
except PackageNotFoundError:
    inst = "(not installed)"
print(f"source={src}  installed={inst}")
print("MATCH" if inst == src else "DRIFT — prefer PYTHONPATH=<syngen>/src, or reinstall the matching wheel (escalation)")
PY

On DRIFT, do not pip install --upgrade (denied by .claude/settings.json and a dependency change requiring escalation). Either run against the source tree with PYTHONPATH set, or escalate to reinstall the exact matching wheel. Report the drift in your handoff.

Step 3 — verify pytest collection

"${PY}" -m pytest --collect-only -q src/tests/unit 2>&1 | tail -5

Expected: a <N> tests collected line with no collection errors.

Step 4 — verify entry-point binaries and imports

ls -la "${VENV_DIR}/bin/train" "${VENV_DIR}/bin/infer" "${VENV_DIR}/bin/syngen" 2>/dev/null
"${PY}" -c "import syngen; print(syngen.__file__)"

If the console scripts are missing, the editable install in step 1 was skipped or failed — re-run "${PY}" -m pip install -e ..

Step 5 — confirm runtime cache directories are absent or empty

ls -d "${REPO_ROOT}/model_artifacts" "${REPO_ROOT}/tmp_store" 2>/dev/null | head

These should not exist on a fresh checkout. If they do, they are leftover from a prior run and should be cleaned up before committing. They are denied for read by the harness (./model_artifacts/**, ./tmp_store/** in settings.json).

When to invoke

Do not

Handoff

State:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.