Skip to content

Commit

Permalink
refactor: formatting style
Browse files Browse the repository at this point in the history
  • Loading branch information
elagil committed Oct 30, 2022
1 parent b15bb5e commit cb61a39
Show file tree
Hide file tree
Showing 26 changed files with 173 additions and 104 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ dist
build
.*.sw[po]
.hypothesis
.venv
.virtual*
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
exclude: (generated)

repos:
- repo: https://github.com/pycqa/isort
rev: 5.10.1
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.9.0
hooks:
- id: isort
- id: reorder-python-imports

- repo: https://github.com/psf/black
rev: 22.10.0
Expand Down
30 changes: 29 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ grpcio-tools = "^1.48.2"
pytest = "^7.1.2"
hypothesis = "^6.47.5"
mypy-protobuf = "^3.3.0"
debugpy = "^1.6.3"

[tool.poetry-dynamic-versioning]
enable = true
Expand Down
1 change: 0 additions & 1 deletion sigmadsp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"""The sigmadsp package."""

# The version string will be replaced by poetry.
__version__ = "0.0.0"
52 changes: 31 additions & 21 deletions sigmadsp/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@
import time
from concurrent.futures import ThreadPoolExecutor
from multiprocessing import Queue
from typing import Callable, Dict
from typing import Callable
from typing import Dict

import grpc
from retry.api import retry_call

import sigmadsp
from sigmadsp.dsp.common import ConfigurationError, Dsp, SafetyCheckError
from sigmadsp.dsp.common import ConfigurationError
from sigmadsp.dsp.common import Dsp
from sigmadsp.dsp.common import SafetyCheckError
from sigmadsp.dsp.factory import dsp_from_config
from sigmadsp.generated.backend_service.control_pb2 import (
ControlParameterRequest,
ControlRequest,
ControlResponse,
)
from sigmadsp.generated.backend_service.control_pb2 import ControlParameterRequest
from sigmadsp.generated.backend_service.control_pb2 import ControlRequest
from sigmadsp.generated.backend_service.control_pb2 import ControlResponse
from sigmadsp.generated.backend_service.control_pb2_grpc import (
BackendServicer,
add_BackendServicer_to_server,
)
from sigmadsp.generated.backend_service.control_pb2_grpc import BackendServicer
from sigmadsp.helper.settings import SigmadspSettings
from sigmadsp.sigmastudio.common import (
CONNECTION_CLOSED,
ReadRequest,
ReadResponse,
SafeloadRequest,
WriteRequest,
)
from sigmadsp.sigmastudio.server import SigmaStudioRequestHandler, SigmaStudioTcpServer
from sigmadsp.sigmastudio.common import CONNECTION_CLOSED
from sigmadsp.sigmastudio.common import ReadRequest
from sigmadsp.sigmastudio.common import ReadResponse
from sigmadsp.sigmastudio.common import SafeloadRequest
from sigmadsp.sigmastudio.common import WriteRequest
from sigmadsp.sigmastudio.server import SigmaStudioRequestHandler
from sigmadsp.sigmastudio.server import SigmaStudioTcpServer

# A logger for this module
logger = logging.getLogger(__name__)
Expand All @@ -55,7 +55,11 @@ class BackendService(BackendServicer):
send_queue: Queue
receive_queue: Queue

def __init__(self, settings: SigmadspSettings, dsp_from_config_fn: Callable[[Dict], Dsp] = dsp_from_config):
def __init__(
self,
settings: SigmadspSettings,
dsp_from_config_fn: Callable[[Dict], Dsp] = dsp_from_config,
):
"""Initialize service and start all relevant threads (TCP, SPI).
Args:
Expand All @@ -67,7 +71,6 @@ def __init__(self, settings: SigmadspSettings, dsp_from_config_fn: Callable[[Dic
super().__init__()

self._active = True

self.send_queue = Queue()
self.receive_queue = Queue()

Expand Down Expand Up @@ -121,11 +124,17 @@ def startup_worker(self):
)

self.sigma_tcp_server_worker_thread = threading.Thread(
target=self.sigma_tcp_server_worker, daemon=True, name="Sigma TCP server worker"
target=self.sigma_tcp_server_worker,
daemon=True,
name="Sigma TCP server worker",
)
self.sigma_tcp_server_worker_thread.start()

logger.info("Sigma TCP server started on [%s]:%d.", self.config["host"]["ip"], self.config["host"]["port"])
logger.info(
"Sigma TCP server started on [%s]:%d.",
self.config["host"]["ip"],
self.config["host"]["port"],
)

# Create the request worker thread.
self.sigma_studio_worker_thread = threading.Thread(
Expand Down Expand Up @@ -261,7 +270,8 @@ def control_parameter(self, request: ControlParameterRequest, context):

if "change_volume" == command:
volume_cells_to_adjust = self.settings.parameter_parser.get_matching_cells_by_name_tokens(
self.settings.parameter_parser.volume_cells, list(request.change_volume.name_tokens)
self.settings.parameter_parser.volume_cells,
list(request.change_volume.name_tokens),
)

if not volume_cells_to_adjust:
Expand Down
10 changes: 4 additions & 6 deletions sigmadsp/dsp/adau14xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import math

from sigmadsp.dsp.common import Dsp
from sigmadsp.helper.conversion import (
float_to_frac_8_24,
frac_8_24_to_float,
int16_to_bytes,
int32_to_bytes,
)
from sigmadsp.helper.conversion import float_to_frac_8_24
from sigmadsp.helper.conversion import frac_8_24_to_float
from sigmadsp.helper.conversion import int16_to_bytes
from sigmadsp.helper.conversion import int32_to_bytes
from sigmadsp.sigmastudio.adau14xx import Adau14xxHeaderGenerator

# A logger for this module
Expand Down
13 changes: 6 additions & 7 deletions sigmadsp/dsp/adau1x01.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
"""This module provides functionality for controlling SigmaDSP ADAU1x01 hardware."""
import logging
import math
from typing import List, Tuple
from typing import List
from typing import Tuple

from sigmadsp.dsp.common import Dsp
from sigmadsp.helper.conversion import (
bytes_to_int16,
float_to_frac_5_23,
frac_5_23_to_float,
int16_to_bytes,
)
from sigmadsp.helper.conversion import bytes_to_int16
from sigmadsp.helper.conversion import float_to_frac_5_23
from sigmadsp.helper.conversion import frac_5_23_to_float
from sigmadsp.helper.conversion import int16_to_bytes
from sigmadsp.sigmastudio.adau1x01 import Adau1x01HeaderGenerator

# A logger for this module
Expand Down
22 changes: 12 additions & 10 deletions sigmadsp/dsp/common.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
"""General definitions for interfacing DSPs."""
import logging
import time
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from abc import ABC
from abc import abstractmethod
from dataclasses import dataclass
from dataclasses import field
from math import nan
from typing import List, Literal, Union
from typing import List
from typing import Literal
from typing import Union

import gpiozero

from sigmadsp.helper.conversion import (
bytes_to_int32,
clamp,
db_to_linear,
int32_to_bytes,
linear_to_db,
)
from sigmadsp.helper.conversion import bytes_to_int32
from sigmadsp.helper.conversion import clamp
from sigmadsp.helper.conversion import db_to_linear
from sigmadsp.helper.conversion import int32_to_bytes
from sigmadsp.helper.conversion import linear_to_db
from sigmadsp.protocols.common import DspProtocol
from sigmadsp.sigmastudio.header import PacketHeaderGenerator

Expand Down
14 changes: 9 additions & 5 deletions sigmadsp/dsp/factory.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"""Factory module for generating DSP objects."""
import logging
from typing import Dict, Type, Union
from typing import Dict
from typing import Type
from typing import Union

from .adau14xx import Adau14xx
from .adau1x01 import Adau1x01
from .common import ConfigurationError
from .common import Dsp
from .common import InputPin
from .common import OutputPin
from sigmadsp.protocols.i2c import I2cProtocol
from sigmadsp.protocols.spi import SpiProtocol

from .adau1x01 import Adau1x01
from .adau14xx import Adau14xx
from .common import ConfigurationError, Dsp, InputPin, OutputPin

logger = logging.getLogger(__name__)

VALID_ADAU14XX = ["adau14xx", "adau145x", "adau146x", "adau147x"]
Expand Down
8 changes: 3 additions & 5 deletions sigmadsp/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
import click
import grpc

from sigmadsp.generated.backend_service.control_pb2 import (
ControlParameterRequest,
ControlRequest,
ControlResponse,
)
from sigmadsp.generated.backend_service.control_pb2 import ControlParameterRequest
from sigmadsp.generated.backend_service.control_pb2 import ControlRequest
from sigmadsp.generated.backend_service.control_pb2 import ControlResponse
from sigmadsp.generated.backend_service.control_pb2_grpc import BackendStub


Expand Down
3 changes: 2 additions & 1 deletion sigmadsp/helper/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
- Conversion from integers to bytes-like objects of specified length
"""
import math
from typing import Literal, Union
from typing import Literal
from typing import Union

BIT_LENGTH_8_24 = 31
BIT_LENGTH_5_23 = 27
Expand Down
7 changes: 5 additions & 2 deletions sigmadsp/helper/parser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""A module that parses SigmaStudio project files and extracts adjustable cells."""
import logging
from dataclasses import dataclass
from itertools import dropwhile, takewhile
from typing import ClassVar, List, Union
from itertools import dropwhile
from itertools import takewhile
from typing import ClassVar
from typing import List
from typing import Union

# A logger for this module
logger = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion sigmadsp/helper/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This module contains a class that handles settings for this application."""
import logging
from typing import List, Union
from typing import List
from typing import Union

import yaml

Expand Down
6 changes: 4 additions & 2 deletions sigmadsp/protocols/common.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""This module implements the base class for I2C and SPI communication handlers."""
import logging
import threading
from abc import ABC, abstractmethod
from abc import ABC
from abc import abstractmethod
from multiprocessing import Queue

from sigmadsp.sigmastudio.common import ReadRequest, WriteRequest
from sigmadsp.sigmastudio.common import ReadRequest
from sigmadsp.sigmastudio.common import WriteRequest

# A logger for this module
logger = logging.getLogger(__name__)
Expand Down
6 changes: 3 additions & 3 deletions sigmadsp/protocols/i2c.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""This module implements an I2C handler that talks to Sigma DSP devices."""
import logging

from smbus2 import SMBus, i2c_msg

from sigmadsp.helper.conversion import int16_to_bytes
from smbus2 import i2c_msg
from smbus2 import SMBus

from .common import DspProtocol
from sigmadsp.helper.conversion import int16_to_bytes

# A logger for this module
logger = logging.getLogger(__name__)
Expand Down
4 changes: 3 additions & 1 deletion sigmadsp/sigmastudio/adau14xx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Header generator for ADAU14xx parts."""
from .header import Field, PacketHeader, PacketHeaderGenerator
from .header import Field
from .header import PacketHeader
from .header import PacketHeaderGenerator


class Adau14xxHeaderGenerator(PacketHeaderGenerator):
Expand Down
4 changes: 3 additions & 1 deletion sigmadsp/sigmastudio/adau1x01.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Header generator for ADAU1x01 parts."""
from .header import Field, PacketHeader, PacketHeaderGenerator
from .header import Field
from .header import PacketHeader
from .header import PacketHeaderGenerator


class Adau1x01HeaderGenerator(PacketHeaderGenerator):
Expand Down
Loading

0 comments on commit cb61a39

Please sign in to comment.