File: common.sh

package info (click to toggle)
pyroon 0.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 372 kB
  • sloc: python: 1,660; sh: 135; makefile: 4
file content (37 lines) | stat: -rw-r--r-- 898 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
28
29
30
31
32
33
34
35
36
37
VENV_DIR=".venv"
PYTHON_BIN="python3"
LINT_PATHS="./roonapi"

function assertPython() {
  if ! [[ $(which "$PYTHON_BIN") ]]; then
    echo "Error: '$PYTHON_BIN' is not in your path."
    exit 1
  fi
}

function enterVenv() {
  # Not sure why I couldn't use "if ! [[ `"$PYTHON_BIN" -c 'import venv'` ]]" below. It just never worked when venv was
  # present.
  VENV_NOT_INSTALLED=$("$PYTHON_BIN" -c 'import venv' 2>&1 | grep -ic ' No module named' || true)
  if [[ "$VENV_NOT_INSTALLED" -gt "0" ]]; then
    echo "Error: The $PYTHON_BIN 'venv' module is not installed."
    exit 1
  fi

  if ! [[ -e "$VENV_DIR" ]]; then
    echo "Creating venv."
    "$PYTHON_BIN" -m venv "$VENV_DIR"
  else
    echo Using existing venv.
  fi

  if ! [[ $(env | grep VIRTUAL_ENV) ]]; then
    echo "Entering venv."
    set +uf
    source "$VENV_DIR/bin/activate"
    set -uf
  else
    echo Already in venv.
  fi

}