Replace sx_call() with render_to_sx() across all services
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m6s

Python no longer generates s-expression strings. All SX rendering now
goes through render_to_sx() which builds AST from native Python values
and evaluates via async_eval_to_sx() — no SX string literals in Python.

- Add render_to_sx()/render_to_html() infrastructure in shared/sx/helpers.py
- Add (abort status msg) IO primitive in shared/sx/primitives_io.py
- Convert all 9 services: ~650 sx_call() invocations replaced
- Convert shared helpers (root_header_sx, full_page_sx, etc.) to async
- Fix likes service import bug (likes.models → models)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 00:08:33 +00:00
parent 0554f8a113
commit e085fe43b4
51 changed files with 1824 additions and 1742 deletions

View File

@@ -26,33 +26,31 @@ def _register_federation_layouts() -> None:
register_custom_layout("social", _social_full, _social_oob)
def _social_full(ctx: dict, **kw: Any) -> str:
from shared.sx.helpers import root_header_sx, header_child_sx, sx_call, SxExpr
from shared.sx.parser import serialize
async def _social_full(ctx: dict, **kw: Any) -> str:
from shared.sx.helpers import root_header_sx, header_child_sx, render_to_sx
from shared.sx.parser import SxExpr
actor = ctx.get("actor")
actor_data = _serialize_actor(actor) if actor else None
nav = sx_call("federation-social-nav",
actor=SxExpr(serialize(actor_data)) if actor_data else None)
social_hdr = sx_call("federation-social-header", nav=SxExpr(nav))
root_hdr = root_header_sx(ctx)
child = header_child_sx(social_hdr)
nav = await render_to_sx("federation-social-nav", actor=actor_data)
social_hdr = await render_to_sx("federation-social-header", nav=SxExpr(nav))
root_hdr = await root_header_sx(ctx)
child = await header_child_sx(social_hdr)
return "(<> " + root_hdr + " " + child + ")"
def _social_oob(ctx: dict, **kw: Any) -> str:
from shared.sx.helpers import root_header_sx, sx_call, SxExpr
from shared.sx.parser import serialize
async def _social_oob(ctx: dict, **kw: Any) -> str:
from shared.sx.helpers import root_header_sx, render_to_sx
from shared.sx.parser import SxExpr
actor = ctx.get("actor")
actor_data = _serialize_actor(actor) if actor else None
nav = sx_call("federation-social-nav",
actor=SxExpr(serialize(actor_data)) if actor_data else None)
social_hdr = sx_call("federation-social-header", nav=SxExpr(nav))
child_oob = sx_call("oob-header-sx",
nav = await render_to_sx("federation-social-nav", actor=actor_data)
social_hdr = await render_to_sx("federation-social-header", nav=SxExpr(nav))
child_oob = await render_to_sx("oob-header-sx",
parent_id="root-header-child",
row=SxExpr(social_hdr))
root_hdr_oob = root_header_sx(ctx, oob=True)
root_hdr_oob = await root_header_sx(ctx, oob=True)
return "(<> " + child_oob + " " + root_hdr_oob + ")"
@@ -145,43 +143,40 @@ def _require_actor():
async def _h_home_timeline_content(**kw):
from quart import g
from shared.services.registry import services
from shared.sx.helpers import sx_call, SxExpr
from shared.sx.parser import serialize
from shared.sx.helpers import render_to_sx
actor = _require_actor()
items = await services.federation.get_home_timeline(g.s, actor.id)
return sx_call("federation-timeline-content",
items=SxExpr(serialize([_serialize_timeline_item(i) for i in items])),
return await render_to_sx("federation-timeline-content",
items=[_serialize_timeline_item(i) for i in items],
timeline_type="home",
actor=SxExpr(serialize(_serialize_actor(actor))))
actor=_serialize_actor(actor))
async def _h_public_timeline_content(**kw):
from quart import g
from shared.services.registry import services
from shared.sx.helpers import sx_call, SxExpr
from shared.sx.parser import serialize
from shared.sx.helpers import render_to_sx
actor = _get_actor()
items = await services.federation.get_public_timeline(g.s)
return sx_call("federation-timeline-content",
items=SxExpr(serialize([_serialize_timeline_item(i) for i in items])),
return await render_to_sx("federation-timeline-content",
items=[_serialize_timeline_item(i) for i in items],
timeline_type="public",
actor=SxExpr(serialize(_serialize_actor(actor))) if actor else None)
actor=_serialize_actor(actor))
async def _h_compose_content(**kw):
from quart import request
from shared.sx.helpers import sx_call
from shared.sx.helpers import render_to_sx
_require_actor()
reply_to = request.args.get("reply_to")
return sx_call("federation-compose-content",
return await render_to_sx("federation-compose-content",
reply_to=reply_to or None)
async def _h_search_content(**kw):
from quart import g, request
from shared.services.registry import services
from shared.sx.helpers import sx_call, SxExpr
from shared.sx.parser import serialize
from shared.sx.helpers import render_to_sx
actor = _get_actor()
query = request.args.get("q", "").strip()
actors_list = []
@@ -194,34 +189,32 @@ async def _h_search_content(**kw):
g.s, actor.preferred_username, page=1, per_page=1000,
)
followed_urls = {a.actor_url for a in following}
return sx_call("federation-search-content",
return await render_to_sx("federation-search-content",
query=query,
actors=SxExpr(serialize([_serialize_remote_actor(a) for a in actors_list])),
actors=[_serialize_remote_actor(a) for a in actors_list],
total=total,
followed_urls=SxExpr(serialize(list(followed_urls))),
actor=SxExpr(serialize(_serialize_actor(actor))) if actor else None)
followed_urls=list(followed_urls),
actor=_serialize_actor(actor))
async def _h_following_content(**kw):
from quart import g
from shared.services.registry import services
from shared.sx.helpers import sx_call, SxExpr
from shared.sx.parser import serialize
from shared.sx.helpers import render_to_sx
actor = _require_actor()
actors_list, total = await services.federation.get_following(
g.s, actor.preferred_username,
)
return sx_call("federation-following-content",
actors=SxExpr(serialize([_serialize_remote_actor(a) for a in actors_list])),
return await render_to_sx("federation-following-content",
actors=[_serialize_remote_actor(a) for a in actors_list],
total=total,
actor=SxExpr(serialize(_serialize_actor(actor))))
actor=_serialize_actor(actor))
async def _h_followers_content(**kw):
from quart import g
from shared.services.registry import services
from shared.sx.helpers import sx_call, SxExpr
from shared.sx.parser import serialize
from shared.sx.helpers import render_to_sx
actor = _require_actor()
actors_list, total = await services.federation.get_followers_paginated(
g.s, actor.preferred_username,
@@ -230,18 +223,17 @@ async def _h_followers_content(**kw):
g.s, actor.preferred_username, page=1, per_page=1000,
)
followed_urls = {a.actor_url for a in following}
return sx_call("federation-followers-content",
actors=SxExpr(serialize([_serialize_remote_actor(a) for a in actors_list])),
return await render_to_sx("federation-followers-content",
actors=[_serialize_remote_actor(a) for a in actors_list],
total=total,
followed_urls=SxExpr(serialize(list(followed_urls))),
actor=SxExpr(serialize(_serialize_actor(actor))))
followed_urls=list(followed_urls),
actor=_serialize_actor(actor))
async def _h_actor_timeline_content(id=None, **kw):
from quart import g, abort
from shared.services.registry import services
from shared.sx.helpers import sx_call, SxExpr
from shared.sx.parser import serialize
from shared.sx.helpers import render_to_sx
actor = _get_actor()
actor_id = id
from shared.models.federation import RemoteActor
@@ -268,18 +260,17 @@ async def _h_actor_timeline_content(id=None, **kw):
)
).scalar_one_or_none()
is_following = existing is not None
return sx_call("federation-actor-timeline-content",
remote_actor=SxExpr(serialize(_serialize_remote_actor(remote_dto))),
items=SxExpr(serialize([_serialize_timeline_item(i) for i in items])),
return await render_to_sx("federation-actor-timeline-content",
remote_actor=_serialize_remote_actor(remote_dto),
items=[_serialize_timeline_item(i) for i in items],
is_following=is_following,
actor=SxExpr(serialize(_serialize_actor(actor))) if actor else None)
actor=_serialize_actor(actor))
async def _h_notifications_content(**kw):
from quart import g
from shared.services.registry import services
from shared.sx.helpers import sx_call, SxExpr
from shared.sx.parser import serialize
from shared.sx.helpers import render_to_sx
actor = _require_actor()
items = await services.federation.get_notifications(g.s, actor.id)
await services.federation.mark_notifications_read(g.s, actor.id)
@@ -298,5 +289,5 @@ async def _h_notifications_content(**kw):
"read": getattr(n, "read", True),
"app_domain": getattr(n, "app_domain", ""),
})
return sx_call("federation-notifications-content",
notifications=SxExpr(serialize(notif_dicts)))
return await render_to_sx("federation-notifications-content",
notifications=notif_dicts)