Skip to content

Commit

Permalink
Updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 committed Nov 15, 2023
1 parent 8e55552 commit 3c2c8b8
Show file tree
Hide file tree
Showing 35 changed files with 186 additions and 100 deletions.
7 changes: 0 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ repos:
# - pep8-naming==0.13.3


- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args: ["--py38-plus"]


- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
Expand Down
62 changes: 62 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

line-length = 120
indent-width = 4

target-version = "py38"
src = ["src", "test"]

# https://docs.astral.sh/ruff/settings/#ignore-init-module-imports
ignore-init-module-imports = true

extend-exclude = ["__init__.py"]

select = [
"E", "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"I", # https://docs.astral.sh/ruff/rules/#isort-i
"UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up

"A", # https://docs.astral.sh/ruff/rules/#flake8-builtins-a
"ASYNC", # https://docs.astral.sh/ruff/rules/#flake8-async-async
"C4", # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em
"FIX", # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix
"INP", # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp
"ISC", # https://docs.astral.sh/ruff/rules/#flake8-implicit-str-concat-isc
"PIE", # https://docs.astral.sh/ruff/rules/#flake8-pie-pie
"PT", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
"RET", # https://docs.astral.sh/ruff/rules/#flake8-return-ret
"SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
"SLOT", # https://docs.astral.sh/ruff/rules/#flake8-slots-slot
"T10", # https://docs.astral.sh/ruff/rules/#flake8-debugger-t10
"TCH", # https://docs.astral.sh/ruff/rules/#flake8-type-checking-tch
"TD", # https://docs.astral.sh/ruff/rules/#flake8-todos-td

"TRY", # https://docs.astral.sh/ruff/rules/#tryceratops-try
"FLY", # https://docs.astral.sh/ruff/rules/#flynt-fly
"PERF", # https://docs.astral.sh/ruff/rules/#perflint-perf
"RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf

# "PL", # https://docs.astral.sh/ruff/rules/#pylint-pl
# "FURB", # https://docs.astral.sh/ruff/rules/#refurb-furb
]

ignore = [
"RET501", # https://docs.astral.sh/ruff/rules/unnecessary-return-none/#unnecessary-return-none-ret501
"TRY400" # https://docs.astral.sh/ruff/rules/error-instead-of-exception/
]


[format]
# Use single quotes for non-triple-quoted strings.
quote-style = "single"



[lint.flake8-builtins]
builtins-ignorelist = ["id", "input"]


[lint.per-file-ignores]
"docs/conf.py" = ["INP001", "A001"]
"setup.py" = ["PTH123"]
17 changes: 8 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
import os
import re
import sys
from pathlib import Path

import sphinx
from docutils.nodes import Text, Node
from docutils.nodes import Node, Text
from sphinx.addnodes import desc_signature

IS_RTD_BUILD = os.environ.get('READTHEDOCS', '-').lower() == 'true'
IS_CI = os.environ.get('CI', '-') == 'true'


# https://www.sphinx-doc.org/en/master/extdev/logging.html
sphinx_logger = sphinx.util.logging.getLogger('post')
logger_lvl = logging.DEBUG if IS_RTD_BUILD or IS_CI else logging.INFO # set level to DEBUG for CI
Expand All @@ -35,7 +35,11 @@ def log(msg: str):
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
sys.path.insert(0, os.path.join(os.path.abspath('..'), 'src'))
src_folder = Path(__file__).parent.with_name('src')
assert src_folder.is_dir()

# required for autodoc
sys.path.insert(0, str(src_folder))

# -- Project information -----------------------------------------------------

Expand All @@ -49,6 +53,7 @@ def log(msg: str):
release = 'beta'
try:
from HABApp import __version__

version = __version__
print(f'Building docs for {version}')
except Exception as e:
Expand Down Expand Up @@ -229,15 +234,13 @@ def log(msg: str):
(re.compile(r'py:class'), re.compile(r'(?:datetime|pendulum|aiohttp|pathlib)\..+'))
]


# -- Extension configuration -------------------------------------------------
exec_code_working_dir = '../src'
exec_code_source_folders = ['../src', '../tests']

autodoc_member_order = 'bysource'
autoclass_content = 'class'


# No config on member
autodoc_pydantic_model_show_config_member = False
autodoc_pydantic_model_show_config_summary = False
Expand All @@ -255,9 +258,6 @@ def log(msg: str):
autodoc_pydantic_field_list_validators = False
autodoc_pydantic_field_swap_name_and_alias = True




# ----------------------------------------------------------------------------------------------------------------------
# Post processing of default value

Expand Down Expand Up @@ -339,7 +339,6 @@ def setup(app):
'python': ('https://docs.python.org/3', None)
}


# Don't show warnings for missing python references since these are created via intersphinx during the RTD build
if not IS_RTD_BUILD:
nitpick_ignore_regex.append(
Expand Down
2 changes: 1 addition & 1 deletion docs/interface_habapp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ And since it is just like a normal item triggering on changes etc. is possible,
my_agg.aggregation_period(2 * 3600)

# Use max as an aggregation function
my_agg.aggregation_func = max
my_agg.aggregation_func(max)


The value of ``my_agg`` in the example will now always be the maximum of ``MyInputItem`` in the last two hours.
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# -----------------------------------------------------------------------------
# Packages for source formatting
# -----------------------------------------------------------------------------
pre-commit >= 3.3, < 3.4
pre-commit >= 3.5, < 3.6
ruff >= 0.1.5, < 0.2

# -----------------------------------------------------------------------------
# Packages for other developement tasks
Expand Down
16 changes: 8 additions & 8 deletions requirements_setup.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
aiohttp == 3.8.5
pydantic == 2.3.0
msgspec == 0.18.2
aiohttp == 3.8.6
pydantic == 2.5.0
msgspec == 0.18.4
pendulum == 2.1.2
bidict == 0.22.1
watchdog == 3.0.0
ujson == 5.8.0
aiomqtt == 1.2.0
aiomqtt == 1.2.1

immutables == 0.20
eascheduler == 0.1.11
easyconfig == 0.3.0
stack_data == 0.6.2
easyconfig == 0.3.1
stack_data == 0.6.3
colorama == 0.4.6

voluptuous == 0.13.1
voluptuous == 0.14.0

typing-extensions == 4.7.1
typing-extensions == 4.8.0

aiohttp-sse-client == 0.2.1

Expand Down
4 changes: 2 additions & 2 deletions requirements_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
# -----------------------------------------------------------------------------
# Packages to run source tests
# -----------------------------------------------------------------------------
packaging == 23.1
pytest == 7.4.2
packaging == 23.2
pytest == 7.4.3
pytest-asyncio == 0.21.1
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def load_req() -> typing.List[str]:
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Home Automation"
],
Expand Down
11 changes: 6 additions & 5 deletions src/HABApp/__cmd_args__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def get_uptime() -> float:
lib.GetTickCount64.restype = ctypes.c_uint64
return lib.GetTickCount64() / 1000

raise NotImplementedError(f'Not supported on {sys.platform}')
msg = f'Not supported on {sys.platform}'
raise NotImplementedError(msg)


def parse_args(passed_args=None) -> argparse.Namespace:
Expand Down Expand Up @@ -79,10 +80,10 @@ def find_config_folder(arg_config_path: typing.Optional[Path]) -> Path:
# Nothing is specified, we try to find the config automatically
check_path = []
try:
working_dir = Path(os.getcwd())
check_path.append( working_dir / 'HABApp')
check_path.append( working_dir.with_name('HABApp'))
check_path.append( working_dir.parent.with_name('HABApp'))
working_dir = Path.cwd()
check_path.append(working_dir / 'HABApp')
check_path.append(working_dir.with_name('HABApp'))
check_path.append(working_dir.parent.with_name('HABApp'))
except ValueError:
# the ValueError gets raised if the working_dir or its parent is empty (e.g. c:\ or /)
pass
Expand Down
1 change: 0 additions & 1 deletion src/HABApp/core/const/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import sys


# we can have subprocesses (https://docs.python.org/3/library/asyncio-platforms.html#subprocess-support-on-windows)
# or mqtt support (https://github.com/sbtinstruments/aiomqtt#note-for-windows-users)
# but not both. For testing, it makes sense to use mqtt support as a default
Expand Down
3 changes: 2 additions & 1 deletion src/HABApp/core/events/filter/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __init__(self, event_class: HINT_ANY_CLASS, **kwargs):
continue

if arg not in type_hints:
raise AttributeError(f'Filter attribute "{arg}" does not exist for "{event_class.__name__}"')
msg = f'Filter attribute "{arg}" does not exist for "{event_class.__name__}"'
raise AttributeError(msg)

if self.attr_name1 is None:
self.attr_name1 = arg
Expand Down
10 changes: 2 additions & 8 deletions src/HABApp/core/events/filter/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ class OrFilterGroup(EventFilterBaseGroup):
"""Only one child filter has to match"""

def trigger(self, event: Any) -> bool:
for f in self.filters:
if f.trigger(event):
return True
return False
return any(f.trigger(event) for f in self.filters)

def describe(self) -> str:
objs = [f.describe() for f in self.filters]
Expand All @@ -32,10 +29,7 @@ class AndFilterGroup(EventFilterBaseGroup):
"""All child filters have to match"""

def trigger(self, event: Any) -> bool:
for f in self.filters:
if not f.trigger(event):
return False
return True
return all(f.trigger(event) for f in self.filters)

def describe(self) -> str:
objs = [f.describe() for f in self.filters]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from HABApp.core.asyncio import async_context, create_task
from HABApp.core.const.hints import HINT_FUNC_ASYNC
from HABApp.core.internals import Context

from .base import WrappedFunctionBase


Expand Down
2 changes: 1 addition & 1 deletion src/HABApp/core/items/item.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from HABApp.core.errors import ItemNotFoundException
from HABApp.core.internals import uses_item_registry, uses_get_item
from HABApp.core.internals import uses_get_item, uses_item_registry
from HABApp.core.items import BaseValueItem

get_item = uses_get_item()
Expand Down
4 changes: 0 additions & 4 deletions src/HABApp/mqtt/connection/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ async def on_setup(self, connection: MqttConnection):
# clean_session=False
)

# noinspection PyProtectedMember
async def on_connecting(self, connection: MqttConnection, context: CONTEXT_TYPE):
assert context is not None

Expand All @@ -73,9 +72,6 @@ async def on_disconnected(self, connection: MqttConnection, context: CONTEXT_TYP
assert context is not None

connection.log.info('Disconnected')
# remove this check when https://github.com/sbtinstruments/aiomqtt/pull/249 gets merged
if not context._lock.locked():
await context._lock.acquire()
await context.__aexit__(None, None, None)


Expand Down
8 changes: 5 additions & 3 deletions src/HABApp/mqtt/connection/subscribe.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
from __future__ import annotations

from typing import Any, Iterable
from typing import TYPE_CHECKING, Any, Iterable

import HABApp
from HABApp.config import CONFIG
from HABApp.config.models.mqtt import QOS
from HABApp.core.asyncio import run_func_from_async
from HABApp.core.errors import ItemNotFoundException
from HABApp.core.internals import uses_post_event, uses_get_item, uses_item_registry
from HABApp.core.internals import uses_get_item, uses_item_registry, uses_post_event
from HABApp.core.lib import SingleTask
from HABApp.core.wrapper import process_exception
from HABApp.mqtt.connection.connection import MqttPlugin
from HABApp.mqtt.events import MqttValueChangeEvent, MqttValueUpdateEvent
from HABApp.mqtt.mqtt_payload import get_msg_payload

if TYPE_CHECKING:
from HABApp.config.models.mqtt import QOS

SUBSCRIBE_CFG = CONFIG.mqtt.subscribe


Expand Down
4 changes: 3 additions & 1 deletion src/HABApp/mqtt/items/mqtt_item.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from HABApp.core.errors import ItemNotFoundException
from HABApp.core.internals import uses_get_item, uses_item_registry
from HABApp.core.items import BaseValueItem
Expand Down Expand Up @@ -33,7 +35,7 @@ def get_create_item(cls, name: str, initial_value=None) -> 'MqttItem':
assert isinstance(item, cls), f'{cls} != {type(item)}'
return item

def publish(self, payload, qos: int = None, retain: bool = None):
def publish(self, payload, qos: Optional[int] = None, retain: Optional[bool] = None):
"""
Publish the payload under the topic from the item.
Expand Down
8 changes: 5 additions & 3 deletions src/HABApp/mqtt/items/mqtt_pair_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from HABApp.core.errors import ItemNotFoundException
from HABApp.core.internals import uses_item_registry
from HABApp.mqtt.interface_sync import publish

from . import MqttBaseItem

Items = uses_item_registry()
Expand All @@ -14,7 +15,8 @@ def build_write_topic(read_topic: str) -> Optional[str]:
parts.insert(-1, 'set')
return '/'.join(parts)

raise ValueError(f'Can not build write topic for "{read_topic}"')
msg = f'Can not build write topic for "{read_topic}"'
raise ValueError(msg)


class MqttPairItem(MqttBaseItem):
Expand Down Expand Up @@ -46,11 +48,11 @@ def get_create_item(cls, name: str, write_topic: Optional[str] = None, initial_v
assert isinstance(item, cls), f'{cls} != {type(item)}'
return item

def __init__(self, name: str, initial_value=None, write_topic: str = None):
def __init__(self, name: str, initial_value=None, write_topic: Optional[str] = None):
super().__init__(name, initial_value)
self.write_topic: str = write_topic

def publish(self, payload, qos: int = None, retain: bool = None):
def publish(self, payload, qos: Optional[int] = None, retain: Optional[bool] = None):
"""
Publish the payload under the write topic from the item.
Expand Down
Loading

0 comments on commit 3c2c8b8

Please sign in to comment.