Moved derive unit API to DLUnit
Derived units now use a DLUnit class similar to a DLPak to be easily stored and loaded, the public API has been updated to either take a DLUnit object or a Path where it reads the DLUnit from a *.dlunit file The .dlunit file is a ZIP compressed archive containing two files, a manifest.json which stores the units uuid, its input signals and its output signal, and unit.py which is the python code for the unit, the same rules apply (one python function with a specifically structured signature) as when a string was passed in the old API Errors have been added to have a DLUnitError similar to the DLPakError as the DLUnit class is heavily inspired from the DLPak architecutre Logging may still be primitive, this will be covered in the next AI logging sweep to homogenize and clean up the logging aspect of things
This commit is contained in:
10 files changed
+378
-44
No files matched your search
+22
-2
@@ -5,6 +5,7 @@ from uuid import UUID, uuid4
|
||||
|
||||
import pytest
|
||||
from dynalab_core.derive import DeriveRegistry
|
||||
from dynalab_core.dlunit import DLUnit
|
||||
from dynalab_core.protocols.packets.data import ValueDescriptor
|
||||
from dynalab_core.protocols.packets.handshake import SignalDescriptor
|
||||
|
||||
@@ -30,6 +31,17 @@ def fail(value: ValueDescriptor, output: SignalDescriptor) -> ValueDescriptor:
|
||||
"""
|
||||
|
||||
|
||||
def make_dlunit(
|
||||
source: str,
|
||||
input_signals: list[SignalDescriptor],
|
||||
return_signal: SignalDescriptor,
|
||||
) -> DLUnit:
|
||||
dlunit = DLUnit()
|
||||
dlunit.set_manifest(uuid4(), input_signals, return_signal)
|
||||
dlunit.set_data(source)
|
||||
return dlunit
|
||||
|
||||
|
||||
def test_derive_registry_routes_with_live_values() -> None:
|
||||
output_queue: Queue[ValueDescriptor] = Queue()
|
||||
left_signal = SignalDescriptor(id=uuid4(), name="Left", type="number")
|
||||
@@ -40,7 +52,11 @@ def test_derive_registry_routes_with_live_values() -> None:
|
||||
|
||||
try:
|
||||
unit = registry.register(
|
||||
PROCESSING_FUNCTION, [left_signal, right_signal], output_signal
|
||||
make_dlunit(
|
||||
PROCESSING_FUNCTION,
|
||||
[left_signal, right_signal],
|
||||
output_signal,
|
||||
)
|
||||
)
|
||||
right_value = ValueDescriptor(signal_id=right_signal.id, value=2.0, timestamp=1)
|
||||
live_values[right_signal.id] = right_value
|
||||
@@ -87,7 +103,11 @@ def test_derive_worker_logs_failure_and_stops(
|
||||
with caplog.at_level(logging.DEBUG, logger="dynalab_core"):
|
||||
try:
|
||||
unit = registry.register(
|
||||
FAILING_PROCESSING_FUNCTION, [input_signal], output_signal
|
||||
make_dlunit(
|
||||
FAILING_PROCESSING_FUNCTION,
|
||||
[input_signal],
|
||||
output_signal,
|
||||
)
|
||||
)
|
||||
unit.put_data(
|
||||
[ValueDescriptor(signal_id=input_signal.id, value=1.0, timestamp=1)]
|
||||
|
||||
Reference in new issue
Block a user