|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# This script updates the development dependendencies used for the Python bindings. |
| 4 | +# |
| 5 | +# When you run it, it will: |
| 6 | +# - create and activate a temporary virtual env |
| 7 | +# - install the current package dependencies from `py/requirements.txt` |
| 8 | +# - upgrade the package dependencies to the latest versions available on PyPI |
| 9 | +# - run `pip freeze` to generate a new `py/requirements.txt` file |
| 10 | +# - run `bazel run //py:requirements.update` to generate a new `py/requirements_lock.txt` file |
| 11 | +# - deactivate and remove the temporary virtual env |
| 12 | +# |
| 13 | +# After running this script, you should also manually check package dependency versions in |
| 14 | +# `py/pyproject.toml`, `py/tox.ini` and `py/BUILD.bazel`, and update those if needed. |
| 15 | +# |
| 16 | +# Once all dependencies are updated, create a new Pull Request with the changes. |
| 17 | + |
| 18 | +set -e |
| 19 | + |
| 20 | +REQUIREMENTS_FILE="./py/requirements.txt" |
| 21 | +VENV="./temp_virtualenv" |
| 22 | + |
| 23 | +cd "$(git rev-parse --show-toplevel)" |
| 24 | + |
| 25 | +if [[ ! -f "${REQUIREMENTS_FILE}" ]]; then |
| 26 | + echo "can't find: ${REQUIREMENTS_FILE}" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +if [[ -d "${VENV}" ]]; then |
| 31 | + echo "${VENV} already exists" |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +echo "creating virtual env: ${VENV}" |
| 36 | +python3 -m venv "${VENV}" |
| 37 | + |
| 38 | +echo "activating virtual env" |
| 39 | +source "${VENV}/bin/activate" |
| 40 | + |
| 41 | +echo "upgrading pip" |
| 42 | +python -m pip install --upgrade pip > /dev/null |
| 43 | + |
| 44 | +echo "installing dev dependencies from: ${REQUIREMENTS_FILE}" |
| 45 | +pip install -r "${REQUIREMENTS_FILE}" > /dev/null |
| 46 | + |
| 47 | +echo "upgrading outdated dependencies ..." |
| 48 | +echo |
| 49 | +pip list --outdated | while read -r line; do |
| 50 | + if [[ ! "${line}" =~ "Version Latest" && ! "${line}" =~ "----" ]]; then |
| 51 | + read -ra fields <<< "${line}" |
| 52 | + package="${fields[0]}" |
| 53 | + echo "upgrading ${package} from ${fields[1]} to ${fields[2]}" |
| 54 | + pip install --upgrade "${package}==${fields[2]}" > /dev/null |
| 55 | + fi |
| 56 | +done |
| 57 | + |
| 58 | +echo |
| 59 | +echo "generating new ${REQUIREMENTS_FILE}" |
| 60 | +pip freeze > "${REQUIREMENTS_FILE}" |
| 61 | +# `pip freeze` doesn't show package "extras", so we explicitly add it here for urllib3 |
| 62 | +if [[ "${OSTYPE}" == "linux"* ]]; then |
| 63 | + sed -i "s/urllib3/urllib3[socks]/g" "${REQUIREMENTS_FILE}" # GNU sed |
| 64 | +else |
| 65 | + sed -i "" "s/urllib3/urllib3[socks]/g" "${REQUIREMENTS_FILE}" |
| 66 | +fi |
| 67 | + |
| 68 | +echo "generating new lock file" |
| 69 | +bazel run //py:requirements.update |
| 70 | + |
| 71 | +echo |
| 72 | +echo "deleting virtual env: ${VENV}" |
| 73 | +deactivate |
| 74 | +rm -rf "${VENV}" |
| 75 | + |
| 76 | +echo |
| 77 | +git status |
| 78 | + |
| 79 | +echo |
| 80 | +echo "done!" |
0 commit comments