run_algorithm_gates.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env bash
  2. # Algorithm facade + kit gates. Does not require RTL, soak, or hardware.
  3. set -uo pipefail
  4. export PATH="/opt/python-3.12/bin:/opt/python-3.11/bin:/opt/python-3.13/bin:/usr/bin:/bin:${PATH}"
  5. SRC="${HTH_SRC:-$(cd "$(dirname "$0")/../.." && pwd)}"
  6. SDK="${SRC}/host/sdk/python"
  7. RUN="${HTH_RUN_DIR:-/tmp/hth-algo-run}"
  8. PKG="${HTH_PACKAGE_DIR:-/tmp}"
  9. mkdir -p "$RUN" "$PKG"
  10. export HTH_RUN_DIR="$RUN"
  11. export HTH_PACKAGE_DIR="$PKG"
  12. export HTH_GIT_COMMIT="${HTH_GIT_COMMIT:-unknown}"
  13. export SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date -u +%s)}"
  14. REC="${SRC}/host/tools/record_cmd.sh"
  15. fail=0
  16. rec() { local n="$1"; shift; if ! "${REC}" "${n}" "$@"; then fail=1; fi; }
  17. cd "$SDK"
  18. PY="${PYTHON:-python3}"
  19. 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
  20. rec algorithm-notebook python3 - <<'PY'
  21. import json
  22. from pathlib import Path
  23. nb = json.loads(Path("examples/algorithm_quickstart.ipynb").read_text(encoding="utf-8"))
  24. g = {}
  25. for cell in nb["cells"]:
  26. if cell.get("cell_type") != "code":
  27. continue
  28. exec("".join(cell.get("source") or []), g, g)
  29. print("NOTEBOOK_OK")
  30. PY
  31. BUILD_PY="${PYTHON:-python3}"
  32. if [[ -x /data/prod2u/venvs/hth-verify/bin/python ]]; then
  33. BUILD_PY=/data/prod2u/venvs/hth-verify/bin/python
  34. elif ! "$BUILD_PY" -c 'import build' >/dev/null 2>&1; then
  35. VENV="${RUN}/build-venv"
  36. "$BUILD_PY" -m venv "$VENV"
  37. "$VENV/bin/pip" install -q -i https://mirrors.aliyun.com/pypi/simple build
  38. BUILD_PY="$VENV/bin/python"
  39. fi
  40. rec algorithm-wheel "$BUILD_PY" -m build --wheel --outdir "${RUN}/dist" .
  41. WHEEL="$(ls -1t "${RUN}/dist"/hth_sdk-*.whl 2>/dev/null | head -n1 || true)"
  42. export HTH_SDK_WHEEL="$WHEEL"
  43. export HTH_USER_KIT="${HTH_USER_KIT:-linux}"
  44. rec algorithm-kit python3 "${SRC}/host/tools/package_hth_user_kits.py"
  45. rec algorithm-kit-zip python3 -m pytest tests/test_userkit.py -q
  46. ZIP="$(ls -1t "${PKG}"/hth-algorithm-python-kit-*.zip 2>/dev/null | head -n1 || true)"
  47. if [[ -n "$ZIP" ]]; then
  48. STAGE="${RUN}/kit-stage"
  49. rm -rf "$STAGE"
  50. mkdir -p "$STAGE"
  51. python3 - <<PY
  52. import zipfile
  53. zipfile.ZipFile(r"${ZIP}").extractall(r"${STAGE}")
  54. PY
  55. 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"
  56. fi
  57. PORTABLE="$(ls -1t "${PKG}"/hth-algorithm-portable-linux-*.zip 2>/dev/null | head -n1 || true)"
  58. if [[ -n "$PORTABLE" ]]; then
  59. PSTAGE="${RUN}/portable-stage"
  60. rm -rf "$PSTAGE"
  61. mkdir -p "$PSTAGE"
  62. python3 - <<PY
  63. import zipfile
  64. zipfile.ZipFile(r"${PORTABLE}").extractall(r"${PSTAGE}")
  65. PY
  66. rec algorithm-portable bash -lc "cd ${PSTAGE}/hth-algorithm-portable-linux-x86_64-${HTH_SDK_VERSION:-0.3.0} && ./START_HERE.sh"
  67. fi
  68. if [[ -d /mnt/c/Users/Administrator/AppData/Local/Temp ]]; then
  69. cp -a "${PKG}"/hth-algorithm-*.zip* /mnt/c/Users/Administrator/AppData/Local/Temp/ 2>/dev/null || true
  70. fi
  71. echo "ALGO_GATES_DONE fail=${fail}" | tee "${RUN}/GATES_DONE"
  72. exit "${fail}"