feat(hiroz-py): rclpy alignment — P1–P8 API improvements#192
Open
YuanYuYuan wants to merge 1 commit into
Open
Conversation
Implements all 8 proposals from the rclpy API alignment review: P1 — wait_for_service / wait_for_server / wait_for_subscription Adds graph-polling wait primitives to ZClient, ZActionClient, and ZPublisher. Replaces time.sleep(1.0) anti-pattern in all examples. P2 — Smart error for swapped arguments create_publisher/create_subscriber detect when msg_type and topic args are positionally swapped (rclpy order vs hiroz order) and raise a clear TypeError. P3 — Method aliases ZNode.create_subscription aliased to create_subscriber. P4 — Service grouping type in codegen python_msgspec_generator now emits AddTwoInts.Request / .Response grouping classes with __srvtype__. create_client/create_server accept the grouping class or the bare Request class (back-compat). P5 — Wire custom exception types Timeouts now raise hiroz_py.TimeoutError instead of bare RuntimeError. Tests and examples updated accordingly. P6 — Optional callback-style create_server create_server accepts optional callback= kwarg; spawns a background thread when provided. Pull mode (take_request/send_response) remains the default. ZNode.create_service added as alias. P7 — Action grouping type in codegen Actions emit Fibonacci.Goal / .Result / .Feedback grouping classes with __actiontype__. create_action_client/server accept either form. P8 — QoS enum constants + int-depth shorthand ReliabilityPolicy, DurabilityPolicy, HistoryPolicy, LivelinessPolicy enums added to __init__.py. QoS params accept int (depth shorthand, rclpy-style). Also adds test_rclpy_alignment.py (17 tests, all passing). 65 total tests pass, clippy clean, ruff clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements 8 concrete API improvements to
hiroz-pythat reduce migration friction for users coming fromrclpy, without touching hiroz's reactive no-spincore. All changes are additive and non-breaking.wait_for_service/wait_for_server/wait_for_subscription: graph-polling wait primitives that replace thetime.sleep(1.0)anti-pattern present in every examplecreate_publisher/create_subscriber: rclpy orders(msg_type, topic), hiroz orders(topic, msg_type)— silent positional failures now raise a clearTypeErrorwith a migration hintcreate_subscriptionandcreate_servicealiases onZNodeAddTwoInts.Request/.Responsewith__srvtype__);create_client/create_serveraccept the grouping class or the bareRequestclass (back-compat preserved)TimeoutError/SerializationError/TypeMismatchError: timeouts now raisehiroz_py.TimeoutErrorinstead of bareRuntimeErrorcreate_server(callback=fn): spawns a background handler thread; pull mode unchanged when omitted. Addscreate_servicealias.Fibonacci.Goal/.Result/.Feedbackwith__actiontype__);create_action_client/create_action_serveraccept either formReliabilityPolicy.RELIABLE,DurabilityPolicy.VOLATILE, etc.) andqos=10int-depth shorthand (rclpy-style)Key Changes
crates/hiroz-py/src/:node.rs,service.rs,action.rs,pubsub.rs,graph.rs,error.rs,qos.rs,traits.rscrates/hiroz-codegen/src/python_msgspec_generator.rs: P4 + P7 grouping class emissioncrates/hiroz-msgs/python/hiroz_msgs_py/types/*.py: regenerated with grouping classescrates/hiroz-py/python/hiroz_py/__init__.py+__init__.pyi: aliases, enums, updated stubscrates/hiroz-py/examples/: all three examples updated to use the new APIcrates/hiroz-py/tests/test_rclpy_alignment.py: 17 new end-to-end testsBreaking Changes
None. All changes are additive. Existing code using bare
Requestclasses,create_subscriber, pull-mode servers, and string QoS values continues to work.Open items (not in this PR)
threading.excepthookor a.last_errorpropertywait_for_serviceuses a 50ms polling loop; could be replaced with a liveliness-based notify once that API stabilises in hiroz core_tmp/MIGRATION-GUIDE.md) not yet added to the book