Skip to content

ogar-render-askama: render_python — Python import-shape emit PoC (SDK + package)#154

Merged
AdaWorldAPI merged 2 commits into
mainfrom
claude/ogar-python-emit
Jul 4, 2026
Merged

ogar-render-askama: render_python — Python import-shape emit PoC (SDK + package)#154
AdaWorldAPI merged 2 commits into
mainfrom
claude/ogar-python-emit

Conversation

@AdaWorldAPI

@AdaWorldAPI AdaWorldAPI commented Jul 4, 2026

Copy link
Copy Markdown
Owner

What

A Python emit back-end for the same ruff → OGAR harvest that render_osm
renders to Rust. Proves the pull-back side of the transpiler is
language-pluggable: OSM (and odoo) come out of the one substrate in Python
import shape, just like Rust.

Emits

python/osm/ — the package

  • models.py — one @dataclass per THINK class; associations → typed id
    fields (belongs_to/has_oneOptional[int], has_many/habtm
    List[int]); each grounded model carries its CLASS_ID.
  • controllers/<name>.py — the DO arm as a faithful mirror of
    app/controllers/, one module per source controller by its verbatim (snake)
    name: osm.controllers.nodes.show(inp), standalone, not methods. Mirrors the
    Rust controllers module — no singularisation.
  • __init__.py — re-exports each controller at the package root
    (osm.nodesosm.controllers.nodes) + CLASS_IDS.

python/ogar_sdk.py — the substrate-pull SDK (Python mirror of Rust
lance_graph_contract::ogar_codebook):

>>> from ogar_sdk import class_id, render_classid
>>> hex(class_id("osm_node"))
'0xf01'
>>> hex(render_classid("account_move", 0x0002))   # odoo, canon-high
'0x2020002'

Ships OSM (0x0F) and odoo/commerce (0x02) — the pull is domain-agnostic.

Verified

  • render_python builds clean; py_compile green on package + SDK.
  • Functional smoke: osm.controllers.nodes.show and re-exported
    osm.nodes.show both callable; class_id('osm_node')=0xf01;
    render_classid('account_move',0x0002)=0x2020002; Node.CLASS_ID=0xf01;
    osm.nodes.show({})NotImplementedError('port Api::NodesController#show').

Depends on

Stacks on #153 (the delete-the-singulariser / faithful-controllers change),
so the container module names are verbatim (nodes, searches, capabilities
— not searche, capabilitie). Merge #153 first.

Follow-up

Input is dict (the Rails params bag); typed params remain the ruff
param-harvest brick (same gap as the Rust DO arm).

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYvNjD8M8LMNYbRy3gq2FP

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 89f6b18. Configure here.

for (is_a, sources) in isas {
let fname = pyify(is_a);
if !seen.insert(fname.clone()) {
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colliding pyify drops actions

Medium Severity

When two distinct is_a rail keys in the same part_of module normalize to the same Python name via pyify, the emitter skips later entries with continue and never merges their controller sources into the surviving stub. Rails predicates ending in ? are especially at risk because snake adds a trailing underscore that trim_matches('_') then removes, so foo? and foo can share one function name and one tile vanishes from the package.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 89f6b18. Configure here.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 89f6b1855f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if let Some(concept) = &c.canonical_concept {
if let Some(id) = canonical_concept_id(concept) {
models.push_str(&format!(
" CLASS_ID: int = 0x{id:04X} # canonical concept `{concept}`\n"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mark generated CLASS_ID as a ClassVar

For grounded classes this emits CLASS_ID as a dataclass instance field, so it becomes part of __init__, repr, equality, and positional construction; for example the generated Node(5) sets CLASS_ID=5 and leaves changeset unset. Since this value is intended to be stable per-class identity, generate it as ClassVar[int] (and import ClassVar) so model instances cannot silently override or serialize it as mutable record data.

Useful? React with 👍 / 👎.

claude added 2 commits July 4, 2026 23:32
…singulariser)

Delete the singulariser entirely. It was inventing a namespace out of
string-munged controller names — arbitrary, lossy (English plurals aren't
invertible by heuristic: `Searches → searche`, `Capabilities → capabilitie`),
and irreversible. The controller's own name IS the faithful identity; the
semantics live in the classid, not in a prettified string.

The DO arm is now a faithful `controllers` module that mirrors
`app/controllers/` 1:1:
- `container_of` snake-cases the controller stem **verbatim**, no
  singularisation: `NodesController → nodes`, `MapsController → maps`,
  `SearchesController → searches`, `ChangesetCommentsController →
  changeset_comments`. Reversible; matches Rails' own resource routes.
- `controller_to_model` likewise stops singularising (returns `Nodes`).
- render_osm emits `generated/controllers.rs` (was `actions.rs`); osm-domain
  does `#[path=…] pub mod controllers;` + `pub use controllers::*;`, so both
  `osm_domain::controllers::nodes::show(input)` and the re-exported
  `osm_domain::nodes::show(input)` resolve.

The (part_of:is_a) rail + the `is_a` archetype axis (index→list, …) are
unchanged — only the invented singular container naming is gone. Regenerated
the parked snapshot; osm-domain builds; `container_of` verbatim test replaces
the deleted singulariser test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYvNjD8M8LMNYbRy3gq2FP
… + package)

The Python counterpart of render_osm: same ruff → OGAR substrate, a
language-pluggable emit back-end. Proves the pull-back side of the transpiler
is not Rust-specific — OSM (and odoo) come out of the one substrate in Python
import shape, just like Rust.

Emits under python/:
- osm/models.py           — one @DataClass per THINK class; associations →
                            typed id fields; each grounded model has CLASS_ID.
- osm/controllers/<name>.py — the DO arm as a FAITHFUL mirror of app/controllers/,
                            one module per source controller by its verbatim
                            (snake) name — `osm.controllers.nodes.show(inp)`,
                            standalone, not methods. No singularisation (mirrors
                            the Rust `controllers` module).
- osm/__init__.py         — re-exports each controller at the package root
                            (`osm.nodes` ≡ `osm.controllers.nodes`) + CLASS_IDS.
- ogar_sdk.py             — the substrate-pull SDK (Python mirror of Rust
                            lance_graph_contract::ogar_codebook): CODEBOOK +
                            class_id(concept) + render_classid(concept, prefix)
                            (canon-high). Ships OSM (0x0F) AND odoo/commerce
                            (0x02) — the pull is domain-agnostic.

Verified: example builds clean; py_compile green on package + SDK; functional
smoke — osm.controllers.nodes.show + re-exported osm.nodes.show both callable,
class_id('osm_node')=0xf01, render_classid('account_move',0x0002)=0x2020002,
osm.nodes.show({}) raises NotImplementedError('port Api::NodesController#show').

Stacks on #153 (the faithful-controllers / no-singulariser change) so the
container module names are verbatim (nodes/searches/capabilities, not
searche/capabilitie). Typed params (dict Input → typed) remain the ruff brick.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYvNjD8M8LMNYbRy3gq2FP
@AdaWorldAPI AdaWorldAPI force-pushed the claude/ogar-python-emit branch from 89f6b18 to 1f62666 Compare July 4, 2026 23:34
@AdaWorldAPI AdaWorldAPI merged commit 518ee9c into main Jul 4, 2026
1 check passed
AdaWorldAPI added a commit that referenced this pull request Jul 5, 2026
render_osm/render_python: merge colliding rail tiles + CLASS_ID as ClassVar (#154 review)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants