-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added enum support to Measurement Client #880
Conversation
We construct new enum class using enum values from enum parameter in measurement: ring parameter in measurement: ring parameter in python client: So, ring values can be only be set to integers in client, we cannot use the name (RED, GREEN, BLUE) here. Please share your thoughts on this @bkeryan We confirmed this behaviour for LabVIEW client. Can you please share your thoughts on this behaviour for python client. |
...rator/ni_measurement_plugin_sdk_generator/client/templates/measurement_plugin_client.py.mako
Outdated
Show resolved
Hide resolved
packages/generator/ni_measurement_plugin_sdk_generator/client/_support.py
Outdated
Show resolved
Hide resolved
packages/generator/ni_measurement_plugin_sdk_generator/client/_support.py
Outdated
Show resolved
Hide resolved
packages/generator/ni_measurement_plugin_sdk_generator/client/_support.py
Outdated
Show resolved
Hide resolved
packages/generator/ni_measurement_plugin_sdk_generator/client/_support.py
Outdated
Show resolved
Hide resolved
packages/generator/ni_measurement_plugin_sdk_generator/client/_support.py
Outdated
Show resolved
Hide resolved
There is a mypy error and will be fixed soon. |
Fixed. The error was on this line seems like mypy static analysis checks for a string literal but we pass a variable. To resolve this error, I've used enum |
This is an indication that we are using the enum functional API wrong (as far as the Mypy authors are concerned, at least). I don't think that calling dunder methods directly is a good solution, because dunder methods are typically implementations of Python features that have their own syntax, and in most cases you should use that syntax instead. If we absolutely must use the enum functional API in this way, then I would prefer to use Also I don't think the generated code should be doing this at all. It has static definitions of all of the enum types and it should use them. |
Seems like MyPy static analysis throws an error if we don't use a direct string literal for dynamic Enum creation. So I have suppressed the error instead of using dunner method like you suggested. Syntax like,
Removed and used the already available metadata. |
def _replace_enum_class_type(output: str) -> str: | ||
pattern = "<enum '([^']+)'>" | ||
return re.sub(pattern, r"\1", output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this method go into _support.py?
name = "".join(s.capitalize() for s in split_string) | ||
else: | ||
name = name[0].upper() + name[1:] | ||
return name + "Enum" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer f-strings for better readability.
@measurement_service.configuration("Enum In", nims.DataType.Enum, Color.BLUE, enum_type=Color) | ||
@measurement_service.configuration( | ||
"Enum Array In", nims.DataType.EnumArray1D, [1, 2], enum_type=Color | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be an over-ask but because we showcase "protobuf enums" in our sample measurement, should we also test the Protobuf Enum type with our client to ensure we're not missing anything on that part?
What does this Pull Request accomplish?
Added enum support for Measurement Client
Implements Task 2827579: Extend support to enums.
Why should this Pull Request be merged?
With this implementation, Measurement Client supports measurements with enum parameters.
Enum
in pascal case. Also, removed special characters from the class name.For example,
enum_values_by_type_name
which acts as a map to eliminate repeating enums.For example, Configuration
Enum In
and OutputEnum Out
will use the same Enum class, soenum_values_by_type_name
will be useful to avoid creating duplicate enums for both parameters.enum_type
while creating pools for the metadata.enum_type=<enum 'EnumInEnum'>) -> enum_type= EnumInEnum
What testing has been done?
Added automated tests.
Generated and verified the client with enum params like enums, enum arrays, and sparse enums.