-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathcompiler.py
More file actions
832 lines (721 loc) ยท 28 KB
/
compiler.py
File metadata and controls
832 lines (721 loc) ยท 28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
"""Compiler plugin infrastructure: protocols, contexts, and dispatch."""
from __future__ import annotations
import dataclasses
import inspect
from collections.abc import Callable, Sequence
from contextvars import ContextVar, Token
from types import TracebackType
from typing import TYPE_CHECKING, Any, ClassVar, Protocol, TypeAlias, cast
from typing_extensions import Self
from reflex_base.components.component import BaseComponent, Component
from reflex_base.utils.imports import ParsedImportDict, collapse_imports, merge_imports
from reflex_base.vars import VarData
from .base import HookOrder, Plugin
if TYPE_CHECKING:
from reflex.app import App, ComponentCallable
PageComponent: TypeAlias = Component | ComponentCallable
else:
PageComponent: TypeAlias = (
Component
| Callable[
[],
Component | tuple[Component, ...] | str,
]
)
class PageDefinition(Protocol):
"""Protocol for page-like objects compiled by :class:`CompileContext`."""
@property
def route(self) -> str:
"""Return the route for this page definition."""
...
@property
def component(self) -> PageComponent:
"""Return the component or callable for this page definition."""
...
ComponentAndChildren: TypeAlias = tuple[BaseComponent, tuple[BaseComponent, ...]]
ComponentReplacement: TypeAlias = BaseComponent | ComponentAndChildren | None
CompiledEnterHook: TypeAlias = Callable[
[BaseComponent, bool],
ComponentReplacement,
]
CompiledLeaveHook: TypeAlias = Callable[
[BaseComponent, tuple[BaseComponent, ...], bool],
ComponentReplacement,
]
EnterHookBinder: TypeAlias = Callable[
["PageContext", "CompileContext"],
CompiledEnterHook,
]
LeaveHookBinder: TypeAlias = Callable[
["PageContext", "CompileContext"],
CompiledLeaveHook,
]
@dataclasses.dataclass(frozen=True, slots=True, kw_only=True)
class CompilerHooks:
"""Dispatch compiler hooks across an ordered plugin chain."""
plugins: tuple[Plugin, ...] = ()
_eval_page_hooks: tuple[Callable[..., Any], ...] = dataclasses.field(
init=False,
repr=False,
)
_compile_page_hooks: tuple[Callable[..., Any], ...] = dataclasses.field(
init=False,
repr=False,
)
_enter_component_hook_binders: tuple[EnterHookBinder, ...] = dataclasses.field(
init=False,
repr=False,
)
_leave_component_hook_binders: tuple[LeaveHookBinder, ...] = dataclasses.field(
init=False,
repr=False,
)
_component_hooks_can_replace: bool = dataclasses.field(
init=False,
repr=False,
)
def __post_init__(self) -> None:
"""Resolve the active compiler hook callables once."""
object.__setattr__(self, "_eval_page_hooks", self._resolve_hooks("eval_page"))
object.__setattr__(
self,
"_compile_page_hooks",
self._resolve_hooks("compile_page"),
)
enter_buckets: dict[HookOrder, list[EnterHookBinder]] = {
order: [] for order in HookOrder
}
leave_buckets: dict[HookOrder, list[LeaveHookBinder]] = {
order: [] for order in HookOrder
}
component_hooks_can_replace = False
for plugin in self.plugins:
plugin_type = type(plugin)
if (
hook_impl := self._get_hook_impl(plugin, "enter_component")
) is not None:
enter_buckets[plugin_type._compiler_enter_component_order].append(
self._get_enter_hook_binder(plugin, hook_impl)
)
component_hooks_can_replace = component_hooks_can_replace or bool(
getattr(plugin_type, "_compiler_can_replace_enter_component", True)
)
if (
hook_impl := self._get_hook_impl(plugin, "leave_component")
) is not None:
leave_buckets[plugin_type._compiler_leave_component_order].append(
self._get_leave_hook_binder(plugin, hook_impl)
)
component_hooks_can_replace = component_hooks_can_replace or bool(
getattr(plugin_type, "_compiler_can_replace_leave_component", True)
)
object.__setattr__(
self,
"_enter_component_hook_binders",
tuple(binder for order in HookOrder for binder in enter_buckets[order]),
)
object.__setattr__(
self,
"_leave_component_hook_binders",
tuple(
binder
for order in HookOrder
for binder in reversed(leave_buckets[order])
),
)
object.__setattr__(
self,
"_component_hooks_can_replace",
component_hooks_can_replace,
)
@staticmethod
def _get_hook_impl(
plugin: Plugin,
hook_name: str,
) -> Callable[..., Any] | None:
"""Return the concrete hook implementation for a plugin, if any.
Args:
plugin: The plugin to inspect.
hook_name: The hook attribute name.
Returns:
The bound hook implementation, or ``None`` when the hook is inherited
unchanged from the default base implementation.
"""
plugin_impl = inspect.getattr_static(type(plugin), hook_name, None)
if plugin_impl is None:
return None
if plugin_impl is inspect.getattr_static(Plugin, hook_name, None):
return None
return cast(Callable[..., Any], getattr(plugin, hook_name, None))
def _resolve_hooks(self, hook_name: str) -> tuple[Callable[..., Any], ...]:
"""Resolve concrete hook implementations for the plugin chain.
Args:
hook_name: The hook attribute name.
Returns:
The ordered concrete hook implementations for the hook.
"""
return tuple(
hook_impl
for plugin in self.plugins
if (hook_impl := self._get_hook_impl(plugin, hook_name)) is not None
)
@staticmethod
def _get_enter_hook_binder(
plugin: Plugin,
hook_impl: Callable[..., Any],
) -> EnterHookBinder:
"""Return a binder that produces a compiled enter-component hook."""
if (
binder := getattr(plugin, "_compiler_bind_enter_component", None)
) is not None:
return cast(EnterHookBinder, binder)
def bind(
page_context: PageContext, compile_context: CompileContext
) -> CompiledEnterHook:
def enter_component(
comp: BaseComponent,
in_prop_tree: bool,
) -> ComponentReplacement:
return cast(
ComponentReplacement,
hook_impl(
comp,
page_context=page_context,
compile_context=compile_context,
in_prop_tree=in_prop_tree,
),
)
return enter_component
return bind
@staticmethod
def _get_leave_hook_binder(
plugin: Plugin,
hook_impl: Callable[..., Any],
) -> LeaveHookBinder:
"""Return a binder that produces a compiled leave-component hook."""
if (
binder := getattr(plugin, "_compiler_bind_leave_component", None)
) is not None:
return cast(LeaveHookBinder, binder)
def bind(
page_context: PageContext, compile_context: CompileContext
) -> CompiledLeaveHook:
def leave_component(
comp: BaseComponent,
children: tuple[BaseComponent, ...],
in_prop_tree: bool,
) -> ComponentReplacement:
return cast(
ComponentReplacement,
hook_impl(
comp,
children,
page_context=page_context,
compile_context=compile_context,
in_prop_tree=in_prop_tree,
),
)
return leave_component
return bind
def eval_page(
self,
page_fn: PageComponent,
/,
*,
page: PageDefinition,
**kwargs: Any,
) -> PageContext | None:
"""Return the first page context produced by the plugin chain."""
for hook_impl in self._eval_page_hooks:
result = hook_impl(page_fn, page=page, **kwargs)
if result is not None:
return cast(PageContext, result)
return None
def compile_page(
self,
page_ctx: PageContext,
/,
**kwargs: Any,
) -> None:
"""Run all ``compile_page`` hooks in plugin order."""
for hook_impl in self._compile_page_hooks:
hook_impl(page_ctx, **kwargs)
def compile_component(
self,
comp: BaseComponent,
/,
*,
page_context: PageContext,
compile_context: CompileContext,
in_prop_tree: bool = False,
) -> BaseComponent:
"""Walk a component tree once while dispatching cached enter/leave hooks.
Returns:
The compiled component root for this subtree.
"""
enter_hooks = tuple(
hook_binder(page_context, compile_context)
for hook_binder in self._enter_component_hook_binders
)
if not self._component_hooks_can_replace:
leave_hooks = tuple(
hook_binder(page_context, compile_context)
for hook_binder in self._leave_component_hook_binders
)
if len(enter_hooks) == 1 and not leave_hooks:
return self._compile_component_single_enter_fast_path(
comp,
enter_hook=enter_hooks[0],
page_context=page_context,
in_prop_tree=in_prop_tree,
)
return self._compile_component_without_replacements(
comp,
enter_hooks=enter_hooks,
leave_hooks=leave_hooks,
page_context=page_context,
in_prop_tree=in_prop_tree,
)
return self._compile_component_with_replacements(
comp,
enter_hooks=enter_hooks,
leave_hooks=tuple(
hook_binder(page_context, compile_context)
for hook_binder in self._leave_component_hook_binders
),
page_context=page_context,
in_prop_tree=in_prop_tree,
)
def _compile_component_without_replacements(
self,
comp: BaseComponent,
/,
*,
enter_hooks: tuple[CompiledEnterHook, ...],
leave_hooks: tuple[CompiledLeaveHook, ...],
page_context: PageContext,
in_prop_tree: bool = False,
) -> BaseComponent:
"""Walk a component tree when hook plans only observe state.
Returns:
The compiled component root for this subtree.
"""
def visit(
current_comp: BaseComponent,
current_in_prop_tree: bool,
) -> BaseComponent:
for hook_impl in enter_hooks:
hook_impl(
current_comp,
current_in_prop_tree,
)
updated_children: list[BaseComponent] | None = None
children = current_comp.children
for index, child in enumerate(children):
compiled_child = visit(
child,
current_in_prop_tree,
)
if updated_children is None:
if compiled_child is child:
continue
updated_children = list(children[:index])
updated_children.append(compiled_child)
if updated_children is not None:
current_comp = current_comp.copy_with(children=tuple(updated_children))
if isinstance(current_comp, Component):
for prop_component in current_comp._get_components_in_props():
visit(
prop_component,
True,
)
if leave_hooks:
compiled_children = tuple(current_comp.children)
for hook_impl in leave_hooks:
hook_impl(
current_comp,
compiled_children,
current_in_prop_tree,
)
return current_comp
return visit(
comp,
in_prop_tree,
)
def _compile_component_single_enter_fast_path(
self,
comp: BaseComponent,
/,
*,
enter_hook: CompiledEnterHook,
page_context: PageContext,
in_prop_tree: bool = False,
) -> BaseComponent:
"""Walk a component tree for the common one-enter-hook fast path.
Returns:
The compiled component root for this subtree.
"""
def visit(
current_comp: BaseComponent,
current_in_prop_tree: bool,
) -> BaseComponent:
enter_hook(
current_comp,
current_in_prop_tree,
)
updated_children: list[BaseComponent] | None = None
children = current_comp.children
for index, child in enumerate(children):
compiled_child = visit(
child,
current_in_prop_tree,
)
if updated_children is None:
if compiled_child is child:
continue
updated_children = list(children[:index])
updated_children.append(compiled_child)
if updated_children is not None:
current_comp = current_comp.copy_with(children=tuple(updated_children))
if isinstance(current_comp, Component):
for prop_component in current_comp._get_components_in_props():
visit(
prop_component,
True,
)
return current_comp
return visit(
comp,
in_prop_tree,
)
def _compile_component_with_replacements(
self,
comp: BaseComponent,
/,
*,
enter_hooks: tuple[CompiledEnterHook, ...],
leave_hooks: tuple[CompiledLeaveHook, ...],
page_context: PageContext,
in_prop_tree: bool = False,
) -> BaseComponent:
"""Walk a component tree while honoring hook replacements.
Returns:
The compiled component root for this subtree.
"""
apply_replacement = self._apply_replacement
def visit_children(
children: Sequence[BaseComponent],
current_in_prop_tree: bool,
) -> tuple[BaseComponent, ...]:
if not children:
return ()
updated_children: list[BaseComponent] | None = None
for index, child in enumerate(children):
compiled_child = visit(
child,
current_in_prop_tree,
)
if updated_children is None:
if compiled_child is child:
continue
updated_children = list(children[:index])
updated_children.append(compiled_child)
if updated_children is None:
return children if isinstance(children, tuple) else tuple(children)
return tuple(updated_children)
def visit(
current_comp: BaseComponent,
current_in_prop_tree: bool,
) -> BaseComponent:
compiled_component = current_comp
structural_children: tuple[BaseComponent, ...] | None = None
for hook_impl in enter_hooks:
compiled_component, structural_children = apply_replacement(
compiled_component,
structural_children,
hook_impl(
compiled_component,
current_in_prop_tree,
),
)
if structural_children is None:
structural_children = tuple(compiled_component.children)
compiled_children = visit_children(
structural_children,
current_in_prop_tree,
)
if isinstance(compiled_component, Component):
for prop_component in compiled_component._get_components_in_props():
visit(
prop_component,
True,
)
for hook_impl in leave_hooks:
compiled_component, replacement_children = apply_replacement(
compiled_component,
compiled_children,
hook_impl(
compiled_component,
compiled_children,
current_in_prop_tree,
),
)
if replacement_children is not compiled_children:
assert replacement_children is not None
# Re-walking fires enter/leave again on any child objects
# carried over from the original children tuple. Observing
# collectors dedupe by dict key, so this is idempotent for
# today's plugins; stateful side effects on the page
# context would be double-applied.
compiled_children = visit_children(
replacement_children,
current_in_prop_tree,
)
current = compiled_component.children
if len(compiled_children) != len(current) or any(
a is not b for a, b in zip(compiled_children, current, strict=True)
):
compiled_component = compiled_component.copy_with(
children=tuple(compiled_children)
)
return compiled_component
return visit(
comp,
in_prop_tree,
)
@staticmethod
def _apply_replacement(
comp: BaseComponent,
children: tuple[BaseComponent, ...] | None,
replacement: ComponentReplacement,
) -> tuple[BaseComponent, tuple[BaseComponent, ...] | None]:
"""Apply a plugin replacement to the current component state.
Args:
comp: The current component.
children: The current structural children.
replacement: The plugin-supplied replacement.
Returns:
The updated component and structural children pair.
"""
if replacement is None:
return comp, children
if isinstance(replacement, tuple):
return replacement
return replacement, children
@dataclasses.dataclass(kw_only=True)
class BaseContext:
"""Context manager that exposes itself through a class-local context var."""
__context_var__: ClassVar[ContextVar[Self | None]]
_attached_context_token: Token[Self | None] | None = dataclasses.field(
default=None,
init=False,
repr=False,
)
@classmethod
def __init_subclass__(cls, **kwargs: Any) -> None:
"""Initialize a dedicated context variable for each subclass."""
super().__init_subclass__(**kwargs)
cls.__context_var__ = ContextVar(cls.__name__, default=None)
@classmethod
def get(cls) -> Self:
"""Return the active context instance for the current task.
Returns:
The active context instance for the current task.
"""
context = cls.__context_var__.get()
if context is None:
msg = f"No active {cls.__name__} is attached to the current context."
raise RuntimeError(msg)
return context
def __enter__(self) -> Self:
"""Attach this context to the current task.
Returns:
The attached context instance.
"""
if self._attached_context_token is not None:
msg = "Context is already attached and cannot be entered twice."
raise RuntimeError(msg)
self._attached_context_token = type(self).__context_var__.set(self)
return self
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None:
"""Detach this context from the current task."""
del exc_type, exc_val, exc_tb
if self._attached_context_token is None:
return
try:
type(self).__context_var__.reset(self._attached_context_token)
finally:
self._attached_context_token = None
async def __aenter__(self) -> Self:
"""Attach this context to the current task asynchronously.
Returns:
The attached context instance.
"""
return self.__enter__()
async def __aexit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None:
"""Detach this context from the current task asynchronously."""
self.__exit__(exc_type, exc_val, exc_tb)
def ensure_context_attached(self) -> None:
"""Ensure this instance is the active context for the current task."""
try:
current = type(self).get()
except RuntimeError as err:
msg = (
f"{type(self).__name__} must be entered with 'with' or 'async with' "
"before calling this method."
)
raise RuntimeError(msg) from err
if current is not self:
msg = f"{type(self).__name__} is not attached to the current task context."
raise RuntimeError(msg)
@dataclasses.dataclass(slots=True, kw_only=True)
class PageContext(BaseContext):
"""Mutable compilation state for a single page."""
name: str
route: str
root_component: BaseComponent
imports: list[ParsedImportDict] = dataclasses.field(default_factory=list)
module_code: dict[str, None] = dataclasses.field(default_factory=dict)
hooks: dict[str, VarData | None] = dataclasses.field(default_factory=dict)
dynamic_imports: set[str] = dataclasses.field(default_factory=set)
refs: dict[str, None] = dataclasses.field(default_factory=dict)
app_wrap_components: dict[tuple[int, str], Component] = dataclasses.field(
default_factory=dict
)
frontend_imports: ParsedImportDict = dataclasses.field(default_factory=dict)
output_path: str | None = None
output_code: str | None = None
# Stack of ``id(component)`` for components whose subtree is
# memoize-suppressed. Populated by ``MemoizeStatefulPlugin`` when it
# encounters a ``MemoizationLeaf``-style snapshot boundary and popped on
# the matching ``leave_component``. Non-empty iff we are inside such a
# subtree.
memoize_suppressor_stack: list[int] = dataclasses.field(default_factory=list)
def merged_imports(self, *, collapse: bool = False) -> ParsedImportDict:
"""Return the imports accumulated for this page.
Args:
collapse: Whether to collapse duplicate imports.
Returns:
The merged page imports.
"""
imports = merge_imports(*self.imports) if self.imports else {}
return collapse_imports(imports) if collapse else imports
def custom_code_dict(self) -> dict[str, None]:
"""Return custom-code snippets keyed like legacy collectors.
Returns:
The page custom code keyed by snippet.
"""
return dict(self.module_code)
@dataclasses.dataclass(slots=True, kw_only=True)
class CompileContext(BaseContext):
"""Mutable compilation state for an entire compile run."""
app: App | None = None
pages: Sequence[PageDefinition]
hooks: CompilerHooks = dataclasses.field(default_factory=CompilerHooks)
compiled_pages: dict[str, PageContext] = dataclasses.field(default_factory=dict)
all_imports: ParsedImportDict = dataclasses.field(default_factory=dict)
app_wrap_components: dict[tuple[int, str], Component] = dataclasses.field(
default_factory=dict
)
stateful_routes: dict[str, None] = dataclasses.field(default_factory=dict)
# Auto-memoize wrapper tags seen during the tree walk (populated by
# ``MemoizeStatefulPlugin``).
memoize_wrappers: dict[str, None] = dataclasses.field(default_factory=dict)
# Compiler-generated experimental memo definitions for auto-memoized
# stateful wrappers. Stored as ``Any`` to keep ``reflex_base`` decoupled
# from ``reflex.experimental.memo``.
auto_memo_components: dict[str, Any] = dataclasses.field(default_factory=dict)
def compile(
self,
*,
evaluate_progress: Callable[[], None] | None = None,
render_progress: Callable[[], None] | None = None,
**kwargs: Any,
) -> dict[str, PageContext]:
"""Compile all configured pages through the plugin pipeline.
Args:
evaluate_progress: Callback invoked after each page evaluation.
render_progress: Callback invoked after each page render.
kwargs: Additional compiler-specific context.
Returns:
The compiled page contexts keyed by route.
"""
from reflex.compiler import compiler
from reflex.state import all_base_state_classes
self.ensure_context_attached()
self.compiled_pages.clear()
self.all_imports.clear()
self.app_wrap_components.clear()
self.stateful_routes.clear()
self.memoize_wrappers.clear()
self.auto_memo_components.clear()
for page in self.pages:
page_fn = page.component
n_states_before = len(all_base_state_classes)
page_ctx = self.hooks.eval_page(
page_fn,
page=page,
compile_context=self,
**kwargs,
)
if page_ctx is None:
page_name = getattr(page_fn, "__name__", repr(page_fn))
msg = (
f"No compiler plugin was able to evaluate page {page.route!r} "
f"({page_name})."
)
raise RuntimeError(msg)
if page_ctx.route in self.compiled_pages:
msg = f"Duplicate compiled page route {page_ctx.route!r}."
raise RuntimeError(msg)
if len(all_base_state_classes) > n_states_before:
self.stateful_routes[page.route] = None
self.compiled_pages[page_ctx.route] = page_ctx
if evaluate_progress is not None:
evaluate_progress()
for page, page_ctx in zip(
self.pages,
self.compiled_pages.values(),
strict=True,
):
with page_ctx:
page_ctx.root_component = self.hooks.compile_component(
page_ctx.root_component,
page_context=page_ctx,
compile_context=self,
)
self.hooks.compile_page(
page_ctx,
page=page,
compile_context=self,
**kwargs,
)
page_ctx.frontend_imports = page_ctx.merged_imports(collapse=True)
self.all_imports = merge_imports(
self.all_imports, page_ctx.frontend_imports
)
self.app_wrap_components.update(page_ctx.app_wrap_components)
page_ctx.output_path, page_ctx.output_code = (
compiler.compile_page_from_context(page_ctx)
)
if render_progress is not None:
render_progress()
return self.compiled_pages
__all__ = [
"BaseContext",
"CompileContext",
"CompilerHooks",
"ComponentAndChildren",
"PageContext",
"PageDefinition",
]