From c3936e6f14596ba9106979951f34ac418e3f583c Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 8 Jun 2023 23:43:56 +0200 Subject: [PATCH] Replace isort with ruff (#94302) --- .github/workflows/ci.yaml | 41 ------------------- .pre-commit-config.yaml | 4 -- homeassistant/auth/providers/command_line.py | 2 +- homeassistant/auth/providers/homeassistant.py | 2 +- .../auth/providers/insecure_example.py | 2 +- .../auth/providers/legacy_api_password.py | 2 +- .../auth/providers/trusted_networks.py | 2 +- homeassistant/components/ads/sensor.py | 2 +- .../components/color_extractor/__init__.py | 2 +- .../components/generic/config_flow.py | 2 +- .../components/google_assistant/__init__.py | 2 +- .../components/huawei_lte/config_flow.py | 2 +- .../components/image_upload/__init__.py | 2 +- homeassistant/components/logger/__init__.py | 2 +- homeassistant/components/mqtt/subscription.py | 2 +- .../components/progettihwsw/__init__.py | 2 +- .../components/progettihwsw/binary_sensor.py | 2 +- .../components/progettihwsw/switch.py | 2 +- .../recorder/table_managers/event_data.py | 2 +- .../recorder/table_managers/event_types.py | 2 +- .../table_managers/state_attributes.py | 2 +- .../recorder/table_managers/states_meta.py | 2 +- .../remote_rpi_gpio/binary_sensor.py | 2 +- .../components/remote_rpi_gpio/switch.py | 2 +- homeassistant/components/rfxtrx/__init__.py | 2 +- .../components/rfxtrx/config_flow.py | 2 +- homeassistant/components/tellduslive/cover.py | 2 +- .../components/tensorflow/image_processing.py | 2 +- homeassistant/components/w800rf32/__init__.py | 2 +- .../components/w800rf32/binary_sensor.py | 2 +- .../zha/core/cluster_handlers/closures.py | 2 +- .../zha/core/cluster_handlers/general.py | 12 +++--- .../core/cluster_handlers/homeautomation.py | 2 +- .../zha/core/cluster_handlers/hvac.py | 2 +- .../zha/core/cluster_handlers/lighting.py | 2 +- .../zha/core/cluster_handlers/lightlink.py | 2 +- .../cluster_handlers/manufacturerspecific.py | 2 +- .../zha/core/cluster_handlers/measurement.py | 2 +- .../zha/core/cluster_handlers/protocol.py | 2 +- .../zha/core/cluster_handlers/security.py | 2 +- .../zha/core/cluster_handlers/smartenergy.py | 2 +- .../components/zha/core/discovery.py | 2 +- pylint/ruff.toml | 7 ++++ pyproject.toml | 22 ++++------ requirements_test_pre_commit.txt | 1 - script/ruff.toml | 7 ++++ .../tests/test_config_flow.py | 8 ++-- .../device_action/tests/test_device_action.py | 2 +- .../tests/test_device_condition.py | 2 +- .../tests/test_device_trigger.py | 2 +- tests/components/rfxtrx/test_device_action.py | 2 +- tests/components/vicare/conftest.py | 2 +- tests/components/vicare/test_config_flow.py | 2 +- tests/components/waze_travel_time/conftest.py | 2 +- .../waze_travel_time/test_sensor.py | 2 +- tests/ruff.toml | 16 ++++++++ 56 files changed, 95 insertions(+), 117 deletions(-) create mode 100644 pylint/ruff.toml create mode 100644 script/ruff.toml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8a99287b8697..b0aa9c74ea1f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -338,44 +338,6 @@ jobs: shopt -s globstar pre-commit run --hook-stage manual ruff --files {homeassistant,tests}/components/${{ needs.info.outputs.integrations_glob }}/{*,**/*} --show-diff-on-failure - lint-isort: - name: Check isort - runs-on: ubuntu-22.04 - needs: - - info - - pre-commit - steps: - - name: Check out code from GitHub - uses: actions/checkout@v3.5.2 - - name: Set up Python ${{ env.DEFAULT_PYTHON }} - uses: actions/setup-python@v4.6.1 - id: python - with: - python-version: ${{ env.DEFAULT_PYTHON }} - check-latest: true - - name: Restore base Python virtual environment - id: cache-venv - uses: actions/cache/restore@v3.3.1 - with: - path: venv - fail-on-cache-miss: true - key: >- - ${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv-${{ - needs.info.outputs.pre-commit_cache_key }} - - name: Restore pre-commit environment from cache - id: cache-precommit - uses: actions/cache/restore@v3.3.1 - with: - path: ${{ env.PRE_COMMIT_CACHE }} - fail-on-cache-miss: true - key: >- - ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ - needs.info.outputs.pre-commit_cache_key }} - - name: Run isort - run: | - . venv/bin/activate - pre-commit run --hook-stage manual isort --all-files --show-diff-on-failure - lint-other: name: Check other linters runs-on: ubuntu-22.04 @@ -719,7 +681,6 @@ jobs: - base - gen-requirements-all - hassfest - - lint-isort - lint-other - lint-ruff - mypy @@ -844,7 +805,6 @@ jobs: - base - gen-requirements-all - hassfest - - lint-isort - lint-other - lint-ruff - mypy @@ -952,7 +912,6 @@ jobs: - base - gen-requirements-all - hassfest - - lint-isort - lint-other - lint-ruff - mypy diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3fac4229f8cb..d6cd3f43b105 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,10 +22,6 @@ repos: - --quiet-level=2 exclude_types: [csv, json] exclude: ^tests/fixtures/|homeassistant/generated/ - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: diff --git a/homeassistant/auth/providers/command_line.py b/homeassistant/auth/providers/command_line.py index f63d6d465f6a..bfe8a2fdddb5 100644 --- a/homeassistant/auth/providers/command_line.py +++ b/homeassistant/auth/providers/command_line.py @@ -13,8 +13,8 @@ from homeassistant.const import CONF_COMMAND from homeassistant.data_entry_flow import FlowResult from homeassistant.exceptions import HomeAssistantError -from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow from ..models import Credentials, UserMeta +from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow CONF_ARGS = "args" CONF_META = "meta" diff --git a/homeassistant/auth/providers/homeassistant.py b/homeassistant/auth/providers/homeassistant.py index 050a0660a6b6..6f621b93a6af 100644 --- a/homeassistant/auth/providers/homeassistant.py +++ b/homeassistant/auth/providers/homeassistant.py @@ -16,8 +16,8 @@ from homeassistant.data_entry_flow import FlowResult from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.storage import Store -from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow from ..models import Credentials, UserMeta +from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow STORAGE_VERSION = 1 STORAGE_KEY = "auth_provider.homeassistant" diff --git a/homeassistant/auth/providers/insecure_example.py b/homeassistant/auth/providers/insecure_example.py index 47626686f9df..f7f01e74c270 100644 --- a/homeassistant/auth/providers/insecure_example.py +++ b/homeassistant/auth/providers/insecure_example.py @@ -11,8 +11,8 @@ from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult from homeassistant.exceptions import HomeAssistantError -from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow from ..models import Credentials, UserMeta +from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow USER_SCHEMA = vol.Schema( { diff --git a/homeassistant/auth/providers/legacy_api_password.py b/homeassistant/auth/providers/legacy_api_password.py index 72ba3b1ecb3e..0cadbf075893 100644 --- a/homeassistant/auth/providers/legacy_api_password.py +++ b/homeassistant/auth/providers/legacy_api_password.py @@ -15,8 +15,8 @@ from homeassistant.data_entry_flow import FlowResult from homeassistant.exceptions import HomeAssistantError import homeassistant.helpers.config_validation as cv -from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow from ..models import Credentials, UserMeta +from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow AUTH_PROVIDER_TYPE = "legacy_api_password" CONF_API_PASSWORD = "api_password" diff --git a/homeassistant/auth/providers/trusted_networks.py b/homeassistant/auth/providers/trusted_networks.py index 04db5fc287b7..6962671cb2fd 100644 --- a/homeassistant/auth/providers/trusted_networks.py +++ b/homeassistant/auth/providers/trusted_networks.py @@ -23,9 +23,9 @@ from homeassistant.data_entry_flow import FlowResult from homeassistant.exceptions import HomeAssistantError import homeassistant.helpers.config_validation as cv -from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow from .. import InvalidAuthError from ..models import Credentials, RefreshToken, UserMeta +from . import AUTH_PROVIDER_SCHEMA, AUTH_PROVIDERS, AuthProvider, LoginFlow IPAddress = IPv4Address | IPv6Address IPNetwork = IPv4Network | IPv6Network diff --git a/homeassistant/components/ads/sensor.py b/homeassistant/components/ads/sensor.py index 76d73f75a8b3..17aede2bd2bb 100644 --- a/homeassistant/components/ads/sensor.py +++ b/homeassistant/components/ads/sensor.py @@ -10,6 +10,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType +from .. import ads from . import ( ADS_TYPEMAP, CONF_ADS_FACTOR, @@ -18,7 +19,6 @@ from . import ( STATE_KEY_STATE, AdsEntity, ) -from .. import ads DEFAULT_NAME = "ADS sensor" PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( diff --git a/homeassistant/components/color_extractor/__init__.py b/homeassistant/components/color_extractor/__init__.py index aa2d9cfbfdb2..d0a6b53964bd 100644 --- a/homeassistant/components/color_extractor/__init__.py +++ b/homeassistant/components/color_extractor/__init__.py @@ -3,10 +3,10 @@ import asyncio import io import logging -from PIL import UnidentifiedImageError import aiohttp import async_timeout from colorthief import ColorThief +from PIL import UnidentifiedImageError import voluptuous as vol from homeassistant.components.light import ( diff --git a/homeassistant/components/generic/config_flow.py b/homeassistant/components/generic/config_flow.py index 94a885a7c5d3..d48c4619abdb 100644 --- a/homeassistant/components/generic/config_flow.py +++ b/homeassistant/components/generic/config_flow.py @@ -9,10 +9,10 @@ import io import logging from typing import Any -import PIL from aiohttp import web from async_timeout import timeout from httpx import HTTPStatusError, RequestError, TimeoutException +import PIL import voluptuous as vol import yarl diff --git a/homeassistant/components/google_assistant/__init__.py b/homeassistant/components/google_assistant/__init__.py index 3a0315a59312..37f3a2c3edc2 100644 --- a/homeassistant/components/google_assistant/__init__.py +++ b/homeassistant/components/google_assistant/__init__.py @@ -28,10 +28,10 @@ from .const import ( # noqa: F401 DEFAULT_EXPOSE_BY_DEFAULT, DEFAULT_EXPOSED_DOMAINS, DOMAIN, + EVENT_QUERY_RECEIVED, # noqa: F401 SERVICE_REQUEST_SYNC, SOURCE_CLOUD, ) -from .const import EVENT_QUERY_RECEIVED # noqa: F401 from .http import GoogleAssistantView, GoogleConfig from .const import EVENT_COMMAND_RECEIVED, EVENT_SYNC_RECEIVED # noqa: F401, isort:skip diff --git a/homeassistant/components/huawei_lte/config_flow.py b/homeassistant/components/huawei_lte/config_flow.py index f6c3b69ddeb6..6d7b0b9bb115 100644 --- a/homeassistant/components/huawei_lte/config_flow.py +++ b/homeassistant/components/huawei_lte/config_flow.py @@ -8,7 +8,6 @@ from urllib.parse import urlparse from huawei_lte_api.Client import Client from huawei_lte_api.Connection import Connection -from huawei_lte_api.Session import GetResponseType from huawei_lte_api.exceptions import ( LoginErrorPasswordWrongException, LoginErrorUsernamePasswordOverrunException, @@ -16,6 +15,7 @@ from huawei_lte_api.exceptions import ( LoginErrorUsernameWrongException, ResponseErrorException, ) +from huawei_lte_api.Session import GetResponseType from requests.exceptions import Timeout from url_normalize import url_normalize import voluptuous as vol diff --git a/homeassistant/components/image_upload/__init__.py b/homeassistant/components/image_upload/__init__.py index 766be89f0d4a..569df9c65e40 100644 --- a/homeassistant/components/image_upload/__init__.py +++ b/homeassistant/components/image_upload/__init__.py @@ -8,9 +8,9 @@ import secrets import shutil from typing import Any -from PIL import Image, ImageOps, UnidentifiedImageError from aiohttp import hdrs, web from aiohttp.web_request import FileField +from PIL import Image, ImageOps, UnidentifiedImageError import voluptuous as vol from homeassistant.components.http.static import CACHE_HEADERS diff --git a/homeassistant/components/logger/__init__.py b/homeassistant/components/logger/__init__.py index b1086d7f780e..cd2761510d3e 100644 --- a/homeassistant/components/logger/__init__.py +++ b/homeassistant/components/logger/__init__.py @@ -14,6 +14,7 @@ from . import websocket_api from .const import ( ATTR_LEVEL, DOMAIN, + EVENT_LOGGING_CHANGED, # noqa: F401 LOGGER_DEFAULT, LOGGER_FILTERS, LOGGER_LOGS, @@ -21,7 +22,6 @@ from .const import ( SERVICE_SET_DEFAULT_LEVEL, SERVICE_SET_LEVEL, ) -from .const import EVENT_LOGGING_CHANGED # noqa: F401 from .helpers import ( LoggerDomainConfig, LoggerSettings, diff --git a/homeassistant/components/mqtt/subscription.py b/homeassistant/components/mqtt/subscription.py index 7ccc31bd3357..dda80bba84e2 100644 --- a/homeassistant/components/mqtt/subscription.py +++ b/homeassistant/components/mqtt/subscription.py @@ -8,8 +8,8 @@ import attr from homeassistant.core import HomeAssistant -from . import debug_info from .. import mqtt +from . import debug_info from .const import DEFAULT_QOS from .models import MessageCallbackType diff --git a/homeassistant/components/progettihwsw/__init__.py b/homeassistant/components/progettihwsw/__init__.py index bce25c07b175..d1d27b78769a 100644 --- a/homeassistant/components/progettihwsw/__init__.py +++ b/homeassistant/components/progettihwsw/__init__.py @@ -1,7 +1,7 @@ """Automation manager for boards manufactured by ProgettiHWSW Italy.""" -from ProgettiHWSW.ProgettiHWSWAPI import ProgettiHWSWAPI from ProgettiHWSW.input import Input +from ProgettiHWSW.ProgettiHWSWAPI import ProgettiHWSWAPI from ProgettiHWSW.relay import Relay from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/progettihwsw/binary_sensor.py b/homeassistant/components/progettihwsw/binary_sensor.py index 058d76cdf05d..b2019389fe3e 100644 --- a/homeassistant/components/progettihwsw/binary_sensor.py +++ b/homeassistant/components/progettihwsw/binary_sensor.py @@ -2,8 +2,8 @@ from datetime import timedelta import logging -from ProgettiHWSW.input import Input import async_timeout +from ProgettiHWSW.input import Input from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/progettihwsw/switch.py b/homeassistant/components/progettihwsw/switch.py index 956848a65942..dc7f838bcbc1 100644 --- a/homeassistant/components/progettihwsw/switch.py +++ b/homeassistant/components/progettihwsw/switch.py @@ -3,8 +3,8 @@ from datetime import timedelta import logging from typing import Any -from ProgettiHWSW.relay import Relay import async_timeout +from ProgettiHWSW.relay import Relay from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/recorder/table_managers/event_data.py b/homeassistant/components/recorder/table_managers/event_data.py index 4e08719e572c..85266a379398 100644 --- a/homeassistant/components/recorder/table_managers/event_data.py +++ b/homeassistant/components/recorder/table_managers/event_data.py @@ -10,11 +10,11 @@ from sqlalchemy.orm.session import Session from homeassistant.core import Event from homeassistant.util.json import JSON_ENCODE_EXCEPTIONS -from . import BaseLRUTableManager from ..const import SQLITE_MAX_BIND_VARS from ..db_schema import EventData from ..queries import get_shared_event_datas from ..util import chunked, execute_stmt_lambda_element +from . import BaseLRUTableManager if TYPE_CHECKING: from ..core import Recorder diff --git a/homeassistant/components/recorder/table_managers/event_types.py b/homeassistant/components/recorder/table_managers/event_types.py index d5541c547d51..fd03bdd14d2f 100644 --- a/homeassistant/components/recorder/table_managers/event_types.py +++ b/homeassistant/components/recorder/table_managers/event_types.py @@ -9,12 +9,12 @@ from sqlalchemy.orm.session import Session from homeassistant.core import Event -from . import BaseLRUTableManager from ..const import SQLITE_MAX_BIND_VARS from ..db_schema import EventTypes from ..queries import find_event_type_ids from ..tasks import RefreshEventTypesTask from ..util import chunked, execute_stmt_lambda_element +from . import BaseLRUTableManager if TYPE_CHECKING: from ..core import Recorder diff --git a/homeassistant/components/recorder/table_managers/state_attributes.py b/homeassistant/components/recorder/table_managers/state_attributes.py index 442277be96ec..3ae67b932bf4 100644 --- a/homeassistant/components/recorder/table_managers/state_attributes.py +++ b/homeassistant/components/recorder/table_managers/state_attributes.py @@ -11,11 +11,11 @@ from homeassistant.core import Event from homeassistant.helpers.entity import entity_sources from homeassistant.util.json import JSON_ENCODE_EXCEPTIONS -from . import BaseLRUTableManager from ..const import SQLITE_MAX_BIND_VARS from ..db_schema import StateAttributes from ..queries import get_shared_attributes from ..util import chunked, execute_stmt_lambda_element +from . import BaseLRUTableManager if TYPE_CHECKING: from ..core import Recorder diff --git a/homeassistant/components/recorder/table_managers/states_meta.py b/homeassistant/components/recorder/table_managers/states_meta.py index bc4a8cfd2d9b..b8f6204d3182 100644 --- a/homeassistant/components/recorder/table_managers/states_meta.py +++ b/homeassistant/components/recorder/table_managers/states_meta.py @@ -8,11 +8,11 @@ from sqlalchemy.orm.session import Session from homeassistant.core import Event -from . import BaseLRUTableManager from ..const import SQLITE_MAX_BIND_VARS from ..db_schema import StatesMeta from ..queries import find_all_states_metadata_ids, find_states_metadata_ids from ..util import chunked, execute_stmt_lambda_element +from . import BaseLRUTableManager if TYPE_CHECKING: from ..core import Recorder diff --git a/homeassistant/components/remote_rpi_gpio/binary_sensor.py b/homeassistant/components/remote_rpi_gpio/binary_sensor.py index 37994830c4d7..bc0e694e8eba 100644 --- a/homeassistant/components/remote_rpi_gpio/binary_sensor.py +++ b/homeassistant/components/remote_rpi_gpio/binary_sensor.py @@ -11,6 +11,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType +from .. import remote_rpi_gpio from . import ( CONF_BOUNCETIME, CONF_INVERT_LOGIC, @@ -19,7 +20,6 @@ from . import ( DEFAULT_INVERT_LOGIC, DEFAULT_PULL_MODE, ) -from .. import remote_rpi_gpio CONF_PORTS = "ports" diff --git a/homeassistant/components/remote_rpi_gpio/switch.py b/homeassistant/components/remote_rpi_gpio/switch.py index 862efb0f89d9..962cf6b4f3c2 100644 --- a/homeassistant/components/remote_rpi_gpio/switch.py +++ b/homeassistant/components/remote_rpi_gpio/switch.py @@ -12,8 +12,8 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from . import CONF_INVERT_LOGIC, DEFAULT_INVERT_LOGIC from .. import remote_rpi_gpio +from . import CONF_INVERT_LOGIC, DEFAULT_INVERT_LOGIC CONF_PORTS = "ports" diff --git a/homeassistant/components/rfxtrx/__init__.py b/homeassistant/components/rfxtrx/__init__.py index de8a9fc6b8de..0edd6f821957 100644 --- a/homeassistant/components/rfxtrx/__init__.py +++ b/homeassistant/components/rfxtrx/__init__.py @@ -8,8 +8,8 @@ import copy import logging from typing import Any, NamedTuple, cast -import RFXtrx as rfxtrxmod import async_timeout +import RFXtrx as rfxtrxmod import voluptuous as vol from homeassistant.config_entries import ConfigEntry diff --git a/homeassistant/components/rfxtrx/config_flow.py b/homeassistant/components/rfxtrx/config_flow.py index 2e054ce47245..8d55208cbb7a 100644 --- a/homeassistant/components/rfxtrx/config_flow.py +++ b/homeassistant/components/rfxtrx/config_flow.py @@ -8,8 +8,8 @@ import itertools import os from typing import Any, TypedDict, cast -import RFXtrx as rfxtrxmod from async_timeout import timeout +import RFXtrx as rfxtrxmod import serial import serial.tools.list_ports import voluptuous as vol diff --git a/homeassistant/components/tellduslive/cover.py b/homeassistant/components/tellduslive/cover.py index 57da852a3561..4934bf811aff 100644 --- a/homeassistant/components/tellduslive/cover.py +++ b/homeassistant/components/tellduslive/cover.py @@ -8,8 +8,8 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import TelldusLiveClient from .. import tellduslive +from . import TelldusLiveClient from .entry import TelldusLiveEntity diff --git a/homeassistant/components/tensorflow/image_processing.py b/homeassistant/components/tensorflow/image_processing.py index 60e9dc54b80a..a149ea92371d 100644 --- a/homeassistant/components/tensorflow/image_processing.py +++ b/homeassistant/components/tensorflow/image_processing.py @@ -7,8 +7,8 @@ import os import sys import time -from PIL import Image, ImageDraw, UnidentifiedImageError import numpy as np +from PIL import Image, ImageDraw, UnidentifiedImageError import tensorflow as tf # pylint: disable=import-error import voluptuous as vol diff --git a/homeassistant/components/w800rf32/__init__.py b/homeassistant/components/w800rf32/__init__.py index 88aaa934a7b7..29701ec82ab0 100644 --- a/homeassistant/components/w800rf32/__init__.py +++ b/homeassistant/components/w800rf32/__init__.py @@ -1,8 +1,8 @@ """Support for w800rf32 devices.""" import logging -import W800rf32 as w800 import voluptuous as vol +import W800rf32 as w800 from homeassistant.const import ( CONF_DEVICE, diff --git a/homeassistant/components/w800rf32/binary_sensor.py b/homeassistant/components/w800rf32/binary_sensor.py index 040074699929..6d1ce5c61c0e 100644 --- a/homeassistant/components/w800rf32/binary_sensor.py +++ b/homeassistant/components/w800rf32/binary_sensor.py @@ -3,8 +3,8 @@ from __future__ import annotations import logging -import W800rf32 as w800 import voluptuous as vol +import W800rf32 as w800 from homeassistant.components.binary_sensor import ( DEVICE_CLASSES_SCHEMA, diff --git a/homeassistant/components/zha/core/cluster_handlers/closures.py b/homeassistant/components/zha/core/cluster_handlers/closures.py index ab58405b9741..0c1ca20ae96b 100644 --- a/homeassistant/components/zha/core/cluster_handlers/closures.py +++ b/homeassistant/components/zha/core/cluster_handlers/closures.py @@ -3,9 +3,9 @@ from zigpy.zcl.clusters import closures from homeassistant.core import callback -from . import AttrReportConfig, ClientClusterHandler, ClusterHandler from .. import registries from ..const import REPORT_CONFIG_IMMEDIATE, SIGNAL_ATTR_UPDATED +from . import AttrReportConfig, ClientClusterHandler, ClusterHandler @registries.ZIGBEE_CLUSTER_HANDLER_REGISTRY.register(closures.DoorLock.cluster_id) diff --git a/homeassistant/components/zha/core/cluster_handlers/general.py b/homeassistant/components/zha/core/cluster_handlers/general.py index d4014bbf697f..8f47eda6e71f 100644 --- a/homeassistant/components/zha/core/cluster_handlers/general.py +++ b/homeassistant/components/zha/core/cluster_handlers/general.py @@ -14,12 +14,6 @@ from zigpy.zcl.foundation import Status from homeassistant.core import callback from homeassistant.helpers.event import async_call_later -from . import ( - AttrReportConfig, - ClientClusterHandler, - ClusterHandler, - parse_and_log_command, -) from .. import registries from ..const import ( REPORT_CONFIG_ASAP, @@ -33,6 +27,12 @@ from ..const import ( SIGNAL_SET_LEVEL, SIGNAL_UPDATE_DEVICE, ) +from . import ( + AttrReportConfig, + ClientClusterHandler, + ClusterHandler, + parse_and_log_command, +) from .helpers import is_hue_motion_sensor if TYPE_CHECKING: diff --git a/homeassistant/components/zha/core/cluster_handlers/homeautomation.py b/homeassistant/components/zha/core/cluster_handlers/homeautomation.py index 981ed08ba00b..8ca014f453ed 100644 --- a/homeassistant/components/zha/core/cluster_handlers/homeautomation.py +++ b/homeassistant/components/zha/core/cluster_handlers/homeautomation.py @@ -5,7 +5,6 @@ import enum from zigpy.zcl.clusters import homeautomation -from . import AttrReportConfig, ClusterHandler from .. import registries from ..const import ( CLUSTER_HANDLER_ELECTRICAL_MEASUREMENT, @@ -13,6 +12,7 @@ from ..const import ( REPORT_CONFIG_OP, SIGNAL_ATTR_UPDATED, ) +from . import AttrReportConfig, ClusterHandler @registries.ZIGBEE_CLUSTER_HANDLER_REGISTRY.register( diff --git a/homeassistant/components/zha/core/cluster_handlers/hvac.py b/homeassistant/components/zha/core/cluster_handlers/hvac.py index 94154564e8c8..8fd28a1dba7d 100644 --- a/homeassistant/components/zha/core/cluster_handlers/hvac.py +++ b/homeassistant/components/zha/core/cluster_handlers/hvac.py @@ -14,7 +14,6 @@ from zigpy.zcl.foundation import Status from homeassistant.core import callback -from . import AttrReportConfig, ClusterHandler from .. import registries from ..const import ( REPORT_CONFIG_MAX_INT, @@ -22,6 +21,7 @@ from ..const import ( REPORT_CONFIG_OP, SIGNAL_ATTR_UPDATED, ) +from . import AttrReportConfig, ClusterHandler AttributeUpdateRecord = namedtuple("AttributeUpdateRecord", "attr_id, attr_name, value") REPORT_CONFIG_CLIMATE = (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 25) diff --git a/homeassistant/components/zha/core/cluster_handlers/lighting.py b/homeassistant/components/zha/core/cluster_handlers/lighting.py index 56f3c701aa1a..993ecca29cd1 100644 --- a/homeassistant/components/zha/core/cluster_handlers/lighting.py +++ b/homeassistant/components/zha/core/cluster_handlers/lighting.py @@ -5,9 +5,9 @@ from functools import cached_property from zigpy.zcl.clusters import lighting -from . import AttrReportConfig, ClientClusterHandler, ClusterHandler from .. import registries from ..const import REPORT_CONFIG_DEFAULT +from . import AttrReportConfig, ClientClusterHandler, ClusterHandler @registries.ZIGBEE_CLUSTER_HANDLER_REGISTRY.register(lighting.Ballast.cluster_id) diff --git a/homeassistant/components/zha/core/cluster_handlers/lightlink.py b/homeassistant/components/zha/core/cluster_handlers/lightlink.py index 437a4b4ecf88..bac4d8c09a9d 100644 --- a/homeassistant/components/zha/core/cluster_handlers/lightlink.py +++ b/homeassistant/components/zha/core/cluster_handlers/lightlink.py @@ -5,8 +5,8 @@ import zigpy.exceptions from zigpy.zcl.clusters import lightlink from zigpy.zcl.foundation import GENERAL_COMMANDS, GeneralCommand -from . import ClusterHandler, ClusterHandlerStatus from .. import registries +from . import ClusterHandler, ClusterHandlerStatus @registries.CLUSTER_HANDLER_ONLY_CLUSTERS.register(lightlink.LightLink.cluster_id) diff --git a/homeassistant/components/zha/core/cluster_handlers/manufacturerspecific.py b/homeassistant/components/zha/core/cluster_handlers/manufacturerspecific.py index d20888e1f553..9bdf49aadc17 100644 --- a/homeassistant/components/zha/core/cluster_handlers/manufacturerspecific.py +++ b/homeassistant/components/zha/core/cluster_handlers/manufacturerspecific.py @@ -10,7 +10,6 @@ import zigpy.zcl from homeassistant.core import callback -from . import AttrReportConfig, ClientClusterHandler, ClusterHandler from .. import registries from ..const import ( ATTR_ATTRIBUTE_ID, @@ -24,6 +23,7 @@ from ..const import ( SIGNAL_ATTR_UPDATED, UNKNOWN, ) +from . import AttrReportConfig, ClientClusterHandler, ClusterHandler if TYPE_CHECKING: from ..endpoint import Endpoint diff --git a/homeassistant/components/zha/core/cluster_handlers/measurement.py b/homeassistant/components/zha/core/cluster_handlers/measurement.py index 8b882a299f65..beeb6296e32f 100644 --- a/homeassistant/components/zha/core/cluster_handlers/measurement.py +++ b/homeassistant/components/zha/core/cluster_handlers/measurement.py @@ -6,7 +6,6 @@ from typing import TYPE_CHECKING import zigpy.zcl from zigpy.zcl.clusters import measurement -from . import AttrReportConfig, ClusterHandler from .. import registries from ..const import ( REPORT_CONFIG_DEFAULT, @@ -14,6 +13,7 @@ from ..const import ( REPORT_CONFIG_MAX_INT, REPORT_CONFIG_MIN_INT, ) +from . import AttrReportConfig, ClusterHandler from .helpers import is_hue_motion_sensor if TYPE_CHECKING: diff --git a/homeassistant/components/zha/core/cluster_handlers/protocol.py b/homeassistant/components/zha/core/cluster_handlers/protocol.py index 6398a8875b68..1643fe031cdc 100644 --- a/homeassistant/components/zha/core/cluster_handlers/protocol.py +++ b/homeassistant/components/zha/core/cluster_handlers/protocol.py @@ -1,8 +1,8 @@ """Protocol cluster handlers module for Zigbee Home Automation.""" from zigpy.zcl.clusters import protocol -from . import ClusterHandler from .. import registries +from . import ClusterHandler @registries.ZIGBEE_CLUSTER_HANDLER_REGISTRY.register( diff --git a/homeassistant/components/zha/core/cluster_handlers/security.py b/homeassistant/components/zha/core/cluster_handlers/security.py index 7e4951ad672e..56b925671e36 100644 --- a/homeassistant/components/zha/core/cluster_handlers/security.py +++ b/homeassistant/components/zha/core/cluster_handlers/security.py @@ -15,7 +15,6 @@ from zigpy.zcl.clusters.security import IasAce as AceCluster, IasZone from homeassistant.core import callback -from . import ClusterHandler, ClusterHandlerStatus from .. import registries from ..const import ( SIGNAL_ATTR_UPDATED, @@ -25,6 +24,7 @@ from ..const import ( WARNING_DEVICE_STROBE_HIGH, WARNING_DEVICE_STROBE_YES, ) +from . import ClusterHandler, ClusterHandlerStatus if TYPE_CHECKING: from ..endpoint import Endpoint diff --git a/homeassistant/components/zha/core/cluster_handlers/smartenergy.py b/homeassistant/components/zha/core/cluster_handlers/smartenergy.py index 1cb647ea313f..8fd38425dff3 100644 --- a/homeassistant/components/zha/core/cluster_handlers/smartenergy.py +++ b/homeassistant/components/zha/core/cluster_handlers/smartenergy.py @@ -8,7 +8,6 @@ from typing import TYPE_CHECKING import zigpy.zcl from zigpy.zcl.clusters import smartenergy -from . import AttrReportConfig, ClusterHandler from .. import registries from ..const import ( REPORT_CONFIG_ASAP, @@ -16,6 +15,7 @@ from ..const import ( REPORT_CONFIG_OP, SIGNAL_ATTR_UPDATED, ) +from . import AttrReportConfig, ClusterHandler if TYPE_CHECKING: from ..endpoint import Endpoint diff --git a/homeassistant/components/zha/core/discovery.py b/homeassistant/components/zha/core/discovery.py index e8b6f5f83048..0ca1c1362718 100644 --- a/homeassistant/components/zha/core/discovery.py +++ b/homeassistant/components/zha/core/discovery.py @@ -16,7 +16,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_registry import async_entries_for_device from homeassistant.helpers.typing import ConfigType -from . import const as zha_const, registries as zha_regs from .. import ( # noqa: F401 pylint: disable=unused-import, alarm_control_panel, binary_sensor, @@ -33,6 +32,7 @@ from .. import ( # noqa: F401 pylint: disable=unused-import, siren, switch, ) +from . import const as zha_const, registries as zha_regs # importing cluster handlers updates registries from .cluster_handlers import ( # noqa: F401 pylint: disable=unused-import, diff --git a/pylint/ruff.toml b/pylint/ruff.toml new file mode 100644 index 000000000000..271881141a92 --- /dev/null +++ b/pylint/ruff.toml @@ -0,0 +1,7 @@ +# This extend our general Ruff rules specifically for tests +extend = "../pyproject.toml" + +[isort] +known-third-party = [ + "pylint", +] \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 6fbd810626bc..60c534b8bf2c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,20 +77,6 @@ include = ["homeassistant*"] [tool.black] extend-exclude = "/generated/" -[tool.isort] -# https://github.com/PyCQA/isort/wiki/isort-Settings -profile = "black" -# will group `import x` and `from x import` of the same module. -force_sort_within_sections = true -known_first_party = [ - "homeassistant", - "tests", -] -forced_separate = [ - "tests", -] -combine_as_imports = true - [tool.pylint.MAIN] py-version = "3.10" ignore = [ @@ -248,6 +234,7 @@ select = [ "D", # docstrings "E", # pycodestyle "F", # pyflakes/autoflake + "I", # isort "ICN001", # import concentions; {name} should be imported as {asname} "PGH004", # Use specific rule codes when using noqa "PLC0414", # Useless import alias. Import alias does not rename original package. @@ -308,6 +295,13 @@ voluptuous = "vol" [tool.ruff.flake8-pytest-style] fixture-parentheses = false +[tool.ruff.isort] +force-sort-within-sections = true +known-first-party = [ + "homeassistant", +] +combine-as-imports = true + [tool.ruff.per-file-ignores] # Allow for main entry & scripts to write to stdout diff --git a/requirements_test_pre_commit.txt b/requirements_test_pre_commit.txt index cee1c684d8aa..eff26bcfe82e 100644 --- a/requirements_test_pre_commit.txt +++ b/requirements_test_pre_commit.txt @@ -2,6 +2,5 @@ black==23.3.0 codespell==2.2.2 -isort==5.12.0 ruff==0.0.272 yamllint==1.28.0 diff --git a/script/ruff.toml b/script/ruff.toml new file mode 100644 index 000000000000..9d77bf60af95 --- /dev/null +++ b/script/ruff.toml @@ -0,0 +1,7 @@ +# This extend our general Ruff rules specifically for tests +extend = "../pyproject.toml" + +[isort] +forced-separate = [ + "tests", +] \ No newline at end of file diff --git a/script/scaffold/templates/config_flow_oauth2/tests/test_config_flow.py b/script/scaffold/templates/config_flow_oauth2/tests/test_config_flow.py index bc087119c6e0..d0000b800df1 100644 --- a/script/scaffold/templates/config_flow_oauth2/tests/test_config_flow.py +++ b/script/scaffold/templates/config_flow_oauth2/tests/test_config_flow.py @@ -5,15 +5,15 @@ from unittest.mock import patch import pytest from homeassistant import config_entries +from homeassistant.components.application_credentials import ( + ClientCredential, + async_import_client_credential, +) from homeassistant.components.NEW_DOMAIN.const import ( DOMAIN, OAUTH2_AUTHORIZE, OAUTH2_TOKEN, ) -from homeassistant.components.application_credentials import ( - ClientCredential, - async_import_client_credential, -) from homeassistant.core import HomeAssistant from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.setup import async_setup_component diff --git a/script/scaffold/templates/device_action/tests/test_device_action.py b/script/scaffold/templates/device_action/tests/test_device_action.py index ce3f907b47b9..7807a1389f5d 100644 --- a/script/scaffold/templates/device_action/tests/test_device_action.py +++ b/script/scaffold/templates/device_action/tests/test_device_action.py @@ -2,8 +2,8 @@ import pytest from homeassistant.components import automation -from homeassistant.components.NEW_DOMAIN import DOMAIN from homeassistant.components.device_automation import DeviceAutomationType +from homeassistant.components.NEW_DOMAIN import DOMAIN from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr, entity_registry as er diff --git a/script/scaffold/templates/device_condition/tests/test_device_condition.py b/script/scaffold/templates/device_condition/tests/test_device_condition.py index 59781e24fe63..61ee7459bbfd 100644 --- a/script/scaffold/templates/device_condition/tests/test_device_condition.py +++ b/script/scaffold/templates/device_condition/tests/test_device_condition.py @@ -4,8 +4,8 @@ from __future__ import annotations import pytest from homeassistant.components import automation -from homeassistant.components.NEW_DOMAIN import DOMAIN from homeassistant.components.device_automation import DeviceAutomationType +from homeassistant.components.NEW_DOMAIN import DOMAIN from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import device_registry as dr, entity_registry as er diff --git a/script/scaffold/templates/device_trigger/tests/test_device_trigger.py b/script/scaffold/templates/device_trigger/tests/test_device_trigger.py index 8cfaa6f64a94..4b151e60f0d2 100644 --- a/script/scaffold/templates/device_trigger/tests/test_device_trigger.py +++ b/script/scaffold/templates/device_trigger/tests/test_device_trigger.py @@ -2,8 +2,8 @@ import pytest from homeassistant.components import automation -from homeassistant.components.NEW_DOMAIN import DOMAIN from homeassistant.components.device_automation import DeviceAutomationType +from homeassistant.components.NEW_DOMAIN import DOMAIN from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import device_registry as dr, entity_registry as er diff --git a/tests/components/rfxtrx/test_device_action.py b/tests/components/rfxtrx/test_device_action.py index c4613d67282c..c2c50cbca8c3 100644 --- a/tests/components/rfxtrx/test_device_action.py +++ b/tests/components/rfxtrx/test_device_action.py @@ -3,8 +3,8 @@ from __future__ import annotations from typing import Any, NamedTuple -import RFXtrx import pytest +import RFXtrx import homeassistant.components.automation as automation from homeassistant.components.device_automation import DeviceAutomationType diff --git a/tests/components/vicare/conftest.py b/tests/components/vicare/conftest.py index 1137abbc54e7..5085ff6661da 100644 --- a/tests/components/vicare/conftest.py +++ b/tests/components/vicare/conftest.py @@ -4,8 +4,8 @@ from __future__ import annotations from collections.abc import AsyncGenerator, Generator from unittest.mock import AsyncMock, Mock, patch -from PyViCare.PyViCareDeviceConfig import PyViCareDeviceConfig import pytest +from PyViCare.PyViCareDeviceConfig import PyViCareDeviceConfig from homeassistant.components.vicare.const import DOMAIN from homeassistant.core import HomeAssistant diff --git a/tests/components/vicare/test_config_flow.py b/tests/components/vicare/test_config_flow.py index 72fb8d0d0b63..0774848ef116 100644 --- a/tests/components/vicare/test_config_flow.py +++ b/tests/components/vicare/test_config_flow.py @@ -1,8 +1,8 @@ """Test the ViCare config flow.""" from unittest.mock import AsyncMock, patch -from PyViCare.PyViCareUtils import PyViCareInvalidCredentialsError import pytest +from PyViCare.PyViCareUtils import PyViCareInvalidCredentialsError from syrupy.assertion import SnapshotAssertion from homeassistant.components import dhcp diff --git a/tests/components/waze_travel_time/conftest.py b/tests/components/waze_travel_time/conftest.py index 4d964d9f08ad..65c2616d1dc0 100644 --- a/tests/components/waze_travel_time/conftest.py +++ b/tests/components/waze_travel_time/conftest.py @@ -1,8 +1,8 @@ """Fixtures for Waze Travel Time tests.""" from unittest.mock import patch -from WazeRouteCalculator import WRCError import pytest +from WazeRouteCalculator import WRCError @pytest.fixture(name="mock_wrc", autouse=True) diff --git a/tests/components/waze_travel_time/test_sensor.py b/tests/components/waze_travel_time/test_sensor.py index 5b23d8a369aa..a3367a48d2ab 100644 --- a/tests/components/waze_travel_time/test_sensor.py +++ b/tests/components/waze_travel_time/test_sensor.py @@ -1,6 +1,6 @@ """Test Waze Travel Time sensors.""" -from WazeRouteCalculator import WRCError import pytest +from WazeRouteCalculator import WRCError from homeassistant.components.waze_travel_time.const import ( CONF_AVOID_FERRIES, diff --git a/tests/ruff.toml b/tests/ruff.toml index dafc6fd6ad77..73246163d2f1 100644 --- a/tests/ruff.toml +++ b/tests/ruff.toml @@ -10,4 +10,20 @@ extend-select = [ "PT015", # Assertion always fails, replace with pytest.fail() "PT021", # use yield instead of request.addfinalizer "PT022", # No teardown in fixture, replace useless yield with return +] + +[isort] +known-first-party = [ + "homeassistant", + "tests", + "script", +] +known-third-party = [ + "syrupy", + "pytest", + "voluptuous", + "pylint", +] +forced-separate = [ + "tests", ] \ No newline at end of file