spc-group / guarneri

Other
0 stars 0 forks source link

Basic YAML parsing #8

Open canismarko opened 4 days ago

canismarko commented 4 days ago

We should implement the YAML parser as well as the TOML parser.

I included a candidate YAML schema below. Does this meet the general use case, and is there anything common that wouldn't fit?

It would be nice if we could maintain some level of similarity with the existing TOML schema: https://github.com/spc-group/guarneri/blob/sansio/src/guarneri/iconfig_example.toml

Expected Behavior

There should be a basic schema and example that can be used for YAML files if no customization is needed. If people have specific needs, then they can re-implement Instrument.parse_yaml_file() or Instrument.parse_config().

Current Behavior

There is a stub Instrument.parse_yaml_file() that raises NotImplementedError if Instrument.load() is given a .yaml file.

Possible Solution

We can implement Instrument.parse_yaml_file(). I think the proposed YAML schema below fits nicely with the internal definitions used by Guarneri, so shouldn't be too hard to do.

We should make sure there aren't any common use cases that aren't met, though. Certainly open to discussion.

Here is some example YAML that would parse easily into Guarneri's internal device list.

- "ophyd.EpicsMotor":
  # Generic motor devices
  - name: "m1"
    prefix: "255idcVME:m1"
  - name: "m2"
    prefix: "255idcVME:m2"
# Area detectors
- "apstools.ad_creator":
  # Simulated area detector
  - prefix: "ad:"
    name: "adsimdet"
  # Eiger 500K area detector
  - prefix: "eiger:"
    name: "eiger_500K"
    plugins: 
      cam:
        class: apstools.devices.SimDetectorCam_V34
      image: null
      pva: null
      hdf1:
        class: apstools.devices.AD_EpicsFileNameHDF5Plugin
        kwargs:
          read_path_template: "/mnt/iocad/tmp/"
          write_path_template: "/tmp/"
      roi1: null
      stats1: null
prjemian commented 3 days ago

It will take some extra code here to handle the loading of classes for the ad_creator plugin definitions.

prjemian commented 3 days ago

A custom override could/would handle the replacement of strings with the actual class as referenced.