Add default value to nislsc python api - #67
Conversation
--------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Update function_helpers.py and templates files to consume default value field from nislscapi_full.json * Refactor the order of parameters to avoid python TypeError: positional argument follows keyword argument error * Regenerate generated Python module files --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
af3371e to
6bb49f5
Compare
* Added default value of None for the library parameter * Regenerate generated Python module files --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
6bb49f5 to
646ecac
Compare
* Refactor parameter ordering in unit tests --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
851de41 to
fdd3ed9
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the codegen metadata and templates so generated NI-SLSC Python APIs can expose parameter default values (notably library=None, timeouts, and “default resource” sentinels), and regenerates the affected modules and tests accordingly.
Changes:
- Added
defaultfields tonislscapi_full.jsonfor various parameters (timeouts, default resources). - Updated codegen helpers/templates to emit defaults in generated Python signatures (and to reorder required vs defaulted parameters).
- Regenerated
generated/nislsc/session.pyand updated unit tests/examples to match the new call signatures.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_session.py | Updates test calls to match reordered/generated Session method signatures and new keyword usage. |
| tests/unit/conftest.py | Updates the session fixture to use new initialize_session_with_devices signature/keywords. |
| src/codegen/utilities/function_helpers.py | Adds “include defaults” support, default formatting helpers, and signature reordering logic. |
| src/codegen/templates/utils.py.mako | Enables default emission for module-level generated functions. |
| src/codegen/templates/session.py.mako | Enables default emission for generated Session methods/classmethods. |
| src/codegen/templates/property.py.mako | Enables default emission for generated PropertyReference APIs. |
| src/codegen/templates/library.py.mako | Enables default emission for generated Library APIs. |
| src/codegen/templates/command.py.mako | Enables default emission for generated CommandReference APIs. |
| src/codegen/metadata/nislscapi_full.json | Adds default values in metadata (timeouts, $Default* resource sentinels). |
| generated/nislsc/session.py | Regenerated Session API with defaults and reordered parameters. |
| examples/show_command_and_property_tree.py | Updates example calls to match new Session method parameter order. |
| examples/reset_device.py | Updates example initialization call to use new keyword/default patterns. |
| examples/check_chassis_battery.py | Updates example property calls to match new parameter ordering/defaults. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Perform the tests on actual hardware and make sure the examples still work. Also try writing a simple python script to test if the default parameter is working as intended, especially the |
* Refactor parameter ordering in examples to match new defaults * Remove library,connection_timeout and reservation_timeout parameters from examples since they have default values. --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
…types --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
0bf3a56 to
30845a7
Compare
* Add * in get_function_parameter_list to make the Booleans keyword-only * Remove argument from get_function_parameter_list if the argument have default value. * Use named parameters for get_function_parameter_list to avoid ambiguity
* Add CONNECTED_DEVICES_ALIAS constant * Add RESERVED_DEVICES_ALIAS constant * Add DEFAULT_NVMEM_AREAS_ALIAS constant * Add DEFAULT_PHYS_CHANS_ALIAS constant * Add RESERVED_DEVICES_ALIAS constant * Add SESSION_ALIAS constant * Add SYSTEM_ALIAS constant --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Change timeout default value from -1 to -1.0 * Add default value "" for reservationGroup * Add default value "read/write" for reservationAccess * Update function_helpers.py to convert read/write to READ_WRITE * Generate new session.py with updated default values --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
053dc9b to
4175108
Compare
* Remove parameters from intialization if its value same as default value. * Reorder parameters to match the order in the function definition. --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Reorder parameters to match the order in the function definition. --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Add get_default_alias_constants in function_helpers.py to retrieve default alias constants. * Update session.py.mako to use get_default_alias_constants for default values. * Generate session.py with updated default values --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
* Remove default value of device/physchan/nvmem from read/write register and execute device/physicalChannel command * Generate new session.py with updated default values --------- Signed-off-by: zoechanzy <zoe.chan@emerson.com>
…n with the LabVIEW example Allow the session API to use its default reservation group when checking chassis battery. This matches the behavior of the equivalent LabVIEW example. Signed-off-by: Jun Liang, Tan <junliang.tan@emerson.com>
…LT_CHANS_ALIAS to align with the LabVIEW example Signed-off-by: Jun Liang, Tan <junliang.tan@emerson.com>
…device to align with the LabVIEW example Signed-off-by: Jun Liang, Tan <junliang.tan@emerson.com>
…e to align with the LabVIEW example Signed-off-by: Jun Liang, Tan <junliang.tan@emerson.com>
…VIEW example Remove device_names from reset_devices so that default devices are used. This aligns with the behavior of the equivalent LabVIEW example. Signed-off-by: Jun Liang, Tan <junliang.tan@emerson.com>
…vice alias for property queries Signed-off-by: Jun Liang, Tan <junliang.tan@emerson.com>
f6ab02e to
abc88dd
Compare
What does this Pull Request accomplish?
Why should this Pull Request be merged?
nislscapi.json is updated to have default values. Function helper and template files should be updated so that the default value can be used in code-gen.
What testing has been done?
-- Result of
poetry run .\examples\show_command_and_property_tree.py SLSC-12001-0368CF24-- Result of
poetry run .\examples\reset_device.py SLSC-12001-0368CF24-- Result of
poetry run .\examples\check_chassis_battery.py SLSC-12001-0368CF24Related work item:
USER STORY 3221873