#!/usr/bin/env bash # SPDX-License-Identifier: MIT # The reference, ay8910-python at the pin, into external/ay8910-python, installed into a PyPy # venv at external/venv. The rungs import it from there, and read its scripts/streams.py and # its examples from the clone. # Usage: scripts/fetch_ay8910python.sh [SOURCE, default its GitHub repository] # AY8910_PYTHON_COMMIT overrides the pin; PYTHON names the interpreter (PyPy 3.11). set -euo pipefail # a3bb485 (2026-11-22): ay8910-python's main, the core as re-derived on 2026-11-14 with its # GPL referee drivers moved out of the repository. COMMIT=${AY8910_PYTHON_COMMIT:-a3bb48511db96356581b010e87a6476eaa03e9bc} ROOT=$(cd "$(dirname "$0")/.." && pwd) DEST="$ROOT/external/ay8910-python" SOURCE=${1:-https://github.com/alewman/ay8910-python.git} PYTHON=${PYTHON:-$(command -v pypy3.11 || command -v pypy3 || echo "$HOME/.local/opt/pypy/bin/pypy3")} mkdir -p "$ROOT/external" if [ ! -d "$DEST/.git" ]; then git clone -q "$SOURCE" "$DEST" fi git -C "$DEST" fetch -q origin || true git -C "$DEST" checkout -q --detach "$COMMIT" VENV="$ROOT/external/venv" if [ ! -x "$VENV/bin/python" ]; then "$PYTHON" -m venv "$VENV" fi # pip keeps an installed core whose pin URL changed, so the reference is uninstalled first # and comes back at the pin. "$VENV/bin/python" -m pip uninstall -q -y ay8910-python || true "$VENV/bin/python" -m pip install -q "$DEST" installed=$("$VENV/bin/python" -I -c "import ay8910_python, pathlib; print(pathlib.Path(ay8910_python.__file__).parent)") # The installed package must be the clone's, byte for byte. for file in "$DEST"/src/ay8910_python/*.py; do cmp -s "$file" "$installed/$(basename "$file")" || { echo "installed $(basename "$file") differs from the pin" >&2; exit 1; } done echo "ay8910-python $(git -C "$DEST" rev-parse --short HEAD) in $DEST, installed in $VENV ($("$VENV/bin/python" -c 'import sys; print(sys.version.split()[0], sys.implementation.name)'))"