File: python-venv.sh

package info (click to toggle)
python-plugwise 1.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,080 kB
  • sloc: xml: 90,006; python: 5,344; sh: 326; makefile: 2
file content (27 lines) | stat: -rwxr-xr-x 804 bytes parent folder | download
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
#!/usr/bin/env bash
set -eu

pyversions=(3.13 3.12)
my_path=$(git rev-parse --show-toplevel)
my_venv=${my_path}/venv

# Ensures a python virtualenv is available at the highest available python3 version
for pv in "${pyversions[@]}"; do
    if [ "$(which "python$pv")" ]; then
        # If not (yet) available instantiate python virtualenv
        if [ ! -d "${my_venv}" ]; then
            "python${pv}" -m venv "${my_venv}"
            # Ensure wheel is installed (preventing local issues)
            # shellcheck disable=SC1091
            . "${my_venv}/bin/activate"
            pip install wheel
        fi
        break
    fi
done

# Failsafe
if [ ! -d "${my_venv}" ]; then
    echo "Unable to instantiate venv, check your base python3 version and if you have python3-venv installed"
    exit 1
fi