Skip to content

Commit

Permalink
Updated pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickBaus committed May 23, 2024
1 parent e843a97 commit 8242346
Show file tree
Hide file tree
Showing 28 changed files with 74 additions and 38 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
# Check for invalid files
- id: check-toml
Expand All @@ -14,7 +14,7 @@ repos:
args: [--fix=lf]
- id: check-executables-have-shebangs
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 24.4.2
hooks:
- id: black
args: ['.']
Expand All @@ -24,7 +24,7 @@ repos:
- id: blacken-docs
args: [--line-length=120]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
- repo: local
Expand All @@ -37,7 +37,7 @@ repos:
require_serial: true
args: [--generated-members=pipe.*]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.5.1'
rev: 'v1.10.0'
hooks:
- id: mypy
additional_dependencies: [types-simplejson]
1 change: 1 addition & 0 deletions _version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
Kraken version information.
"""

__version__ = "4.3.6"
1 change: 1 addition & 0 deletions async_event_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
A lightweight event bus for the asyncio framework that relies on asynchronous
generators to deliver messages.
"""

from __future__ import annotations

import asyncio
Expand Down
1 change: 1 addition & 0 deletions connections/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
Kraken connections module
"""

from .ip_connection import GenericIpConnection
1 change: 1 addition & 0 deletions connections/ip_connection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This file contains an ip connection class, that simplifies the asyncio streamreader and streamwriter
"""

from __future__ import annotations

import asyncio
Expand Down
1 change: 1 addition & 0 deletions data_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This file contains all custom data types used across the application
"""

from __future__ import annotations

from dataclasses import dataclass, field
Expand Down
Empty file added database/__init__.py
Empty file.
1 change: 1 addition & 0 deletions database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This file contains all database data models, that represent either sensor
hosts/nodes or sensors.
"""

from __future__ import annotations

from datetime import datetime
Expand Down
4 changes: 4 additions & 0 deletions databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The database abstraction layer, that handles all application specific tasks of
the databases.
"""

from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -177,6 +178,9 @@ def _log_database_error(
timeout,
)

async def monitor_changes(self, timeout: float) -> None:
raise NotImplementedError

async def _monitor_database(
self, database_model: Type[DeviceDocument], timeout: float
) -> AsyncGenerator[tuple[ChangeType, UUID | Document], None]:
Expand Down
1 change: 1 addition & 0 deletions helper_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
A collection of helper functions used in Kraken.
"""

from __future__ import annotations

import asyncio
Expand Down
1 change: 1 addition & 0 deletions managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
hosts of a certain type are managed by their managers. The mangers configure the
hosts extract the data stream from them.
"""

from __future__ import annotations

import asyncio
Expand Down
15 changes: 9 additions & 6 deletions sensors/drivers/generic_driver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This is an asyncIO driver for a generic SCPI compatible device.
"""

from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -145,16 +146,18 @@ def stream_data(self, initial_config: dict[str, Any]) -> AsyncGenerator[DataEven
stream.just(initial_config), stream.iterate(event_bus.subscribe(f"nodes/by_uuid/{self.__uuid}/update"))
)
| pipe.action(
lambda config: logging.getLogger(__name__).info("Got new configuration for: %s.", self)
if config is not None
else logging.getLogger(__name__).info("Removed configuration for: %s.", self)
lambda config: (
logging.getLogger(__name__).info("Got new configuration for: %s.", self)
if config is not None
else logging.getLogger(__name__).info("Removed configuration for: %s.", self)
)
)
| pipe.map(self._parse_config)
| pipe.action(self._log_config_progress)
| pipe.switchmap(
lambda config: stream.empty()
if config is None or not config["enabled"]
else (self._configure_and_stream(config))
lambda config: (
stream.empty() if config is None or not config["enabled"] else (self._configure_and_stream(config))
)
)
)

Expand Down
7 changes: 4 additions & 3 deletions sensors/drivers/generic_scpi_driver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This is an asyncIO driver for a generic SCPI compatible device.
"""

from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -266,13 +267,13 @@ async def enumerate(self) -> None:
if manufacturer is None:
logging.getLogger(__name__).warning("Could not query '*IDN?' of device: %s", self)

def stream_data(self, config: dict[str, Any]) -> AsyncGenerator[DataEvent, None]:
def stream_data(self, initial_config: dict[str, Any]) -> AsyncGenerator[DataEvent, None]:
"""
Enumerate the device, then read data from it.
Parameters
----------
config: dict
initial_config: dict
A dict containing the configuration for the device
Yields
Expand All @@ -282,5 +283,5 @@ def stream_data(self, config: dict[str, Any]) -> AsyncGenerator[DataEvent, None]
"""
return stream.chain(
stream.just(self) | pipe.action(async_(lambda sensor: sensor.enumerate())) | pipe.filter(lambda x: False),
super().stream_data(config),
super().stream_data(initial_config),
)
1 change: 1 addition & 0 deletions sensors/drivers/hp3478a_driver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This is an asyncIO driver for a generic SCPI compatible device.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Any
Expand Down
7 changes: 4 additions & 3 deletions sensors/drivers/labnode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This is a wrapper for LabNode devices.
"""

# pylint: disable=duplicate-code
from __future__ import annotations

Expand Down Expand Up @@ -72,9 +73,9 @@ def stream_data(self) -> AsyncGenerator[DataEvent, None]:
)
| pipe.map(self._create_config)
| pipe.switchmap(
lambda config: stream.empty()
if config is None or not config["enabled"]
else (self._configure_and_stream(config))
lambda config: (
stream.empty() if config is None or not config["enabled"] else (self._configure_and_stream(config))
)
)
)

Expand Down
1 change: 1 addition & 0 deletions sensors/drivers/shared.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This file contains all shared classed used by the drivers.
"""

from dataclasses import dataclass


Expand Down
45 changes: 25 additions & 20 deletions sensors/drivers/tinkerforge.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This is a wrapper for Tinkerforge devices.
"""

# pylint: disable=duplicate-code
from __future__ import annotations

Expand Down Expand Up @@ -117,28 +118,32 @@ def stream_data(self) -> AsyncGenerator[DataEvent, None]:
| pipe.map(lambda x: None),
)
| pipe.switchmap(
lambda sensor: stream.empty()
if sensor is None
else (
self._stream_config_updates(sensor)
| pipe.switchmap(
lambda config: stream.chain(
stream.just(config),
stream.iterate(event_bus.subscribe(f"nodes/by_uuid/{config['uuid']}/remove"))[:1]
| pipe.map(lambda x: None),
lambda sensor: (
stream.empty()
if sensor is None
else (
self._stream_config_updates(sensor)
| pipe.switchmap(
lambda config: stream.chain(
stream.just(config),
stream.iterate(event_bus.subscribe(f"nodes/by_uuid/{config['uuid']}/remove"))[:1]
| pipe.map(lambda x: None),
)
)
)
| pipe.action(
lambda config: logging.getLogger(__name__).info(
"Got new configuration for: %s",
sensor.device,
| pipe.action(
lambda config: logging.getLogger(__name__).info(
"Got new configuration for: %s",
sensor.device,
)
)
| pipe.map(self._create_config)
| pipe.switchmap(
lambda config: (
stream.empty()
if config is None or not config["enabled"]
else (self._configure_and_stream(config))
)
)
)
| pipe.map(self._create_config)
| pipe.switchmap(
lambda config: stream.empty()
if config is None or not config["enabled"]
else (self._configure_and_stream(config))
)
)
)
Expand Down
4 changes: 2 additions & 2 deletions sensors/factories/sensor_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This file contains the GPIB device factory, that produces sensor devices using
available special GPIB device drivers.
"""

from typing import Any

from errors import UnknownDriverError
Expand Down Expand Up @@ -62,8 +63,7 @@ def get(self, driver: str, connection: Any, **kwargs: Any) -> Any:
device = self.__available_drivers[driver]
except KeyError:
raise UnknownDriverError(f"No driver available for {driver}") from None
else:
return device(connection=connection, **kwargs)
return device(connection=connection, **kwargs)


sensor_factory = SensorFactory()
Expand Down
1 change: 1 addition & 0 deletions sensors/transports/ethernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This is a wrapper for a generic Ethernet transport used by other generic devices like the SCPI driver. It wraps
the IP connection and adds the stream interface via GenericTransport.
"""

from __future__ import annotations

from typing import Any
Expand Down
1 change: 1 addition & 0 deletions sensors/transports/generic_ethernet_transport.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This is a generic transport driver implementing error handling for an ethernet streamer.
"""

# pylint: disable=duplicate-code
from __future__ import annotations

Expand Down
1 change: 1 addition & 0 deletions sensors/transports/generic_transport.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This is a generic transport driver implementing the basic streams used by transports, that cannot enumerate its devices.
"""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions sensors/transports/labnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This is a wrapper for the Prologix Ethernet controller used by other generic devices like the SCPI driver. It wraps
the Prologix library and adds the stream interface via GenericTransport.
"""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions sensors/transports/linux_gpib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This is a wrapper for the Prologix Ethernet controller used by other generic devices like the SCPI driver. It wraps
the Prologix library and adds the stream interface via GenericTransport.
"""

# pylint: disable=duplicate-code
from __future__ import annotations

Expand Down
1 change: 1 addition & 0 deletions sensors/transports/prologix_ethernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This is a wrapper for the Prologix Ethernet controller used by other generic devices like the SCPI driver. It wraps
the Prologix library and adds the stream interface via GenericTransport.
"""

from __future__ import annotations

from typing import Any
Expand Down
1 change: 1 addition & 0 deletions sensors/transports/tinkerforge.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This is a asyncIO driver for a generic SCPI compatible device.
"""

from __future__ import annotations

import asyncio
Expand Down
1 change: 1 addition & 0 deletions sensors/transports/transport_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This file contains a factory to select the correct driver for all supported
sensor hosts.
"""

from typing import Any, Type

from errors import UnknownDriverError
Expand Down
3 changes: 3 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pre-commit~=3.7.1
pylint~=3.2.2
pylint-pydantic~=0.3.2
pytest~=8.0.1
1 change: 1 addition & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test to catch invalid versions when releasing a new git tag"""

import os

from _version import __version__
Expand Down

0 comments on commit 8242346

Please sign in to comment.