setup_python.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env bash
  2. # py2_incomp='assign_test|nvs_compatible_test|IT'
  3. # - auto_test_script do not support python2 anymore
  4. # but there are still some jobs incompatible with Python 3 (eg: example_test)
  5. # keep the default python interpreter as 2.7.15 until all the jobs support python3
  6. # Regexp for matching job names which are incompatible with Python 3
  7. # - UT_009_ - multi-device tests are not compatible
  8. # - UT_017_ - multi-device tests are not compatible
  9. py3_incomp='UT_009_|UT_017_'
  10. if [ -z ${PYTHON_VER+x} ] || [[ $CI_JOB_NAME =~ $py3_incomp ]]; then
  11. # Use this version of the Python interpreter if it was not defined before or
  12. # the given job is not compatible with Python 3
  13. PYTHON_VER=2.7.15
  14. fi
  15. if [ -f /opt/pyenv/activate ];
  16. then
  17. source /opt/pyenv/activate
  18. pyenv global $PYTHON_VER || {
  19. echo 'Python' $PYTHON_VER 'is not installed.'
  20. INSTALLED_PY_VERS=$(pyenv versions --bare)
  21. while [ ${#PYTHON_VER} -gt 0 ]
  22. do
  23. echo 'Tring to locate a match for' $PYTHON_VER
  24. for ver in ${INSTALLED_PY_VERS[@]}
  25. do
  26. if [[ $ver == $PYTHON_VER* ]];
  27. then
  28. pyenv global $ver
  29. break 2
  30. fi
  31. done
  32. # Removing last character and trying to find some match.
  33. # For example, if 3.4.8 was selected but isn't installed then it will try to
  34. # find some other installed 3.4.X version, and then some 3.X.X version.
  35. PYTHON_VER=${PYTHON_VER: : -1}
  36. done
  37. }
  38. python --version || {
  39. echo 'No matching Python interpreter is found!'
  40. exit 1
  41. }
  42. elif command -v python -V 1>/dev/null 2>&1;
  43. then
  44. python --version
  45. echo 'No /opt/pyenv/activate exists and Python from path is used.'
  46. else
  47. echo 'No /opt/pyenv/activate exists and no Python interpreter is found!'
  48. exit 1
  49. fi
  50. # add esp-idf local package path to PYTHONPATH so it can be imported directly
  51. export PYTHONPATH="$IDF_PATH/tools:$IDF_PATH/tools/ci/python_packages:$PYTHONPATH"