Skip to content

Commit

Permalink
refactor(isort): organize imports with isort
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviml committed Nov 21, 2020
1 parent 5a80067 commit bc82a2d
Show file tree
Hide file tree
Showing 36 changed files with 121 additions and 84 deletions.
7 changes: 0 additions & 7 deletions .coveragerc

This file was deleted.

3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ dmypy.json
.pyre/

#VSCode
.vscode/
.vscode/*
!.vscode/settings.json
.idea

# Ignoring Pipfile.lock since we support python 3.6, 3.7 and 3.8
Expand Down
36 changes: 16 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: check-json
- id: pretty-format-json
args:
- --autofix
- --indent
- '4'
- repo: local
hooks:
- id: isort
name: isort
entry: pipenv run isort
language: python
types: [python]
args: []
require_serial: false
- id: black
name: black
entry: pipenv run black apps/controllerx tests
language: system
pass_filenames: false
always_run: true
entry: pipenv run black
language: python
types: [python]
- id: flake8
name: flake8
entry: pipenv run flake8 apps/controllerx tests
language: system
pass_filenames: false
always_run: true
entry: pipenv run flake8
language: python
types: [python]
- id: mypy
name: mypy
entry: pipenv run mypy apps/controllerx tests/ --no-implicit-optional
language: system
entry: pipenv run mypy apps/controllerx/ tests/
language: python
types: [python]
pass_filenames: false
always_run: true
- id: pytest
name: pytest
entry: pipenv run pytest
Expand Down
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 100,
"python.testing.pytestEnabled": true,
"editor.formatOnSave": true,
"python.formatting.provider": "black",
"python.analysis.typeCheckingMode": "basic",
"python.analysis.diagnosticMode": "workspace",
"python.analysis.stubPath": "apps/controllerx",
"python.testing.pytestArgs": [
"tests"
],
"python.languageServer": "Pylance",
"python.linting.mypyEnabled": true,
"python.linting.mypyCategorySeverity.note": "Error",
"python.linting.flake8Enabled": true,
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
}
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pre-commit = "==2.8.2"
commitizen = "==2.4.2"
mypy = "==0.790"
flake8 = "==3.8.4"
isort = "==5.6.4"
controllerx = {path = ".", editable = true}

[packages]
Expand Down
1 change: 0 additions & 1 deletion apps/controllerx/cx_const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any, Awaitable, Callable, Dict, Tuple, Union


ActionFunction = Callable[..., Awaitable[Any]]
TypeAction = Union[ActionFunction, Tuple, str]
ActionEvent = Union[str, int]
Expand Down
2 changes: 1 addition & 1 deletion apps/controllerx/cx_core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
from appdaemon.plugins.hass.hassapi import Hass # type: ignore
from appdaemon.plugins.mqtt.mqttapi import Mqtt # type: ignore
from cx_const import ActionEvent, ActionFunction, TypeAction, TypeActionsMapping

from cx_core import integration as integration_module
from cx_core.integration import EventData, Integration

Service = Tuple[str, Dict]
Services = List[Service]


DEFAULT_DELAY = 350 # In milliseconds
DEFAULT_ACTION_DELTA = 300 # In milliseconds
DEFAULT_MULTIPLE_CLICK_DELAY = 500 # In milliseconds
Expand Down
2 changes: 1 addition & 1 deletion apps/controllerx/cx_core/feature_support/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional, Set, TYPE_CHECKING, Type, TypeVar
from typing import TYPE_CHECKING, List, Optional, Set, Type, TypeVar

if TYPE_CHECKING:
from cx_core.type_controller import TypeController
Expand Down
3 changes: 1 addition & 2 deletions apps/controllerx/cx_core/integration/mqtt.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Optional

from appdaemon.plugins.mqtt.mqttapi import Mqtt # type: ignore

from cx_const import TypeActionsMapping
from cx_core.integration import Integration, EventData
from cx_core.integration import EventData, Integration


class MQTTIntegration(Integration):
Expand Down
1 change: 0 additions & 1 deletion apps/controllerx/cx_core/integration/state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Optional

from appdaemon.plugins.hass.hassapi import Hass # type: ignore

from cx_const import TypeActionsMapping
from cx_core.integration import Integration

Expand Down
3 changes: 1 addition & 2 deletions apps/controllerx/cx_core/integration/z2m.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

from appdaemon.plugins.hass.hassapi import Hass # type: ignore
from appdaemon.plugins.mqtt.mqttapi import Mqtt # type: ignore

from cx_const import TypeActionsMapping
from cx_core.integration import Integration, EventData
from cx_core.integration import EventData, Integration

LISTENS_TO_HA = "ha"
LISTENS_TO_MQTT = "mqtt"
Expand Down
5 changes: 3 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ stages:
jobs:
- job: Build
displayName: Build job

strategy:
matrix:
Python36:
Expand All @@ -41,11 +40,13 @@ stages:
displayName: Lock dependencies
- script: pipenv install --system --deploy --dev
displayName: Install dependencies
- script: isort apps/controllerx tests --check
displayName: Formatter (black)
- script: black apps/controllerx tests --check
displayName: Formatter (black)
- script: flake8 apps/controllerx tests
displayName: Styling (flake8)
- script: mypy apps/controllerx tests/ --no-implicit-optional
- script: mypy apps/controllerx tests/
displayName: Typing (mypy)
- script: pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=apps --cov-report=xml --cov-report=html
displayName: Tests (pytest)
Expand Down
2 changes: 0 additions & 2 deletions pytest.ini

This file was deleted.

30 changes: 30 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[isort]
profile=black

[black]
line-length = 88
exclude = .git,.hg,.mypy_cache,.tox,_build,buck-out,build,dist

[flake8]
ignore = E501, W503
exclude = controllerx.py
max-line-length = 88

[mypy]
python_version = 3.6
namespace_packages = True
no_implicit_optional = True

[tool:pytest]
mock_use_standalone_module = true

[report]
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain if tests don't hit defensive assertion code:
raise NotImplementedError

[mypy-appdaemon.*]
ignore_missing_imports = true
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import appdaemon.plugins.mqtt.mqttapi as mqtt # type: ignore
import pytest
from _pytest.monkeypatch import MonkeyPatch
from cx_core.controller import Controller
from cx_core import LightController
from cx_core.controller import Controller

from tests.test_utils import fake_fn

Expand Down
6 changes: 3 additions & 3 deletions tests/integ_tests/integ_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from pathlib import Path
from typing import Any, Dict

from pytest_mock.plugin import MockerFixture
from tests.test_utils import get_controller

import pytest
import yaml
from pytest_mock.plugin import MockerFixture

from tests.test_utils import get_controller


def get_integ_tests():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import os
import pkgutil
from contextlib import contextmanager
from typing import Callable, TYPE_CHECKING, Generator, Optional
from mock import MagicMock
from typing import TYPE_CHECKING, Callable, Generator, Optional

import pytest
from _pytest._code.code import ExceptionInfo
from mock import MagicMock
from pytest_mock.plugin import MockerFixture

if TYPE_CHECKING:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/cx_core/color_helper_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest
from tests.test_utils import wrap_exetuction

from cx_core.color_helper import Colors, get_color_wheel

from tests.test_utils import wrap_exetuction


@pytest.mark.parametrize(
"colors, error_expected",
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/cx_core/controller_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import appdaemon.plugins.hass.hassapi as hass # type: ignore
import pytest
from cx_const import ActionEvent, ActionFunction, TypeAction, TypeActionsMapping
from pytest_mock.plugin import MockerFixture
from tests.test_utils import IntegrationMock, fake_fn, wrap_exetuction

from cx_core import integration as integration_module
from cx_core.controller import Controller, action
from pytest_mock.plugin import MockerFixture

from tests.test_utils import IntegrationMock, fake_fn, wrap_exetuction

INTEGRATION_TEST_NAME = "test"
CONTROLLER_NAME = "test_controller"
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/cx_core/custom_controller_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import pytest
from _pytest.monkeypatch import MonkeyPatch
from cx_const import TypeActionsMapping
from pytest_mock.plugin import MockerFixture
from tests.test_utils import fake_fn

from cx_core import (
CallServiceController,
Controller,
Expand All @@ -15,6 +12,9 @@
SwitchController,
)
from cx_core.type_controller import TypeController
from pytest_mock.plugin import MockerFixture

from tests.test_utils import fake_fn


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cx_core.type_controller import TypeController
import pytest
from cx_core.feature_support import Features, FeatureSupport, SupportedFeatures
from cx_core.type_controller import TypeController


@pytest.mark.parametrize(
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/cx_core/integration/zha_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Dict
from cx_core.controller import Controller
import pytest

import pytest
from cx_core.controller import Controller
from cx_core.integration.zha import ZHAIntegration
from pytest_mock.plugin import MockerFixture

Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/cx_core/release_hold_controller_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from _pytest.monkeypatch import MonkeyPatch
import pytest
from _pytest.monkeypatch import MonkeyPatch
from cx_core.controller import Controller, ReleaseHoldController
from pytest_mock import MockerFixture
from tests.test_utils import fake_fn

from cx_core.controller import Controller, ReleaseHoldController
from tests.test_utils import fake_fn


class FakeReleaseHoldController(ReleaseHoldController):
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/cx_core/stepper/circular_stepper_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Tuple
import pytest

from cx_core.stepper.circular_stepper import CircularStepper
import pytest
from cx_core.stepper import Stepper
from cx_core.stepper.circular_stepper import CircularStepper
from typing_extensions import Literal


Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/cx_core/stepper/minmax_stepper_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Tuple
import pytest

from cx_core.stepper.minmax_stepper import MinMaxStepper
import pytest
from cx_core.stepper import Stepper
from cx_core.stepper.minmax_stepper import MinMaxStepper
from typing_extensions import Literal


Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/cx_core/type/cover_controller_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from cx_core.feature_support.cover import CoverSupport
from cx_core.type_controller import TypeController
from pytest_mock.plugin import MockerFixture

from tests.test_utils import fake_fn, wrap_exetuction

ENTITY_NAME = "cover.test"
Expand Down
9 changes: 5 additions & 4 deletions tests/unit_tests/cx_core/type/light_controller_test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from typing import Any, Dict, Set, Tuple, Type, Union
from _pytest.monkeypatch import MonkeyPatch
from cx_core.controller import Controller

import pytest
from _pytest.monkeypatch import MonkeyPatch
from cx_core import LightController, ReleaseHoldController
from cx_core.controller import Controller
from cx_core.feature_support.light import LightSupport
from cx_core.stepper import Stepper
from cx_core.stepper.circular_stepper import CircularStepper
from cx_core.stepper.minmax_stepper import MinMaxStepper
from cx_core.type.light_controller import ColorMode, LightEntity
from pytest_mock.plugin import MockerFixture
from typing_extensions import Literal
from tests.test_utils import fake_fn, wrap_exetuction
from cx_core.type.light_controller import ColorMode, LightEntity

from tests.test_utils import fake_fn, wrap_exetuction

ENTITY_NAME = "light.test"

Expand Down

0 comments on commit bc82a2d

Please sign in to comment.