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

Commit 51ab52b8 authored by uael's avatar uael
Browse files

avatar: update avatar script

* Check for `python3` and `pip` to exists.
* Format and lint are now also applied to external sources.
* Fixed `Gatt` experimental servicer lint & format issues.
* Updated `mypy` to 1.1.1.

Test: avatar run
Change-Id: I06fce4fc0afd8f6991aa1ac84726a8a81c3542d2
parent 30666482
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
#!/usr/bin/env bash
_BT_ROOT="${ANDROID_BUILD_TOP}/packages/modules/Bluetooth"
_TEST_ROOT="${_BT_ROOT}/android/pandora/test"
_TEST_FILES=("${_TEST_ROOT}/main.py" "${_TEST_ROOT}/"*_test.py)

_USAGE="avatar [OPTIONS] <COMMAND> ...
  OPTIONS:
    -h, --help           Show this message and exit.
@@ -24,6 +20,15 @@ _USAGE="avatar [OPTIONS] <COMMAND> ...
                         See 'avatar run --help-all'
    "

_BT_ROOT="${ANDROID_BUILD_TOP}/packages/modules/Bluetooth"
_TEST_ROOT="${_BT_ROOT}/android/pandora/test"
_PY_SOURCES=(
  "${ANDROID_BUILD_TOP}/external/pandora/avatar/"{avatar,examples}
  "${_BT_ROOT}/pandora/server/bumble_experimental"
  "${_TEST_ROOT}/"*_test.py
  "${_TEST_ROOT}/main.py"
)

_PANDORA_PYTHON_PATHS=(
  "${_BT_ROOT}/pandora/server/"
  "${ANDROID_BUILD_TOP}/external/pandora/avatar/"
@@ -39,23 +44,23 @@ case "$1" in
    pip install \
      'black==22.10.0' \
      'isort==5.12.0'
    black -S -l 119 "$@" "${_TEST_FILES[@]}"
    isort --profile black -l 119 --ds --lbt 1 --ca "$@" "${_TEST_FILES[@]}"
    black -S -l 119 "$@" "${_PY_SOURCES[@]}"
    isort --profile black -l 119 --ds --lbt 1 --ca "$@" "${_PY_SOURCES[@]}"
  ;;
  'lint') shift
    pip install \
      'grpcio==1.51.1' \
      'protobuf==4.21.0' \
      'pyright==1.1.298' \
      'mypy==1.0' \
      'mypy==1.1.1' \
      'types-protobuf==4.21.0.3'
    export PYTHONPATH="$(IFS=:; echo "${_PANDORA_PYTHON_PATHS[*]}"):${PYTHONPATH}"
    mypy \
      --pretty --show-column-numbers --strict --no-warn-unused-ignores --ignore-missing-imports \
      "$@" "${_TEST_FILES[@]}" || exit 1
      "$@" "${_PY_SOURCES[@]}" || exit 1
    pyright \
      -p "${_TEST_ROOT}" \
      "$@" "${_TEST_FILES[@]}"
      "$@" "${_PY_SOURCES[@]}"
  ;;
  'run') shift
    tradefed.sh \
+11 −0
Original line number Diff line number Diff line
@@ -2,6 +2,17 @@ function avatar {
  # avatar script.
  _AVATAR="${ANDROID_BUILD_TOP}/packages/modules/Bluetooth/android/pandora/test/avatar.sh"

  if ! command -v python3 &> /dev/null; then
    echo "python3: command not found" 1>&2
    echo "  on linux: 'sudo apt install python3 python3-pip'" 1>&2
    return 1
  fi
  if ! command -v pip &> /dev/null; then
    echo "pip: command not found" 1>&2
    echo "  on linux: 'sudo apt install python3 python3-pip'" 1>&2
    return 1
  fi

  # only compile when needed.
  if [[ "$1" == "run" ]]; then
    m avatar avatar.sh PandoraServer tradefed || return 1
+11 −11
Original line number Diff line number Diff line
@@ -19,8 +19,9 @@ import logging
from bumble.core import ProtocolError
from bumble.device import Connection as BumbleConnection, Device, Peer
from bumble.gatt_client import CharacteristicProxy, ServiceProxy
from pandora_experimental.gatt_grpc_aio import GATTServicer
from pandora_experimental.gatt_pb2 import (
    AttStatusCode,
    SUCCESS,
    AttValue,
    ClearCacheRequest,
    ClearCacheResponse,
@@ -41,7 +42,6 @@ from pandora_experimental.gatt_pb2 import (
    WriteRequest,
    WriteResponse,
)
from pandora_experimental.gatt_grpc_aio import GATTServicer
from typing import Dict, List


@@ -61,7 +61,7 @@ class GATTService(GATTServicer):
        self.device.remove_listener('disconnection', self.on_disconnection)  # type: ignore

    def on_connection(self, connection: BumbleConnection) -> None:
        self.peers[connection.handle] = Peer(connection)
        self.peers[connection.handle] = Peer(connection)  # type: ignore[no-untyped-call]

    def on_disconnection(self, connection: BumbleConnection) -> None:
        del self.peers[connection.handle]
@@ -89,11 +89,11 @@ class GATTService(GATTServicer):

        try:
            await peer.write_value(request.handle, request.value, with_response=True)  # type: ignore
            status = 0
            status = SUCCESS
        except ProtocolError as e:
            status = e.error_code

        return WriteResponse(handle=request.handle, status=AttStatusCode(status))
        return WriteResponse(handle=request.handle, status=status)

    async def DiscoverServiceByUuid(
        self, request: DiscoverServiceByUuidRequest, context: grpc.ServicerContext
@@ -110,7 +110,7 @@ class GATTService(GATTServicer):
        async def feed_service(service: ServiceProxy) -> None:
            characteristic: CharacteristicProxy
            for characteristic in await peer.discover_characteristics(service=service):  # type: ignore
                await characteristic.discover_descriptors()
                await characteristic.discover_descriptors()  # type: ignore[no-untyped-call]

        await asyncio.gather(*(feed_service(service) for service in services))

@@ -206,12 +206,12 @@ class GATTService(GATTServicer):

        try:
            value = await peer.read_value(request.handle)  # type: ignore
            status = 0
            status = SUCCESS
        except ProtocolError as e:
            value = bytes()
            status = e.error_code

        return ReadCharacteristicResponse(value=AttValue(value=value), status=AttStatusCode(status))
        return ReadCharacteristicResponse(value=AttValue(value=value), status=status)

    async def ReadCharacteristicsFromUuid(
        self, request: ReadCharacteristicsFromUuidRequest, context: grpc.ServicerContext
@@ -232,7 +232,7 @@ class GATTService(GATTServicer):
                characteristics_read=[
                    ReadCharacteristicResponse(
                        value=AttValue(value=value, handle=handle),  # type: ignore
                        status=AttStatusCode.SUCCESS,
                        status=SUCCESS,
                    )
                    for handle, value in characteristics  # type: ignore
                ]
@@ -255,9 +255,9 @@ class GATTService(GATTServicer):

        try:
            value = await peer.read_value(request.handle)  # type: ignore
            status = 0
            status = SUCCESS
        except ProtocolError as e:
            value = bytes()
            status = e.error_code

        return ReadCharacteristicDescriptorResponse(value=AttValue(value=value), status=AttStatusCode(status))
        return ReadCharacteristicDescriptorResponse(value=AttValue(value=value), status=status)