refactor: form-core wiring, JWT sessions, slowapi, packaging, frontend rewrite, test declutter
This commit is contained in:
parent
06ab25fb47
commit
03af41e837
74 changed files with 6089 additions and 5183 deletions
|
|
@ -29,6 +29,74 @@ FLOW_DIR = REPO_ROOT / "backend" / "flows"
|
|||
|
||||
HANDLE_QUOTE = "\u0153" # ReactFlow handle-id quoting used by Langflow exports
|
||||
|
||||
FORM_CORE_PATH = REPO_ROOT / "backend" / "components" / "kirche" / "_form_core.py"
|
||||
|
||||
INLINE_MARKER = "# <-- _form_core inlined by scripts/make_flow_fixtures.py:kirche_node()"
|
||||
|
||||
|
||||
def _inline_core() -> str:
|
||||
"""Body of _form_core.py minus docstring/future/std-imports (already present)."""
|
||||
text = FORM_CORE_PATH.read_text(encoding="utf-8")
|
||||
lines = text.splitlines()
|
||||
body: list[str] = []
|
||||
skip_docstring = True
|
||||
in_docstring = False
|
||||
for line in lines:
|
||||
stripped = line.strip()
|
||||
if skip_docstring:
|
||||
if stripped.startswith('"""') and not in_docstring:
|
||||
if stripped.count('"""') >= 2:
|
||||
skip_docstring = False
|
||||
else:
|
||||
in_docstring = True
|
||||
continue
|
||||
if in_docstring:
|
||||
if '"""' in stripped:
|
||||
in_docstring = False
|
||||
skip_docstring = False
|
||||
continue
|
||||
if stripped in (
|
||||
"from __future__ import annotations",
|
||||
"import json",
|
||||
"import re",
|
||||
"",
|
||||
):
|
||||
continue
|
||||
skip_docstring = False
|
||||
if stripped in ("from __future__ import annotations", "import json", "import re"):
|
||||
continue
|
||||
body.append(line)
|
||||
return "\n".join(body).strip() + "\n"
|
||||
|
||||
|
||||
def _compose_component_code(source: str) -> str:
|
||||
"""Replace the sibling import + marker with inlined core (LFX self-contained)."""
|
||||
core = _inline_core()
|
||||
out: list[str] = []
|
||||
skipping_import = False
|
||||
for line in source.splitlines():
|
||||
stripped = line.strip()
|
||||
if not skipping_import and stripped.startswith(
|
||||
("from kirche._form_core import", "from ._form_core import")
|
||||
):
|
||||
out.append(core.rstrip())
|
||||
# Multi-line parenthesized import: skip continuation lines
|
||||
# up to and including the closing paren.
|
||||
if "(" in stripped and ")" not in stripped:
|
||||
skipping_import = True
|
||||
continue
|
||||
if skipping_import:
|
||||
if ")" in stripped:
|
||||
skipping_import = False
|
||||
continue
|
||||
if "_form_core inlined by" in stripped:
|
||||
continue
|
||||
out.append(line)
|
||||
composed = "\n".join(out)
|
||||
assert "from kirche" not in composed, "sibling import survived inlining"
|
||||
assert "from ._" not in composed, "relative import survived inlining"
|
||||
return composed
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# node builders
|
||||
|
|
@ -118,7 +186,7 @@ def kirche_node(
|
|||
comp_name = getattr(component_cls, "name", None) or component_cls.__name__
|
||||
inst = component_cls()
|
||||
if code_override is not None:
|
||||
inst._code = code_override
|
||||
inst._code = _compose_component_code(code_override)
|
||||
frontend_node = ComponentFrontendNode.from_inputs(**inst.get_template_config(inst))
|
||||
inst._map_parameters_on_frontend_node(frontend_node)
|
||||
node = frontend_node.to_dict(keep_name=False)
|
||||
|
|
@ -126,6 +194,10 @@ def kirche_node(
|
|||
inst._map_parameters_on_template(node["template"])
|
||||
if not getattr(inst, "_code", None):
|
||||
inst.set_class_code()
|
||||
# Always compose: default path may already carry thin source with the
|
||||
# sibling import (Component base sets _code on init); override path is
|
||||
# pre-composed but re-composing is idempotent (no import lines left).
|
||||
inst._code = _compose_component_code(inst._code)
|
||||
node["template"]["code"] = {
|
||||
"advanced": True,
|
||||
"api_editable": False,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue