Skip to content

Commit

Permalink
sort imports with isort
Browse files Browse the repository at this point in the history
- Add isort to pyproject.toml
- Format code using isort
- Add isort to CI lint checks
  • Loading branch information
dlech committed Apr 29, 2024
1 parent 86b28ac commit 809c429
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/format_and_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
uses: actions/setup-python@v4
- name: Install development dependencies
run: pipx run poetry install --only docs,lint
- name: Check import sort with isort
run: pipx run poetry run isort . --check --diff
- name: Check code formatting with black
run: pipx run poetry run black . --check --diff
- name: Lint with flake8
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ and your favorite text editor. And Python of course.

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

$ poetry run isort .
$ poetry run black .
$ poetry run flake8
$ poetry run pytest
Expand Down
5 changes: 2 additions & 3 deletions bleak/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import sys
import uuid
from types import TracebackType
from typing import (
TYPE_CHECKING,
AsyncGenerator,
Expand All @@ -22,6 +23,7 @@
Dict,
Iterable,
List,
Literal,
Optional,
Set,
Tuple,
Expand All @@ -31,8 +33,6 @@
overload,
)
from warnings import warn
from typing import Literal
from types import TracebackType

if sys.version_info < (3, 12):
from typing_extensions import Buffer
Expand All @@ -46,7 +46,6 @@
from asyncio import timeout as async_timeout
from typing import Unpack


from .backends.characteristic import BleakGATTCharacteristic
from .backends.client import BaseBleakClient, get_platform_client_backend_type
from .backends.device import BLEDevice
Expand Down
5 changes: 2 additions & 3 deletions bleak/backends/bluezdbus/advertisement_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import logging
from typing import Iterable, NamedTuple, Tuple, Union, no_type_check

from dbus_fast.service import ServiceInterface, dbus_property, method, PropertyAccess
from dbus_fast.service import PropertyAccess, ServiceInterface, dbus_property, method

from . import defs
from ...assigned_numbers import AdvertisementDataType

from . import defs

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions bleak/backends/bluezdbus/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
from . import defs
from .advertisement_monitor import AdvertisementMonitor, OrPatternLike
from .characteristic import BleakGATTCharacteristicBlueZDBus
from .defs import Device1, GattService1, GattCharacteristic1, GattDescriptor1
from .defs import Device1, GattCharacteristic1, GattDescriptor1, GattService1
from .descriptor import BleakGATTDescriptorBlueZDBus
from .service import BleakGATTServiceBlueZDBus
from .signals import MatchRules, add_match
from .utils import (
assert_reply,
get_dbus_authenticator,
device_path_from_characteristic_path,
get_dbus_authenticator,
)

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion bleak/backends/bluezdbus/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dbus_fast.constants import MessageType
from dbus_fast.message import Message

from ...exc import BleakError, BleakDBusError
from ...exc import BleakDBusError, BleakError


def assert_reply(reply: Message) -> None:
Expand Down
2 changes: 1 addition & 1 deletion bleak/backends/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from collections.abc import Buffer

from ..exc import BleakError
from .service import BleakGATTServiceCollection
from .characteristic import BleakGATTCharacteristic
from .device import BLEDevice
from .service import BleakGATTServiceCollection

NotifyCallback = Callable[[bytearray], None]

Expand Down
6 changes: 3 additions & 3 deletions bleak/backends/corebluetooth/CentralManagerDelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import objc
from CoreBluetooth import (
CBUUID,
CBCentralManager,
CBManagerStatePoweredOff,
CBManagerStatePoweredOn,
Expand All @@ -27,9 +28,9 @@
CBManagerStateUnknown,
CBManagerStateUnsupported,
CBPeripheral,
CBUUID,
)
from Foundation import (
NSUUID,
NSArray,
NSDictionary,
NSError,
Expand All @@ -38,9 +39,8 @@
NSNumber,
NSObject,
NSString,
NSUUID,
)
from libdispatch import dispatch_queue_create, DISPATCH_QUEUE_SERIAL
from libdispatch import DISPATCH_QUEUE_SERIAL, dispatch_queue_create

from ...exc import BleakError

Expand Down
8 changes: 4 additions & 4 deletions bleak/backends/corebluetooth/PeripheralDelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
from asyncio import timeout as async_timeout

import objc
from Foundation import NSNumber, NSObject, NSArray, NSData, NSError, NSUUID, NSString
from CoreBluetooth import (
CBPeripheral,
CBService,
CBCharacteristic,
CBDescriptor,
CBCharacteristicWriteWithResponse,
CBDescriptor,
CBPeripheral,
CBService,
)
from Foundation import NSUUID, NSArray, NSData, NSError, NSNumber, NSObject, NSString

from ...exc import BleakError
from ..client import NotifyCallback
Expand Down
2 changes: 1 addition & 1 deletion bleak/backends/corebluetooth/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Foundation import NSData
from CoreBluetooth import CBUUID
from Foundation import NSData

from ...uuids import normalize_uuid_str

Expand Down
3 changes: 2 additions & 1 deletion bleak/backends/p4android/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import enum

import bleak.exc
from jnius import autoclass, cast

import bleak.exc

# caching constants avoids unnecessary extra use of the jni-python interface, which can be slow

List = autoclass("java.util.ArrayList")
Expand Down
6 changes: 3 additions & 3 deletions bleak/backends/p4android/recipes/bleak/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
from os.path import join

from pythonforandroid.recipe import PythonRecipe
from pythonforandroid.toolchain import shprint, info
import sh
from os.path import join
from pythonforandroid.recipe import PythonRecipe
from pythonforandroid.toolchain import info, shprint


class BleakRecipe(PythonRecipe):
Expand Down
2 changes: 1 addition & 1 deletion bleak/backends/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from uuid import UUID

from ..exc import BleakError
from ..uuids import uuidstr_to_str, normalize_uuid_str
from ..uuids import normalize_uuid_str, uuidstr_to_str
from .characteristic import BleakGATTCharacteristic
from .descriptor import BleakGATTDescriptor

Expand Down
1 change: 0 additions & 1 deletion bleak/uuids.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Dict
from uuid import UUID


uuid16_dict: Dict[int, str] = {
0x0001: "SDP",
0x0003: "RFCOMM",
Expand Down
2 changes: 1 addition & 1 deletion examples/async_callback_with_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"""

import argparse
import time
import asyncio
import logging
import time

from bleak import BleakClient, BleakScanner

Expand Down
3 changes: 1 addition & 2 deletions examples/disconnect_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import asyncio
import logging

from bleak import BleakScanner, BleakClient

from bleak import BleakClient, BleakScanner

logger = logging.getLogger(__name__)

Expand Down
8 changes: 3 additions & 5 deletions examples/kivy/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import asyncio
import bleak

import bleak
from kivy.app import App

# from kivy.core.window import Window
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView

# bind bleak's python logger into kivy's logger before importing python module using logging
from kivy.logger import Logger
import logging
from kivy.logger import Logger # isort: skip
import logging # isort: skip

logging.Logger.manager.root = Logger

Expand Down
4 changes: 2 additions & 2 deletions examples/mtu_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import asyncio

from bleak import BleakScanner, BleakClient
from bleak.backends.scanner import BLEDevice, AdvertisementData
from bleak import BleakClient, BleakScanner
from bleak.backends.scanner import AdvertisementData, BLEDevice

# replace with real characteristic UUID
CHAR_UUID = "00000000-0000-0000-0000-000000000000"
Expand Down
2 changes: 1 addition & 1 deletion examples/philips_hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"""

import sys
import asyncio
import sys

from bleak import BleakClient

Expand Down
2 changes: 1 addition & 1 deletion examples/two_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from typing import Iterable

from bleak import BleakScanner, BleakClient
from bleak import BleakClient, BleakScanner


async def connect_to_device(
Expand Down
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ Sphinx = "^5.1.1"
sphinx-rtd-theme = "^1.0.0"

[tool.poetry.group.lint.dependencies]
black = ">=22.1,<25.0"
black = ">=24.3,<25.0"
flake8 = "^5.0.0"
isort = "^5.13.2"

[tool.poetry.group.test.dependencies]
pytest = "^7.0.0"
Expand All @@ -54,3 +55,9 @@ pytest-cov = "^3.0.0 "
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.isort]
profile = "black"
py_version=38
src_paths = ["bleak", "examples", "tests", "typings"]
extend_skip = [".buildozer"]
3 changes: 2 additions & 1 deletion tests/bleak/backends/bluezdbus/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

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

import pytest
import sys

import pytest


@pytest.mark.skipif(
not sys.platform.startswith("linux"), reason="requires dbus-fast on Linux"
Expand Down
4 changes: 2 additions & 2 deletions typings/CoreBluetooth/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from typing import Any, NewType, Optional, Type, TypeVar

from ..libdispatch import dispatch_queue_t
from ..Foundation import (
NSUUID,
NSArray,
NSData,
NSDictionary,
NSError,
NSNumber,
NSObject,
NSString,
NSUUID,
)
from ..libdispatch import dispatch_queue_t

class CBManager(NSObject):
def state(self) -> CBManagerState: ...
Expand Down

0 comments on commit 809c429

Please sign in to comment.