fix(python_codegen): emit service methods without PascalCase prefix #40
No reviewers
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_router!40
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/python-codegen-strip-service-prefix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes lhumina_code/hero_rpc#29.
Service methods declared on an OSchema
serviceblock (e.g.LogicService.play_start) were previously emitted asLogicService_play_startin the generated Python client — ugly, not what the issue expected, and effectively unused (every flow template hand-rolls raw socket/JSON-RPC instead of importing the generated client).This PR:
to_python_method_nameso the generated method isplay_start,workflow_clone,workflow_version_fetch, etc. CRUD (play.list) and management (rpc.discover) methods are untouched — they keep their lowercase prefixes. The wire method name stays intact inside_call(...).descriptionoversummaryfor docstrings, becausehero_rpc's openrpc.json generator writes the real oschema comment intodescriptionwhilesummaryduplicates the method name. Hand-authored specs (hero_router's own static spec) only setsummary, so the fallback keeps them working.examples/regen_python_clientso a service's cached Python files can be regenerated from a static OpenRPC spec without rebuilding + restarting the service behind it — useful for local iteration and for this PR's verification step.JS and Rust generators are untouched.
Verification
All 25 LogicService methods are now present with typed signatures and description-sourced docstrings. No
LogicService_prefix remains.New tests:
test_python_method_nameextended to cover PascalCase stripping, lowercase passthrough, nested dots, and hyphenstest_service_methods_emitted_without_prefix— end-to-end assert on generator outputOne pre-existing test (
test_generate_from_router_spec) was already failing ondevelopmentbefore this change (asserts21 methodsbut the spec now has a different count) — not addressed here.Size comparison (for the hero_rpc#29 ask)
Every Python node in
hero_logic/crates/hero_logic/templates/*.jsontoday pastes a localrpc()helper with aUDSclass to make JSON-RPC-over-Unix-socket calls — ~18 lines of boilerplate per node. Across the 5 flow templates: 12 such Python nodes, ~95 total boilerplate lines.With the new generated client, each node collapses to:
≈ 2 lines instead of 18 → ~190 lines of boilerplate deletable when the templates are rewritten.
Template rewrites are explicitly not in this PR — they're scheduled for deletion in lhumina_code/hero_logic#13 per the flows-as-python epic (hero_logic#10). Touching them here would waste work.
Follow-up issues (already filed)
rpc.discovercan serve a stale cached spec. Orthogonal — this PR regenerates from the static openrpc.json, so it's unaffected. A separate PR will address the live-spec freshness.Test plan
cargo test -p hero_router --lib python_codegen— 7/7 new/updated tests passcargo build -p hero_router --example regen_python_clienthero_logic's static specplay_start|workflow_clone|workflow_version_fetchin the regenerated clientLogicService_prefix in the regenerated clienthero_logicrebuild (depends on hero_logic rebuild; out of scope — see hero_rpc#32)🤖 Generated with Claude Code