Skip to content

[pre-commit.ci] pre-commit autoupdate #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: check-toml
Expand All @@ -19,47 +19,47 @@ repos:

# Verify the contents of pyproject.toml
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.13
rev: v0.24.1
hooks:
- id: validate-pyproject

# Updating code to use modern python patterns where available.
- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
rev: v3.20.0
hooks:
- id: pyupgrade

# General Project code formatter.
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 25.1.0
hooks:
- id: black

# Sorts python imports.
- repo: https://github.com/PyCQA/isort
# Note - on black update blacken-docs pin should also be updated.
rev: 5.12.0
rev: 6.0.1
hooks:
- id: isort
args: ['--profile=black']

# Formats python docstrings.
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.1
rev: v1.7.7
hooks:
- id: docformatter

# Formats code-blocks in documentation.
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
rev: 1.19.1
hooks:
- id: blacken-docs
# Note - on black update blacken-docs pin should also be updated.
additional_dependencies: ['black==22.12.0']

# Used to detect unintentionally unused code.
- repo: https://github.com/asottile/dead
rev: v1.5.1
rev: v2.1.0
hooks:
- id: dead
args: [
Expand All @@ -69,13 +69,13 @@ repos:
# Lint documentation source.
- repo: https://github.com/sphinx-contrib/sphinx-lint
# Make sure to also update the additional dependency pin
rev: v0.6.7
rev: v1.0.0
hooks:
- id: sphinx-lint

# lint documentation
- repo: https://github.com/PyCQA/doc8
rev: v1.1.1
rev: v2.0.0
hooks:
- id: doc8

Expand All @@ -91,14 +91,14 @@ repos:

# Static typehint linting.
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.3.0
rev: v1.17.0
hooks:
- id: mypy

# A faster python linter
- repo: https://github.com/charliermarsh/ruff-pre-commit
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.269'
rev: 'v0.12.4'
hooks:
- id: ruff

Expand All @@ -118,7 +118,7 @@ repos:

# Lint code in pre-commit env, note: This ignores import checks.
- repo: https://github.com/PyCQA/pylint
rev: v2.17.4
rev: v3.3.7
hooks:
# Pylint is also run from within pre-commit for CI purposes.
- id: pylint
Expand All @@ -129,7 +129,7 @@ repos:

# Lint code for security flaws.
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
rev: 1.8.6
hooks:
- id: bandit
# Assert is used exclusively in pytest.
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
-- Project information -----------------------------------------------------
https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
"""

import os
import sys
from re import Match, match
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pytest package for testing uoshardware."""

from dataclasses import dataclass


Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for package test configuration, scope=session."""

import pytest

from uoshardware import Loading
Expand Down
1 change: 1 addition & 0 deletions tests/interface/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module used for fixture initialisation in interface tests."""

import pytest


Expand Down
1 change: 1 addition & 0 deletions tests/interface/test_package.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for testing the interface package."""

from time import sleep

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/test_abstractions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for the `abstractions` module."""

import pytest

from tests import Packet
Expand Down
1 change: 1 addition & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for the api module."""

from inspect import signature

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/test_devices.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the devices module."""

import pytest

from uoshardware import UOSUnsupportedError
Expand Down
1 change: 1 addition & 0 deletions uoshardware/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The high level interface for communicating with UOS devices."""

import logging
from enum import Enum

Expand Down
31 changes: 17 additions & 14 deletions uoshardware/abstractions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module defining the base class and static func for interfaces."""

from abc import ABCMeta, abstractmethod
from dataclasses import dataclass, field
from datetime import datetime
Expand Down Expand Up @@ -182,12 +183,13 @@ class UOSInterface(metaclass=ABCMeta):
def execute_instruction(self, packet: NPCPacket) -> ComResult: # dead: disable
"""Abstract method for executing instructions on UOSInterfaces.

:param packet: A tuple containing the uint8 npc packet for the UOS instruction.
:param packet: A tuple containing the uint8 npc packet for the
UOS instruction.
:returns: ComResult object.
:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
:raises: UOSCommunicationError if there is a problem completing
the action.
the action.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride "
Expand All @@ -201,12 +203,13 @@ def read_response(
"""Read ACK and Data packets from a UOSInterface.

:param expect_packets: How many packets including ACK to expect
:param timeout_s: The maximum time this function will wait for data.
:param timeout_s: The maximum time this function will wait for
data.
:return: COM Result object.
:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
:raises: UOSCommunicationError if there is a problem completing
the action.
the action.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride "
Expand All @@ -219,9 +222,9 @@ def hard_reset(self) -> ComResult:

:return: COM Result object.
:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
:raises: UOSCommunicationError if there is a problem completing
the action.
the action.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride "
Expand All @@ -233,9 +236,9 @@ def open(self):
"""Abstract method for opening a connection to a UOSInterface.

:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
:raises: UOSCommunicationError if there is a problem completing
the action.
the action.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride " f"{UOSInterface.open.__name__} prototype."
Expand All @@ -246,9 +249,9 @@ def close(self):
"""Abstract method for closing a connection to a UOSInterface.

:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
:raises: UOSCommunicationError if there is a problem completing
the action.
the action.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride " f"{UOSInterface.close.__name__} prototype."
Expand All @@ -260,7 +263,7 @@ def is_active(self) -> bool:

:return: Success boolean.
:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride " f"{UOSInterface.close.__name__} prototype."
Expand All @@ -273,7 +276,7 @@ def enumerate_devices() -> list:

:return: A list of possible UOSInterfaces on the server.
:raises: UOSUnsupportedError if the interface hasn't been built
correctly.
correctly.
"""
raise UOSUnsupportedError(
"UOSInterfaces must over-ride "
Expand Down
32 changes: 20 additions & 12 deletions uoshardware/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provides the HAL layer for communicating with the hardware."""

from uoshardware import (
Loading,
Persistence,
Expand Down Expand Up @@ -29,7 +30,7 @@ def enumerate_system_devices( # dead: disable
"""Iterate through all interfaces and locates available devices.

:param interface_filter: Interface enum to limit the search to a
single interface type.
single interface type.
:return: A list of uosinterface objects.
"""
system_devices = []
Expand All @@ -44,7 +45,8 @@ def enumerate_system_devices( # dead: disable
def get_device_definition(identity: str) -> Device | None:
"""Look up the system config dictionary for the defined device mappings.

:param identity: String containing the lookup key of the device in the dictionary.
:param identity: String containing the lookup key of the device in
the dictionary.
:return: Device Object or None if not found
"""
if identity is not None and hasattr(Devices, identity):
Expand All @@ -58,7 +60,8 @@ def get_device_definition(identity: str) -> Device | None:
class UOSDevice: # dead: disable
"""Class for high level object-orientated control of UOS devices.

:ivar identity: The type of device, this is must have a valid device in the config.
:ivar identity: The type of device, this is must have a valid device
in the config.
:ivar address: Compliant connection string for identifying the
device and interface.
"""
Expand Down Expand Up @@ -165,10 +168,11 @@ def get_gpio_input(
"""Read a GPIO pins level from device and returns the value.

:param pin: The numeric number of the pin as defined in the
dictionary for that device.
:param pull_up: Enable the internal pull-up resistor. Default is false.
dictionary for that device.
:param pull_up: Enable the internal pull-up resistor. Default is
false.
:param volatility: How volatile should the command be, use
constants from uoshardware.
constants from uoshardware.
:return: ComResult object.
"""
result = self.__execute_instruction(
Expand Down Expand Up @@ -219,8 +223,9 @@ def reset_all_io(self, volatility=Persistence.RAM) -> ComResult:
"""Execute the reset IO at the defined volatility level.

:param volatility: Where should the pins reset from, use
constants from uoshardware.
:return: ComResult object containing the result of the reset operation..
constants from uoshardware.
:return: ComResult object containing the result of the reset
operation..
"""
return self.__execute_instruction(
UOSFunctions.reset_all_io,
Expand Down Expand Up @@ -258,11 +263,13 @@ def __execute_instruction(
"""Execute a generic UOS function and get the result.

:param function: The name of the function in the OOL.
:param instruction_data: device_functions from the LUT, payload ect.
:param retry: Allows the instruction to retry execution when fails.
:param instruction_data: device_functions from the LUT, payload
ect.
:param retry: Allows the instruction to retry execution when
fails.
:return: ComResult object
:raises: UOSUnsupportedError if function is not possible on the
loaded device.
loaded device.
"""
if (
function.name not in self.__device.functions_enabled
Expand Down Expand Up @@ -373,7 +380,8 @@ def get_compatible_pins(self, function: UOSFunction) -> set:
def get_functions_enabled(self) -> dict: # dead: disable
"""Return functions enabled for the device.

:return: Dictionary of function names to list of Persistence levels.
:return: Dictionary of function names to list of Persistence
levels.
"""
return self.__device.functions_enabled

Expand Down
1 change: 1 addition & 0 deletions uoshardware/devices/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Packages used to define Devices supported by the library."""

from dataclasses import dataclass

from uoshardware.abstractions import Device
Expand Down
1 change: 1 addition & 0 deletions uoshardware/devices/_arduino.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module contains definitions for arduino devices."""

from uoshardware import Persistence
from uoshardware.abstractions import Device, Pin, UOSFunctions
from uoshardware.interface import Interface
Expand Down
1 change: 1 addition & 0 deletions uoshardware/interface/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Package defining io interfaces used for NPC Comms."""

from enum import Enum

from uoshardware.interface.serial import Serial
Expand Down
Loading