| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #!/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}/sdk/python"
- RUN="${HTH_RUN_DIR:-/tmp/hth-algo-run}"
- PKG="${HTH_PACKAGE_DIR:-/tmp}"
- mkdir -p "$RUN" "$PKG"
- SDK_BUILD="${RUN}/sdk-build-src"
- rm -rf "$SDK_BUILD"
- mkdir -p "$SDK_BUILD"
- cp -a "$SDK/." "$SDK_BUILD/"
- rm -rf "$SDK_BUILD/build" "$SDK_BUILD/hth_sdk.egg-info" "$SDK_BUILD/.pytest_cache"
- export HTH_RUN_DIR="$RUN"
- export HTH_PACKAGE_DIR="$PKG"
- export HTH_GIT_COMMIT="${HTH_GIT_COMMIT:-unknown}"
- if [[ -z "${HTH_TOOL_CACHE:-}" ]]; then
- if [[ -d /data/prod2u ]]; then
- export HTH_TOOL_CACHE=/data/prod2u/hth-tool-cache
- else
- export HTH_TOOL_CACHE="${RUN}/tool-cache"
- fi
- fi
- export SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date -u +%s)}"
- REC="${SRC}/tools/record_cmd.sh"
- fail=0
- rec() { local n="$1"; shift; if ! bash "${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.__main__' >/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" "$SDK_BUILD"
- 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}/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 sys
- from pathlib import Path
- sys.path.insert(0, r"${SRC}/tools")
- from zip_unix_modes import extract_zip_with_unix_modes
- extract_zip_with_unix_modes(Path(r"${ZIP}"), Path(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 sys
- from pathlib import Path
- sys.path.insert(0, r"${SRC}/tools")
- from zip_unix_modes import extract_zip_with_unix_modes
- extract_zip_with_unix_modes(Path(r"${PORTABLE}"), Path(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
- echo "ALGO_GATES_DONE fail=${fail}" | tee "${RUN}/GATES_DONE"
- exit "${fail}"
|