Skip to content

Commit

Permalink
Support for python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
yama-yeah committed Apr 3, 2024
1 parent bd0bdf0 commit 10b611f
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 48 deletions.
21 changes: 15 additions & 6 deletions bless/backends/winrt/characteristic.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import sys
from uuid import UUID
from typing import Union, Optional

from bleak.backends.winrt.characteristic import ( # type: ignore
BleakGATTCharacteristicWinRT,
)

from bleak_winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E501
GattProtectionLevel,
GattLocalCharacteristicParameters,
GattLocalCharacteristic,
GattLocalCharacteristicResult,
)
if sys.version_info >= (3, 12):
from winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E501
GattProtectionLevel,
GattLocalCharacteristicParameters,
GattLocalCharacteristic,
GattLocalCharacteristicResult,
)
else:
from bleak_winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E501
GattProtectionLevel,
GattLocalCharacteristicParameters,
GattLocalCharacteristic,
GattLocalCharacteristicResult,
)

from bless.backends.service import BlessGATTService

Expand Down
51 changes: 35 additions & 16 deletions bless/backends/winrt/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import logging

import sys
from uuid import UUID
from threading import Event
from asyncio.events import AbstractEventLoop
Expand All @@ -24,22 +25,40 @@
# from BleakBridge import Bridge

# Import of other CLR components needed.
from bleak_winrt.windows.foundation import Deferral # type: ignore

from bleak_winrt.windows.storage.streams import DataReader, DataWriter # type: ignore

from bleak_winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E501
GattWriteOption,
GattServiceProvider,
GattLocalCharacteristic,
GattServiceProviderAdvertisingParameters,
GattServiceProviderAdvertisementStatusChangedEventArgs as StatusChangeEvent, # noqa: E501
GattReadRequestedEventArgs,
GattReadRequest,
GattWriteRequestedEventArgs,
GattWriteRequest,
GattSubscribedClient,
)
if sys.version_info >= (3, 12):
from winrt.windows.foundation import Deferral # type: ignore

from winrt.windows.storage.streams import DataReader, DataWriter # type: ignore

from winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E501
GattWriteOption,
GattServiceProvider,
GattLocalCharacteristic,
GattServiceProviderAdvertisingParameters,
GattServiceProviderAdvertisementStatusChangedEventArgs as StatusChangeEvent, # noqa: E501
GattReadRequestedEventArgs,
GattReadRequest,
GattWriteRequestedEventArgs,
GattWriteRequest,
GattSubscribedClient,
)
else:
from bleak_winrt.windows.foundation import Deferral # type: ignore

from bleak_winrt.windows.storage.streams import DataReader, DataWriter # type: ignore

from bleak_winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E501
GattWriteOption,
GattServiceProvider,
GattLocalCharacteristic,
GattServiceProviderAdvertisingParameters,
GattServiceProviderAdvertisementStatusChangedEventArgs as StatusChangeEvent, # noqa: E501
GattReadRequestedEventArgs,
GattReadRequest,
GattWriteRequestedEventArgs,
GattWriteRequest,
GattSubscribedClient,
)

logger = logging.getLogger(__name__)

Expand Down
19 changes: 13 additions & 6 deletions bless/backends/winrt/service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import sys
from uuid import UUID
from typing import Union, cast, TYPE_CHECKING

from bleak_winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E501
GattServiceProviderResult,
GattServiceProvider,
GattLocalService,
)
if sys.version_info >= (3, 12):
from winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E501
GattServiceProviderResult,
GattServiceProvider,
GattLocalService,
)
else:
from bleak_winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E501
GattServiceProviderResult,
GattServiceProvider,
GattLocalService,
)

from bleak.backends.winrt.service import BleakGATTServiceWinRT # type: ignore
from bless.backends.service import BlessGATTService
Expand Down
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
"pywin32;platform_system=='Windows'",
"dbus_next;platform_system=='Linux'",
"pysetupdi @ git+https://github.com/gwangyi/pysetupdi#egg=pysetupdi;platform_system=='Windows'", # noqa: E501
'bleak-winrt>=1.2.0; platform_system=="Windows" and python_version<"3.12"',
'winrt-Windows.Devices.Bluetooth==2.0.0b1; platform_system=="Windows" and python_version>="3.12"',
'winrt-Windows.Devices.Bluetooth.Advertisement==2.0.0b1; platform_system=="Windows" and python_version>="3.12"',
'winrt-Windows.Devices.Bluetooth.GenericAttributeProfile==2.0.0b1; platform_system=="Windows" and python_version>="3.12"',
'winrt-Windows.Devices.Enumeration==2.0.0b1; platform_system=="Windows" and python_version>="3.12"',
'winrt-Windows.Foundation==2.0.0b1; platform_system=="Windows" and python_version>="3.12"',
'winrt-Windows.Foundation.Collections==2.0.0b1; platform_system=="Windows" and python_version>="3.12"',
'winrt-Windows.Storage.Streams==2.0.0b1; platform_system=="Windows" and python_version>="3.12"',
],
classifiers=[
"Programming Language :: Python :: 3",
Expand Down
60 changes: 40 additions & 20 deletions test/backends/winrt/test_serviceprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,46 @@
GATTAttributePermissions,
)

from bleak_winrt.windows.foundation import Deferral # type: ignore # noqa: E402 E501

from bleak_winrt.windows.storage.streams import DataReader, DataWriter # type: ignore # noqa: E402 E501

from bleak_winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E402 F401 E501
GattWriteOption,
GattServiceProviderResult,
GattServiceProvider,
GattLocalService,
GattLocalCharacteristicResult,
GattLocalCharacteristic,
GattLocalCharacteristicParameters,
GattServiceProviderAdvertisingParameters,
GattServiceProviderAdvertisementStatusChangedEventArgs,
GattReadRequestedEventArgs,
GattReadRequest,
GattWriteRequestedEventArgs,
GattWriteRequest,
GattSubscribedClient,
)
if sys.version_info >= (3, 12):
from winrt.windows.foundation import Deferral # type: ignore # noqa: E402 E501
from winrt.windows.storage.streams import DataReader, DataWriter # type: ignore # noqa: E402 E501
from winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E402 F401 E501
GattWriteOption,
GattServiceProviderResult,
GattServiceProvider,
GattLocalService,
GattLocalCharacteristicResult,
GattLocalCharacteristic,
GattLocalCharacteristicParameters,
GattServiceProviderAdvertisingParameters,
GattServiceProviderAdvertisementStatusChangedEventArgs,
GattReadRequestedEventArgs,
GattReadRequest,
GattWriteRequestedEventArgs,
GattWriteRequest,
GattSubscribedClient,
)
else:
from bleak_winrt.windows.foundation import Deferral # type: ignore # noqa: E402 E501

from bleak_winrt.windows.storage.streams import DataReader, DataWriter # type: ignore # noqa: E402 E501

from bleak_winrt.windows.devices.bluetooth.genericattributeprofile import ( # type: ignore # noqa: E402 F401 E501
GattWriteOption,
GattServiceProviderResult,
GattServiceProvider,
GattLocalService,
GattLocalCharacteristicResult,
GattLocalCharacteristic,
GattLocalCharacteristicParameters,
GattServiceProviderAdvertisingParameters,
GattServiceProviderAdvertisementStatusChangedEventArgs,
GattReadRequestedEventArgs,
GattReadRequest,
GattWriteRequestedEventArgs,
GattWriteRequest,
GattSubscribedClient,
)


@hardware_only
Expand Down

0 comments on commit 10b611f

Please sign in to comment.