python-use.sh 596 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. # 'import perf' in python
  3. # SPDX-License-Identifier: GPL-2.0
  4. # Just test if we can load the python binding.
  5. set -e
  6. shelldir=$(dirname "$0")
  7. # shellcheck source=lib/setup_python.sh
  8. . "${shelldir}"/lib/setup_python.sh
  9. MODULE_DIR=$(dirname "$(which perf)")/python
  10. if [ -d "$MODULE_DIR" ]
  11. then
  12. CMD=$(cat <<EOF
  13. import sys
  14. sys.path.insert(0, '$MODULE_DIR')
  15. import perf
  16. print('success!')
  17. EOF
  18. )
  19. else
  20. CMD=$(cat <<EOF
  21. import perf
  22. print('success!')
  23. EOF
  24. )
  25. fi
  26. echo -e "Testing 'import perf' with:\n$CMD"
  27. if ! echo "$CMD" | $PYTHON | grep -q "success!"
  28. then
  29. exit 1
  30. fi
  31. exit 0