Skip to content

Feature: template in configuration file - #442

Draft
kparasch wants to merge 3 commits into
mainfrom
feature/configuration-template
Draft

kparasch wants to merge 3 commits into
mainfrom
feature/configuration-template

Conversation

@kparasch

Copy link
Copy Markdown
Member

This is an unfinished example of a Template class the replicates a specific class in the configuration:

example config:

- class: pyaml.configuration.template.Template
  template: |
    class: pyaml.magnet.hcorrector.HCorrector
    name: %template_parameter%
    model:
      class: pyaml.magnet.linear_model.LinearMagnetModel
      unit: rad
      hardware_unit: str
      calibration_factor: 1.0
      powerconverter: MAGNET/%template_parameter%/B1L
  string_to_replace: "%template_parameter%"
  parameter_list:
    - PKDK_WL_108
    - PKDK_WL_93
    - PKDK_WL_79
    - PKDK_WL_64

During building, the factory would instead build now 4 objects.

This required a few simple changes, but there are a lot of edge cases that are not checked.

  • I had the class be an iterator and treat it as a specific case in the Factory in order to avoid a configuration that would be built like: [[tobj1, tobj2, ...,] object 1] and instead have it be: [tobj1, tobj2, ..., object 1]
  • Because the Template generates an object that is different to the Template class, new function had to be overloaded instead of init. This meant handling this case in the validation.

An example building script and configuration file can be found in pyaml/examples/template.

@gubaidulinvadim gubaidulinvadim linked an issue Sep 18, 2026 that may be closed by this pull request
2 tasks
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.

Feature: Templates in configuration

1 participant