Skip to content

Expose device metadata on schema-built device modules - #61

Open
bruno-f-cruz wants to merge 2 commits into
harp-tech:mainfrom
bruno-f-cruz:device-metadata
Open

bruno-f-cruz wants to merge 2 commits into
harp-tech:mainfrom
bruno-f-cruz:device-metadata

Conversation

@bruno-f-cruz

@bruno-f-cruz bruno-f-cruz commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Generated device packages now carry their source device.yml as a DEVICE_METADATA string constant (harp-tech/generators#188), mirroring Device.Metadata in the C# interface. This brings the runtime path to parity, so a module built with create_device_module exposes the same constant, and adds a protocol for code that needs it.

  • DeviceModule declares DEVICE_METADATA: str, and create_device_module sets it from the schema text and exports it in __all__.
  • The value matches what a generated package holds for the same file. Python reads every line ending in source as \n, so line endings are normalized, and schema bytes are decoded the way the YAML parser detects them: a UTF-16 byte order mark, otherwise UTF-8 with an optional byte order mark.
  • DescribedDeviceModuleLike extends DeviceModuleLike with DEVICE_METADATA: str. Generated packages and DeviceModule match it structurally, so code that needs the schema can accept it directly, or narrow a DeviceModuleLike with isinstance, which types DEVICE_METADATA as str.
  • tests/device/expected_device.py gains the block the generator emits for tests/assets/device.yml, so the existing check that both paths publish the same __all__ keeps holding, and new tests compare the two values directly and pin which modules match each protocol.

DeviceModuleLike does not require DEVICE_METADATA, so device modules written by hand still match without carrying a schema, and packages generated before harp-tech/generators#188 keep satisfying it unchanged.

DeviceModuleLike leaves DEVICE_METADATA optional so device modules written
by hand still match. DescribedDeviceModuleLike requires it, so code needing
the schema can accept it directly or narrow a DeviceModuleLike to it with
isinstance.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant