python.sh 769 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/bash
  2. set -e
  3. python="$(docker run --rm "$1" bash -ec '
  4. for c in python3 python pypy3 pypy; do
  5. if command -v "$c" &> /dev/null; then
  6. echo "$c"
  7. break
  8. fi
  9. done
  10. ')"
  11. if [ -z "$python" ]; then
  12. echo >&2 "error: unable to determine how to run 'python' in '$1'"
  13. exit 1
  14. fi
  15. # run each test artifact in a separate, isolated container
  16. for artifact in "$(dirname "$(readlink -f "$BASH_SOURCE")")"/python-artifacts/*; do
  17. inContainerPath="/tmp/$(basename "$artifact")"
  18. case "$artifact" in
  19. *.py) cmd=( "$python" "$inContainerPath" ) ;;
  20. *.sh) cmd=( "$inContainerPath" ) ;;
  21. *) continue ;;
  22. esac
  23. if ! docker run --rm -e PYTHON="$python" -v "$artifact":"$inContainerPath":ro "$1" "${cmd[@]}"; then
  24. echo >&2 "error: '$artifact' failed!"
  25. exit 1
  26. fi
  27. done