Fix enum item sets conversion
I believe this might have been broken after switch to jpype 0.7, as internal properties became forbidden, one has to use getter methods.
Proof of concept:
Python 3.6.5 (default, Jun 15 2019, 23:43:46)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyjapc
>>> japc = pyjapc.PyJapc(incaAcceleratorName='', selector='')
/opt/isinkare/projects/devenv/lib/python3.6/site-packages/jpype/_core.py:218: UserWarning:
-------------------------------------------------------------------------------
Deprecated: convertStrings was not specified when starting the JVM. The default
behavior in JPype will be False starting in JPype 0.8. The recommended setting
for new code is convertStrings=False. The legacy value of True was assumed for
this session. If you are a user of an application that reported this warning,
please file a ticket with the developer.
-------------------------------------------------------------------------------
""")
>>> japc.getParam('KFA45.867.FIDS.dumpSwitch/SettingRegisters#ModuleParam', noPyConversion=False)
Traceback (most recent call last):
File "/opt/isinkare/projects/devenv/lib/python3.6/site-packages/pyjapc/pyjapc.py", line 729, in _processTempValue
vals, heads = self._convertParGroupToPy(temp_value, unixtime)
File "/opt/isinkare/projects/devenv/lib/python3.6/site-packages/pyjapc/pyjapc.py", line 1449, in _convertParGroupToPy
for fspv in failSafeParValues:
TypeError: 'cern.japc.core.spi.AcquiredParameterValueImpl' object is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/isinkare/projects/devenv/lib/python3.6/site-packages/pyjapc/pyjapc.py", line 580, in getParam
return self._processTempValue(temp_value=temp_val, getHeader=getHeader, noPyConversion=noPyConversion, unixtime=unixtime)
File "/opt/isinkare/projects/devenv/lib/python3.6/site-packages/pyjapc/pyjapc.py", line 742, in _processTempValue
val = self._convertValToPy(parValue)
File "/opt/isinkare/projects/devenv/lib/python3.6/site-packages/pyjapc/pyjapc.py", line 1430, in _convertValToPy
return self._convertSimpleValToPy(val)
File "/opt/isinkare/projects/devenv/lib/python3.6/site-packages/pyjapc/pyjapc.py", line 1382, in _convertSimpleValToPy
return [(v.code, v.string) for v in val.value]
AttributeError: 'cern.japc.value.spi.value.simple.EnumSetValue' object has no attribute 'value'
Merge request reports
Activity
Aha. Thanks @isinkare. I've been fighting with JAPC in order to build an enumset for testing (for the inverse conversion, but my forward testing would have caught this). I wouldn't dream of making it a requirement for this MR, but if you have any more insight than I do into building an enumset instance, I would gladly take it.
The failing CI is related to the latest JPype in the v7.x series. I think in reality PyJapc is going to need to pin to specific versions given the frequency in which JPype seems to break between patch versions
.Something like this?
import jpype as jp EnumerationRegistry = jp.JClass("cern.japc.value.spi.value.EnumerationRegistry") EnumItemData = jp.JClass("cern.japc.value.spi.value.EnumItemData") EnumItemSetImpl = jp.JClass("cern.japc.value.spi.value.EnumItemSetImpl") EnumTypeBitSize = jp.JClass("cern.japc.value.EnumTypeBitSize") SimpleParameterValueFactory = jp.JClass("cern.japc.core.factory.SimpleParameterValueFactory") HashSet = jp.JClass("java.util.HashSet") item_set = HashSet() item_set.add(EnumItemData(1, "Item 1")) item_set.add(EnumItemData(2, "Item 2")) item_set.add(EnumItemData(4, "Item 3")) item_set.add(EnumItemData(8, "Item 4")) enum_type = EnumerationRegistry.registerEnumType("TestEnum", EnumTypeBitSize.BYTE, item_set) enum_item_set = EnumItemSetImpl(enum_type, 1 | 4 | 8) enum_set_value = SimpleParameterValueFactory.newSimpleParameterValue(enum_item_set) print(enum_set_value)
yields
(EnumSet:1) -> [Item 1, Item 3, Item 4]
Cheers, Michi
added 1 commit
- a04d2101 - Fix failing CI by pinning JPype back to 0.7.1.
added 1 commit
- c19c2bba - Fix failing CI by pinning JPype back to 0.7.1.
Thanks for the extremely helpful hint @mihostet!
I've updated the MR to include a test for the code that was originally proposed by Ivan. Whilst updating the enumset test I also added the integer to enumset conversion that was raised via acc-py-support last week.
In order to get the CI passing, I've also pinned the 0.7.x series to 0.7.1. Further work is needed to support v0.7.[3|4], but that is independent of this MR.
mentioned in commit c4af18be
mentioned in merge request !44 (merged)