spc-group / guarneri

Other
0 stars 0 forks source link

InvalidConfiguration exception: Missing required key 'args' #9

Closed prjemian closed 5 days ago

prjemian commented 1 week ago

Error is reproducible in TOML when using the sansio branch. Config file content:

[[ SimulatedApsPssShutterWithStatus ]]
name = "shutter"

Code that reproduces the exception trace:

"""docs"""

import guarneri
from apstools.devices import SimulatedApsPssShutterWithStatus

xref = {
    "SimulatedApsPssShutterWithStatus": SimulatedApsPssShutterWithStatus,
}
instr = guarneri.Instrument(xref)
instr.load("src/instrument/configs/guarneri-shutters.toml")
print(f"{sorted(instr.devices.device_names)=!r}")
print(f"component count: {len(instr.devices.component_names)}")

The exception trace:

(test) prjemian@arf:~/bluesky$ !python
python ./dev_demo.py 
Traceback (most recent call last):
  File "/home/prjemian/bluesky/./dev_demo.py", line 10, in <module>
    instr.load("src/instrument/configs/guarneri-shutters.toml")
  File "/home/prjemian/.conda/envs/test/lib/python3.11/site-packages/guarneri/instrument.py", line 352, in load
    devices = self.make_devices(device_defns, fake=fake)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/prjemian/.conda/envs/test/lib/python3.11/site-packages/guarneri/instrument.py", line 155, in make_devices
    self.validate_params(defn["kwargs"], Klass)
  File "/home/prjemian/.conda/envs/test/lib/python3.11/site-packages/guarneri/instrument.py", line 190, in validate_params
    raise InvalidConfiguration(
guarneri.exceptions.InvalidConfiguration: Missing required key 'args' for <class 'apstools.devices.shutters.SimulatedApsPssShutterWithStatus'>: {'name': 'shutter'}

Originally posted by @prjemian in https://github.com/spc-group/guarneri/issues/5#issuecomment-2484797325

prjemian commented 1 week ago

Build the conda test environment:

conda create -y -n test python=3.11
conda activate test
pip install https://github.com/spc-group/guarneri/archive/sansio.zip apstools
canismarko commented 6 days ago

Thanks @prjemian. It should just skip validation for *args, so the fact that you're getting that error is a bug. But beyond that, I should actually validate *args and *kwargs together, since a required argument might be in *args instead of **kwargs in which case validation of *kwargs alone would fail.

I'll work on this.

prjemian commented 6 days ago

Is it as simple as adding an exclusion check for sig_param.VAR_POSITIONAL at the start of this loop? https://github.com/spc-group/guarneri/blob/68c797375708b1e30ac410cfc019febc7b74d2bf/src/guarneri/instrument.py#L182-L184

canismarko commented 5 days ago

Should be fixed now that #5 is merged. *args is now properly recognized as being optional.

Let me know if there are still any issues.