Joe Ethier | fbe6615 | 2021-03-31 16:02:36 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2021 The Pigweed Authors |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 6 | # use this file except in compliance with the License. You may obtain a copy of |
| 7 | # the License at |
| 8 | # |
| 9 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations under |
| 15 | # the License. |
| 16 | |
| 17 | set -o xtrace -o errexit -o nounset |
| 18 | |
| 19 | SRC="${BASH_SOURCE[0]}" |
| 20 | DIR="$(python3 -c "import os; print(os.path.dirname(os.path.abspath(os.path.realpath(\"$SRC\"))))")" |
| 21 | VENV="${DIR}/python-venv" |
| 22 | PY_TO_TEST="python3" |
| 23 | |
| 24 | if [ ! -z "${1-}" ]; then |
| 25 | VENV="${1-}" |
| 26 | PY_TO_TEST="${VENV}/bin/python" |
| 27 | fi |
| 28 | |
| 29 | PY_MAJOR_VERSION=$(${PY_TO_TEST} -c "import sys; print(sys.version_info[0])") |
| 30 | PY_MINOR_VERSION=$(${PY_TO_TEST} -c "import sys; print(sys.version_info[1])") |
| 31 | |
| 32 | if [ ${PY_MAJOR_VERSION} -ne 3 ] || [ ${PY_MINOR_VERSION} -lt 7 ] |
| 33 | then |
| 34 | echo "ERROR: This Python distributable requires Python 3.7 or newer." |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
| 38 | if [ ! -d "${VENV}" ] |
| 39 | then |
| 40 | ${PY_TO_TEST} -m venv ${VENV} |
| 41 | fi |
| 42 | |
| 43 | ${VENV}/bin/python -m pip install --upgrade pip |
| 44 | |
| 45 | for wheel in $(ls ${DIR}/python_wheels/*.whl) |
| 46 | do |
| 47 | ${VENV}/bin/python -m pip install \ |
| 48 | --upgrade --force-reinstall \ |
| 49 | --find-links=${DIR}/python_wheels \ |
| 50 | $wheel |
| 51 | done |
| 52 | |
| 53 | exit 0 |