๐Ÿ“ฆ SeleniumHQ / selenium

๐Ÿ“„ update_py_dependencies.sh ยท 82 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82#!/usr/bin/env bash
#
# This script updates the development dependencies used for the Python bindings.
#
# When you run it, it will:
# - create and activate a temporary virtual env
# - install the current package dependencies from `py/requirements.txt`
# - upgrade the package dependencies to the latest versions available on PyPI
# - run `pip freeze` to generate a new `py/requirements.txt` file
# - run `bazel run //py:requirements.update` to generate a new `py/requirements_lock.txt` file
# - deactivate and remove the temporary virtual env
#
# After running this script, you should also manually check package dependency
# versions in `py/pyproject.toml`, `py/tox.ini`, py/BUILD.bazel`,
# `py/docs/requirements.txt`, and update those if needed.
#
# Once all dependencies are updated, create a new Pull Request with the changes.

set -e

REQUIREMENTS_FILE="./py/requirements.txt"
VENV="./temp_virtualenv"

cd "$(git rev-parse --show-toplevel)"

if [[ ! -f "${REQUIREMENTS_FILE}" ]]; then
    echo "can't find: ${REQUIREMENTS_FILE}"
    exit 1
fi

if [[ -d "${VENV}" ]]; then
    echo "${VENV} already exists"
    exit 1
fi

echo "creating virtual env: ${VENV}"
python3 -m venv "${VENV}"

echo "activating virtual env"
source "${VENV}/bin/activate"

echo "upgrading pip"
python -m pip install --upgrade pip > /dev/null

echo "installing dev dependencies from: ${REQUIREMENTS_FILE}"
pip install -r "${REQUIREMENTS_FILE}" > /dev/null

echo "upgrading outdated dependencies ..."
echo
pip list --outdated | while read -r line; do
    if [[ ! "${line}" =~ "Version" && ! "${line}" =~ "----" ]]; then
        read -ra fields <<< "${line}"
        package="${fields[0]}"
        echo "upgrading ${package} from ${fields[1]} to ${fields[2]}"
        pip install --upgrade "${package}==${fields[2]}" > /dev/null
    fi
done

echo
echo "generating new ${REQUIREMENTS_FILE}"
pip freeze > "${REQUIREMENTS_FILE}"
# `pip freeze` doesn't show package "extras", so we explicitly add it here for urllib3
if [[ "${OSTYPE}" == "linux"* ]]; then
    sed -i "s/urllib3/urllib3[socks]/g" "${REQUIREMENTS_FILE}" # GNU sed
else
    sed -i "" "s/urllib3/urllib3[socks]/g" "${REQUIREMENTS_FILE}"
fi

echo "generating new lock file"
bazel run //py:requirements.update

echo
echo "deleting virtual env: ${VENV}"
deactivate
rm -rf "${VENV}"

echo
git status

echo
echo "done!"