Skip to content

Commit 322346d

Browse files
committed
sort imports with isort
- Add isort to pyproject.toml - Format code using isort - Add isort to CI lint checks
1 parent 86b28ac commit 322346d

24 files changed

+61
-41
lines changed

.github/workflows/format_and_lint.yml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
uses: actions/setup-python@v4
1717
- name: Install development dependencies
1818
run: pipx run poetry install --only docs,lint
19+
- name: Check import sort with isort
20+
run: pipx run poetry run isort . --check --diff
1921
- name: Check code formatting with black
2022
run: pipx run poetry run black . --check --diff
2123
- name: Lint with flake8

CONTRIBUTING.rst

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ and your favorite text editor. And Python of course.
8181

8282
5. When you're done making changes, check that your changes pass linting and the tests::
8383

84+
$ poetry run isort .
8485
$ poetry run black .
8586
$ poetry run flake8
8687
$ poetry run pytest

bleak/__init__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import os
1515
import sys
1616
import uuid
17+
from types import TracebackType
1718
from typing import (
1819
TYPE_CHECKING,
1920
AsyncGenerator,
@@ -22,6 +23,7 @@
2223
Dict,
2324
Iterable,
2425
List,
26+
Literal,
2527
Optional,
2628
Set,
2729
Tuple,
@@ -31,8 +33,6 @@
3133
overload,
3234
)
3335
from warnings import warn
34-
from typing import Literal
35-
from types import TracebackType
3636

3737
if sys.version_info < (3, 12):
3838
from typing_extensions import Buffer
@@ -46,7 +46,6 @@
4646
from asyncio import timeout as async_timeout
4747
from typing import Unpack
4848

49-
5049
from .backends.characteristic import BleakGATTCharacteristic
5150
from .backends.client import BaseBleakClient, get_platform_client_backend_type
5251
from .backends.device import BLEDevice

bleak/backends/bluezdbus/advertisement_monitor.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
import logging
1010
from typing import Iterable, NamedTuple, Tuple, Union, no_type_check
1111

12-
from dbus_fast.service import ServiceInterface, dbus_property, method, PropertyAccess
12+
from dbus_fast.service import PropertyAccess, ServiceInterface, dbus_property, method
1313

14-
from . import defs
1514
from ...assigned_numbers import AdvertisementDataType
16-
15+
from . import defs
1716

1817
logger = logging.getLogger(__name__)
1918

bleak/backends/bluezdbus/manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333
from . import defs
3434
from .advertisement_monitor import AdvertisementMonitor, OrPatternLike
3535
from .characteristic import BleakGATTCharacteristicBlueZDBus
36-
from .defs import Device1, GattService1, GattCharacteristic1, GattDescriptor1
36+
from .defs import Device1, GattCharacteristic1, GattDescriptor1, GattService1
3737
from .descriptor import BleakGATTDescriptorBlueZDBus
3838
from .service import BleakGATTServiceBlueZDBus
3939
from .signals import MatchRules, add_match
4040
from .utils import (
4141
assert_reply,
42-
get_dbus_authenticator,
4342
device_path_from_characteristic_path,
43+
get_dbus_authenticator,
4444
)
4545

4646
logger = logging.getLogger(__name__)

bleak/backends/bluezdbus/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dbus_fast.constants import MessageType
77
from dbus_fast.message import Message
88

9-
from ...exc import BleakError, BleakDBusError
9+
from ...exc import BleakDBusError, BleakError
1010

1111

1212
def assert_reply(reply: Message) -> None:

bleak/backends/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from collections.abc import Buffer
2121

2222
from ..exc import BleakError
23-
from .service import BleakGATTServiceCollection
2423
from .characteristic import BleakGATTCharacteristic
2524
from .device import BLEDevice
25+
from .service import BleakGATTServiceCollection
2626

2727
NotifyCallback = Callable[[bytearray], None]
2828

bleak/backends/corebluetooth/CentralManagerDelegate.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import objc
2121
from CoreBluetooth import (
22+
CBUUID,
2223
CBCentralManager,
2324
CBManagerStatePoweredOff,
2425
CBManagerStatePoweredOn,
@@ -27,9 +28,9 @@
2728
CBManagerStateUnknown,
2829
CBManagerStateUnsupported,
2930
CBPeripheral,
30-
CBUUID,
3131
)
3232
from Foundation import (
33+
NSUUID,
3334
NSArray,
3435
NSDictionary,
3536
NSError,
@@ -38,9 +39,8 @@
3839
NSNumber,
3940
NSObject,
4041
NSString,
41-
NSUUID,
4242
)
43-
from libdispatch import dispatch_queue_create, DISPATCH_QUEUE_SERIAL
43+
from libdispatch import DISPATCH_QUEUE_SERIAL, dispatch_queue_create
4444

4545
from ...exc import BleakError
4646

bleak/backends/corebluetooth/PeripheralDelegate.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
from asyncio import timeout as async_timeout
2121

2222
import objc
23-
from Foundation import NSNumber, NSObject, NSArray, NSData, NSError, NSUUID, NSString
2423
from CoreBluetooth import (
25-
CBPeripheral,
26-
CBService,
2724
CBCharacteristic,
28-
CBDescriptor,
2925
CBCharacteristicWriteWithResponse,
26+
CBDescriptor,
27+
CBPeripheral,
28+
CBService,
3029
)
30+
from Foundation import NSUUID, NSArray, NSData, NSError, NSNumber, NSObject, NSString
3131

3232
from ...exc import BleakError
3333
from ..client import NotifyCallback

bleak/backends/corebluetooth/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from Foundation import NSData
21
from CoreBluetooth import CBUUID
2+
from Foundation import NSData
33

44
from ...uuids import normalize_uuid_str
55

bleak/backends/p4android/defs.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import enum
44

5-
import bleak.exc
65
from jnius import autoclass, cast
76

7+
import bleak.exc
8+
89
# caching constants avoids unnecessary extra use of the jni-python interface, which can be slow
910

1011
List = autoclass("java.util.ArrayList")

bleak/backends/p4android/recipes/bleak/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
2+
from os.path import join
23

3-
from pythonforandroid.recipe import PythonRecipe
4-
from pythonforandroid.toolchain import shprint, info
54
import sh
6-
from os.path import join
5+
from pythonforandroid.recipe import PythonRecipe
6+
from pythonforandroid.toolchain import info, shprint
77

88

99
class BleakRecipe(PythonRecipe):

bleak/backends/service.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from uuid import UUID
1212

1313
from ..exc import BleakError
14-
from ..uuids import uuidstr_to_str, normalize_uuid_str
14+
from ..uuids import normalize_uuid_str, uuidstr_to_str
1515
from .characteristic import BleakGATTCharacteristic
1616
from .descriptor import BleakGATTDescriptor
1717

bleak/uuids.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import Dict
44
from uuid import UUID
55

6-
76
uuid16_dict: Dict[int, str] = {
87
0x0001: "SDP",
98
0x0003: "RFCOMM",

examples/async_callback_with_queue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"""
1212

1313
import argparse
14-
import time
1514
import asyncio
1615
import logging
16+
import time
1717

1818
from bleak import BleakClient, BleakScanner
1919

examples/disconnect_callback.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
import asyncio
1313
import logging
1414

15-
from bleak import BleakScanner, BleakClient
16-
15+
from bleak import BleakClient, BleakScanner
1716

1817
logger = logging.getLogger(__name__)
1918

examples/kivy/main.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import asyncio
2-
import bleak
32

3+
import bleak
44
from kivy.app import App
5-
6-
# from kivy.core.window import Window
75
from kivy.uix.label import Label
86
from kivy.uix.scrollview import ScrollView
97

108
# bind bleak's python logger into kivy's logger before importing python module using logging
11-
from kivy.logger import Logger
12-
import logging
9+
from kivy.logger import Logger # isort: skip
10+
import logging # isort: skip
1311

1412
logging.Logger.manager.root = Logger
1513

examples/mtu_size.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import asyncio
66

7-
from bleak import BleakScanner, BleakClient
8-
from bleak.backends.scanner import BLEDevice, AdvertisementData
7+
from bleak import BleakClient, BleakScanner
8+
from bleak.backends.scanner import AdvertisementData, BLEDevice
99

1010
# replace with real characteristic UUID
1111
CHAR_UUID = "00000000-0000-0000-0000-000000000000"

examples/philips_hue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
2323
"""
2424

25-
import sys
2625
import asyncio
26+
import sys
2727

2828
from bleak import BleakClient
2929

examples/two_devices.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
from typing import Iterable
66

7-
from bleak import BleakScanner, BleakClient
7+
from bleak import BleakClient, BleakScanner
88

99

1010
async def connect_to_device(

poetry.lock

+15-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+8-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ Sphinx = "^5.1.1"
4343
sphinx-rtd-theme = "^1.0.0"
4444

4545
[tool.poetry.group.lint.dependencies]
46-
black = ">=22.1,<25.0"
46+
black = ">=24.3,<25.0"
4747
flake8 = "^5.0.0"
48+
isort = "^5.13.2"
4849

4950
[tool.poetry.group.test.dependencies]
5051
pytest = "^7.0.0"
@@ -54,3 +55,9 @@ pytest-cov = "^3.0.0 "
5455
[build-system]
5556
requires = ["poetry-core"]
5657
build-backend = "poetry.core.masonry.api"
58+
59+
[tool.isort]
60+
profile = "black"
61+
py_version=38
62+
src_paths = ["bleak", "examples", "tests", "typings"]
63+
extend_skip = [".buildozer"]

tests/bleak/backends/bluezdbus/test_utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
"""Tests for `bleak.backends.bluezdbus.utils` package."""
44

5-
import pytest
65
import sys
76

7+
import pytest
8+
89

910
@pytest.mark.skipif(
1011
not sys.platform.startswith("linux"), reason="requires dbus-fast on Linux"

typings/CoreBluetooth/__init__.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from typing import Any, NewType, Optional, Type, TypeVar
22

3-
from ..libdispatch import dispatch_queue_t
43
from ..Foundation import (
4+
NSUUID,
55
NSArray,
66
NSData,
77
NSDictionary,
88
NSError,
99
NSNumber,
1010
NSObject,
1111
NSString,
12-
NSUUID,
1312
)
13+
from ..libdispatch import dispatch_queue_t
1414

1515
class CBManager(NSObject):
1616
def state(self) -> CBManagerState: ...

0 commit comments

Comments
 (0)