| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #!/usr/bin/env bash
- # Algorithm facade + kit gates. Does not require RTL, soak, or hardware.
- set -uo pipefail
- export PATH="/opt/python-3.12/bin:/opt/python-3.11/bin:/opt/python-3.13/bin:/usr/bin:/bin:${PATH}"
- SRC="${HTH_SRC:-$(cd "$(dirname "$0")/../.." && pwd)}"
- SDK="${SRC}/host/sdk/python"
- RUN="${HTH_RUN_DIR:-/tmp/hth-algo-run}"
- PKG="${HTH_PACKAGE_DIR:-/tmp}"
- mkdir -p "$RUN" "$PKG"
- export HTH_RUN_DIR="$RUN"
- export HTH_PACKAGE_DIR="$PKG"
- export HTH_GIT_COMMIT="${HTH_GIT_COMMIT:-unknown}"
- export SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date -u +%s)}"
- REC="${SRC}/host/tools/record_cmd.sh"
- fail=0
- rec() { local n="$1"; shift; if ! "${REC}" "${n}" "$@"; then fail=1; fi; }
- cd "$SDK"
- PY="${PYTHON:-python3}"
- rec algorithm-facade "$PY" -m pytest tests/test_facade.py tests/test_import.py tests/test_mock_client.py tests/test_doctor.py tests/test_zip_unix_modes.py -q
- rec algorithm-notebook python3 - <<'PY'
- import json
- from pathlib import Path
- nb = json.loads(Path("examples/algorithm_quickstart.ipynb").read_text(encoding="utf-8"))
- g = {}
- for cell in nb["cells"]:
- if cell.get("cell_type") != "code":
- continue
- exec("".join(cell.get("source") or []), g, g)
- print("NOTEBOOK_OK")
- PY
- BUILD_PY="${PYTHON:-python3}"
- if [[ -x /data/prod2u/venvs/hth-verify/bin/python ]]; then
- BUILD_PY=/data/prod2u/venvs/hth-verify/bin/python
- elif ! "$BUILD_PY" -c 'import build' >/dev/null 2>&1; then
- VENV="${RUN}/build-venv"
- "$BUILD_PY" -m venv "$VENV"
- "$VENV/bin/pip" install -q -i https://mirrors.aliyun.com/pypi/simple build
- BUILD_PY="$VENV/bin/python"
- fi
- rec algorithm-wheel "$BUILD_PY" -m build --wheel --outdir "${RUN}/dist" .
- WHEEL="$(ls -1t "${RUN}/dist"/hth_sdk-*.whl 2>/dev/null | head -n1 || true)"
- export HTH_SDK_WHEEL="$WHEEL"
- export HTH_USER_KIT="${HTH_USER_KIT:-linux}"
- rec algorithm-kit python3 "${SRC}/host/tools/package_hth_user_kits.py"
- rec algorithm-kit-zip python3 -m pytest tests/test_userkit.py -q
- ZIP="$(ls -1t "${PKG}"/hth-algorithm-python-kit-*.zip 2>/dev/null | head -n1 || true)"
- if [[ -n "$ZIP" ]]; then
- STAGE="${RUN}/kit-stage"
- rm -rf "$STAGE"
- mkdir -p "$STAGE"
- python3 - <<PY
- import zipfile
- zipfile.ZipFile(r"${ZIP}").extractall(r"${STAGE}")
- PY
- rec python-kit-install bash -lc "cd ${STAGE}/hth-algorithm-python-kit-${HTH_SDK_VERSION:-0.3.0} && ./INSTALL.sh && ./.venv/bin/python app/quickstart.py && ./.venv/bin/python -m hth_sdk doctor"
- fi
- PORTABLE="$(ls -1t "${PKG}"/hth-algorithm-portable-linux-*.zip 2>/dev/null | head -n1 || true)"
- if [[ -n "$PORTABLE" ]]; then
- PSTAGE="${RUN}/portable-stage"
- rm -rf "$PSTAGE"
- mkdir -p "$PSTAGE"
- python3 - <<PY
- import zipfile
- zipfile.ZipFile(r"${PORTABLE}").extractall(r"${PSTAGE}")
- PY
- rec algorithm-portable bash -lc "cd ${PSTAGE}/hth-algorithm-portable-linux-x86_64-${HTH_SDK_VERSION:-0.3.0} && ./START_HERE.sh"
- fi
- if [[ -d /mnt/c/Users/Administrator/AppData/Local/Temp ]]; then
- cp -a "${PKG}"/hth-algorithm-*.zip* /mnt/c/Users/Administrator/AppData/Local/Temp/ 2>/dev/null || true
- fi
- echo "ALGO_GATES_DONE fail=${fail}" | tee "${RUN}/GATES_DONE"
- exit "${fail}"
|