Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 86819a22 authored by uael's avatar uael
Browse files

avatar: use a custom venv directory

This change:
* Remove dependency over `virtualenv`.
* Improve TF `PythonVirtualenvPreparer` step performance (only first run
  perform a complete install).

Also:
* Force use of `python3`.
* Fixed bad default testbed name is usage.

Test: avatar run
Change-Id: I50c69108934b017651ac5e433c5d84a6a53c6155
parent 3ca03f89
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ _USAGE="avatar [OPTIONS] <COMMAND> ...
      OPTIONS: (subset, see 'avatar run --help-all')
        --include-filter=<ClassA[#test_a]>
                         Add a test filter in form of 'ClassA[#test_a]'.
        --test-bed       Set mobly test bed (default is 'android.bumble').
        --test-bed       Set mobly test bed (default is 'android.bumbles').
        --mobly-std-log  Print mobly logs to standard outputs.
        --mobly-options=<'--opt-a --opt-b'>
                         Pass additional options to mobly, like '--verbose' or '--list'.
@@ -20,6 +20,7 @@ _USAGE="avatar [OPTIONS] <COMMAND> ...
                         See 'avatar run --help-all'
    "

_VENV_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/avatar/venv"
_BT_ROOT="${ANDROID_BUILD_TOP}/packages/modules/Bluetooth"
_TEST_ROOT="${_BT_ROOT}/android/pandora/test"
_PY_SOURCES=(
@@ -41,30 +42,32 @@ _PANDORA_PYTHON_PATHS=(

case "$1" in
  'format') shift
    pip install \
    python3 -m pip install \
      'black==22.10.0' \
      'isort==5.12.0'
    black -S -l 119 "$@" "${_PY_SOURCES[@]}"
    isort --profile black -l 119 --ds --lbt 1 --ca "$@" "${_PY_SOURCES[@]}"
    python3 -m black -S -l 119 "$@" "${_PY_SOURCES[@]}"
    python3 -m isort --profile black -l 119 --ds --lbt 1 --ca "$@" "${_PY_SOURCES[@]}"
  ;;
  'lint') shift
    pip install \
    python3 -m pip install \
      'grpcio==1.51.1' \
      'protobuf==4.21.0' \
      'pyright==1.1.298' \
      'mypy==1.1.1' \
      'types-protobuf==4.21.0.3'
    export PYTHONPATH="$(IFS=:; echo "${_PANDORA_PYTHON_PATHS[*]}"):${PYTHONPATH}"
    mypy \
    python3 -m mypy \
      --pretty --show-column-numbers --strict --no-warn-unused-ignores --ignore-missing-imports \
      "$@" "${_PY_SOURCES[@]}" || exit 1
    pyright \
    python3 -m pyright \
      -p "${_TEST_ROOT}" \
      "$@" "${_PY_SOURCES[@]}"
  ;;
  'run') shift
    [ ! -d "${_VENV_DIR}" ] && python3 -m venv "${_VENV_DIR}"
    tradefed.sh \
      run commandAndExit template/local_min --template:map test=avatar --log-level INFO \
        --venv-dir "${_VENV_DIR}" \
        "$@"
  ;;
  'help'|'--help'|'-h') shift