Skip to content

eds: Support custom_options for unknown EDS fields#653

Open
bizfsc wants to merge 1 commit into
canopen-python:masterfrom
bizfsc:feat/custom-options-eds
Open

eds: Support custom_options for unknown EDS fields#653
bizfsc wants to merge 1 commit into
canopen-python:masterfrom
bizfsc:feat/custom-options-eds

Conversation

@bizfsc
Copy link
Copy Markdown
Collaborator

@bizfsc bizfsc commented May 4, 2026

Supersedes #615.

When importing an EDS/DCF file, any key that is not part of the CiA 306 standard field set is now collected into a custom_options dict on the object. This allows applications to round-trip vendor-specific metadata without losing it.

Changes

  • ODVariable, ODRecord and ODArray gain a custom_options: dict[str, str] attribute (default {}).
  • New _STANDARD_OPTIONS set in eds.py lists all keys that are parsed explicitly. ObjFlags and Denotation are intentionally not in this set — they flow through custom_options and survive round-trips until first-class support is added in eds: Add first-class support for CiA 306 ObjFlags and Denotation #654.
  • New _get_custom_options(eds, section) helper collects every key not in _STANDARD_OPTIONS.
  • custom_options is populated for top-level VAR/DOMAIN, ARRAY and RECORD objects as well as for sub-variables via build_variable().
  • copy_variable() now gives each copied variable its own custom_options dict to avoid shared-state mutations between shallow-copy clones.
  • export_variable() and export_record() write custom_options back to the EDS file, guarded by a _STANDARD_OPTIONS check to prevent user-supplied keys from clobbering standard fields.

Tests

  • test_reading_custom_options — VAR with Category=Motor, Offset=100
  • test_custom_options_standard_keys_excluded — standard keys absent from custom_options
  • test_custom_options_empty_for_standard_object — heartbeat time has {}
  • test_custom_options_record — RECORD-level custom_options
  • test_roundtrip_custom_options — full EDS export/import cycle preserves values
  • test_roundtrip_custom_options_not_duplicated_as_standard — standard keys stay out after round-trip

@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
canopen/objectdictionary/eds.py 89.47% 0 Missing and 2 partials ⚠️
canopen/objectdictionary/__init__.py 80.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for round-tripping vendor-specific (non-CiA-306) EDS/DCF keys by collecting them into a new custom_options dict on object dictionary objects and exporting them back out.

Changes:

  • Introduces custom_options on ODVariable, ODRecord, and ODArray to store unknown EDS keys.
  • Updates EDS import/export to populate and persist custom_options using a _STANDARD_OPTIONS allowlist and _get_custom_options() helper.
  • Adds tests and sample EDS entries covering read + export/import round-trip behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
canopen/objectdictionary/eds.py Collects unknown keys into custom_options during import and writes them back during export.
canopen/objectdictionary/__init__.py Adds custom_options attribute to OD object types.
test/test_eds.py Adds unit tests for reading and round-tripping custom_options.
test/sample.eds Adds sample objects containing vendor-specific keys to validate behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread canopen/objectdictionary/eds.py Outdated
Comment thread canopen/objectdictionary/eds.py Outdated
Comment thread canopen/objectdictionary/eds.py
Comment thread canopen/objectdictionary/eds.py Outdated
@bizfsc bizfsc force-pushed the feat/custom-options-eds branch 2 times, most recently from 064b334 to 11da53a Compare May 12, 2026 08:06
@bizfsc bizfsc requested a review from Copilot May 12, 2026 08:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

Comment thread canopen/objectdictionary/eds.py
Comment thread canopen/objectdictionary/eds.py
Comment thread canopen/objectdictionary/eds.py Outdated
Comment thread canopen/objectdictionary/__init__.py Outdated
Comment thread canopen/objectdictionary/__init__.py Outdated
Comment thread canopen/objectdictionary/eds.py
@bizfsc bizfsc force-pushed the feat/custom-options-eds branch from 11da53a to 1f1cb14 Compare May 12, 2026 08:32
@bizfsc bizfsc requested a review from Copilot May 12, 2026 08:37
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread canopen/objectdictionary/__init__.py Outdated
Comment on lines 294 to 296
"bit_definitions", "storage_location", "custom_options"):
if attr in template.__dict__:
var.__dict__[attr] = template.__dict__[attr]
Comment thread canopen/objectdictionary/eds.py
When importing an EDS/DCF file, any key that is not part of the CiA 306
standard field set is now collected into a custom_options dict on the object.
This allows applications to round-trip vendor-specific metadata without
losing it.

Co-authored-by: FedericoSpada <FedericoSpada@users.noreply.github.com>
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.

2 participants