• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17set -o xtrace -o errexit -o nounset
18
19SRC="${BASH_SOURCE[0]}"
20DIR="$(python3 -c "import os; print(os.path.dirname(os.path.abspath(os.path.realpath(\"$SRC\"))))")"
21VENV="${DIR}/python-venv"
22PY_TO_TEST="python3"
23CONSTRAINTS_PATH="${DIR}/constraints.txt"
24
25if [ ! -z "${1-}" ]; then
26  VENV="${1-}"
27  PY_TO_TEST="${VENV}/bin/python"
28fi
29
30CONSTRAINTS_ARG=""
31if [ -f ${CONSTRAINTS_PATH} ]; then
32    CONSTRAINTS_ARG="-c ${CONSTRAINTS_PATH}"
33fi
34
35PY_MAJOR_VERSION=$(${PY_TO_TEST} -c "import sys; print(sys.version_info[0])")
36PY_MINOR_VERSION=$(${PY_TO_TEST} -c "import sys; print(sys.version_info[1])")
37
38if [ ${PY_MAJOR_VERSION} -ne 3 ] || [ ${PY_MINOR_VERSION} -lt 7 ]
39then
40    echo "ERROR: This Python distributable requires Python 3.7 or newer."
41    exit 1
42fi
43
44if [ ! -d "${VENV}" ]
45then
46    ${PY_TO_TEST} -m venv ${VENV}
47fi
48
49${VENV}/bin/python -m pip install --upgrade pip
50
51# Uninstall wheels first, in case installing over an existing venv. This is a
52# faster and less destructive approach than --force-reinstall to ensure wheels
53# whose version numbers haven't incremented still get reinstalled.
54for wheel in $(ls ${DIR}/python_wheels/*.whl)
55do
56    ${VENV}/bin/python -m pip uninstall --yes $wheel
57done
58
59for wheel in $(ls ${DIR}/python_wheels/*.whl)
60do
61    ${VENV}/bin/python -m pip install \
62    --upgrade --find-links=${DIR}/python_wheels ${CONSTRAINTS_ARG} $wheel
63done
64
65exit 0
66