reflex 0.7.13a2__py3-none-any.whl → 0.7.14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of reflex might be problematic. Click here for more details.
- reflex/.templates/apps/blank/code/blank.py +0 -2
- reflex/app.py +85 -89
- reflex/app_mixins/lifespan.py +2 -3
- reflex/app_mixins/middleware.py +1 -0
- reflex/app_mixins/mixin.py +0 -1
- reflex/assets.py +7 -4
- reflex/base.py +3 -2
- reflex/compiler/compiler.py +79 -65
- reflex/compiler/utils.py +8 -6
- reflex/components/base/app_wrap.pyi +0 -1
- reflex/components/base/bare.py +22 -12
- reflex/components/base/body.pyi +0 -1
- reflex/components/base/document.pyi +0 -5
- reflex/components/base/error_boundary.pyi +0 -1
- reflex/components/base/fragment.pyi +0 -1
- reflex/components/base/head.pyi +0 -2
- reflex/components/base/link.pyi +0 -2
- reflex/components/base/meta.py +2 -1
- reflex/components/base/meta.pyi +0 -4
- reflex/components/base/script.py +2 -1
- reflex/components/base/script.pyi +0 -1
- reflex/components/base/strict_mode.pyi +0 -1
- reflex/components/component.py +85 -45
- reflex/components/core/auto_scroll.pyi +0 -1
- reflex/components/core/banner.py +1 -1
- reflex/components/core/banner.pyi +0 -6
- reflex/components/core/breakpoints.py +9 -11
- reflex/components/core/client_side_routing.pyi +0 -2
- reflex/components/core/clipboard.pyi +0 -1
- reflex/components/core/colors.py +10 -7
- reflex/components/core/cond.py +4 -2
- reflex/components/core/debounce.py +5 -3
- reflex/components/core/debounce.pyi +0 -1
- reflex/components/core/foreach.py +8 -6
- reflex/components/core/html.py +3 -3
- reflex/components/core/html.pyi +0 -1
- reflex/components/core/match.py +19 -17
- reflex/components/core/sticky.pyi +0 -4
- reflex/components/core/upload.py +1 -1
- reflex/components/core/upload.pyi +0 -5
- reflex/components/datadisplay/code.py +1 -2
- reflex/components/datadisplay/code.pyi +0 -2
- reflex/components/datadisplay/dataeditor.py +7 -10
- reflex/components/datadisplay/dataeditor.pyi +0 -1
- reflex/components/datadisplay/logo.py +3 -4
- reflex/components/datadisplay/shiki_code_block.py +8 -11
- reflex/components/datadisplay/shiki_code_block.pyi +0 -3
- reflex/components/dynamic.py +2 -3
- reflex/components/el/__init__.pyi +2 -0
- reflex/components/el/element.pyi +0 -1
- reflex/components/el/elements/__init__.py +1 -0
- reflex/components/el/elements/__init__.pyi +3 -0
- reflex/components/el/elements/base.pyi +0 -1
- reflex/components/el/elements/forms.py +14 -15
- reflex/components/el/elements/forms.pyi +15 -32
- reflex/components/el/elements/inline.pyi +0 -28
- reflex/components/el/elements/media.py +26 -0
- reflex/components/el/elements/media.pyi +259 -25
- reflex/components/el/elements/metadata.py +0 -1
- reflex/components/el/elements/metadata.pyi +0 -6
- reflex/components/el/elements/other.pyi +0 -7
- reflex/components/el/elements/scripts.pyi +0 -3
- reflex/components/el/elements/sectioning.pyi +0 -15
- reflex/components/el/elements/tables.pyi +0 -10
- reflex/components/el/elements/typography.pyi +0 -15
- reflex/components/gridjs/datatable.py +10 -13
- reflex/components/gridjs/datatable.pyi +0 -2
- reflex/components/lucide/icon.py +10 -9
- reflex/components/lucide/icon.pyi +0 -3
- reflex/components/markdown/markdown.py +6 -8
- reflex/components/markdown/markdown.pyi +0 -1
- reflex/components/moment/moment.pyi +0 -1
- reflex/components/next/base.py +0 -2
- reflex/components/next/base.pyi +0 -3
- reflex/components/next/image.pyi +0 -1
- reflex/components/next/link.pyi +0 -1
- reflex/components/next/video.pyi +0 -1
- reflex/components/plotly/plotly.pyi +0 -9
- reflex/components/props.py +4 -3
- reflex/components/radix/primitives/accordion.pyi +0 -7
- reflex/components/radix/primitives/base.py +1 -3
- reflex/components/radix/primitives/base.pyi +0 -2
- reflex/components/radix/primitives/drawer.pyi +0 -11
- reflex/components/radix/primitives/form.py +4 -8
- reflex/components/radix/primitives/form.pyi +0 -12
- reflex/components/radix/primitives/progress.py +1 -1
- reflex/components/radix/primitives/progress.pyi +0 -5
- reflex/components/radix/primitives/slider.py +1 -1
- reflex/components/radix/primitives/slider.pyi +0 -5
- reflex/components/radix/themes/base.pyi +0 -8
- reflex/components/radix/themes/color_mode.pyi +0 -3
- reflex/components/radix/themes/components/alert_dialog.py +4 -2
- reflex/components/radix/themes/components/alert_dialog.pyi +4 -9
- reflex/components/radix/themes/components/aspect_ratio.py +1 -2
- reflex/components/radix/themes/components/aspect_ratio.pyi +1 -3
- reflex/components/radix/themes/components/avatar.py +5 -2
- reflex/components/radix/themes/components/avatar.pyi +1 -3
- reflex/components/radix/themes/components/badge.py +5 -2
- reflex/components/radix/themes/components/badge.pyi +1 -3
- reflex/components/radix/themes/components/button.py +2 -3
- reflex/components/radix/themes/components/button.pyi +1 -3
- reflex/components/radix/themes/components/callout.py +1 -2
- reflex/components/radix/themes/components/callout.pyi +1 -7
- reflex/components/radix/themes/components/card.py +1 -2
- reflex/components/radix/themes/components/card.pyi +1 -3
- reflex/components/radix/themes/components/checkbox.py +7 -4
- reflex/components/radix/themes/components/checkbox.pyi +1 -5
- reflex/components/radix/themes/components/checkbox_cards.py +1 -2
- reflex/components/radix/themes/components/checkbox_cards.pyi +1 -4
- reflex/components/radix/themes/components/checkbox_group.py +1 -2
- reflex/components/radix/themes/components/checkbox_group.pyi +1 -4
- reflex/components/radix/themes/components/context_menu.py +1 -1
- reflex/components/radix/themes/components/context_menu.pyi +1 -14
- reflex/components/radix/themes/components/data_list.py +1 -2
- reflex/components/radix/themes/components/data_list.pyi +1 -6
- reflex/components/radix/themes/components/dialog.py +4 -2
- reflex/components/radix/themes/components/dialog.pyi +4 -9
- reflex/components/radix/themes/components/dropdown_menu.py +5 -2
- reflex/components/radix/themes/components/dropdown_menu.pyi +4 -10
- reflex/components/radix/themes/components/hover_card.py +4 -2
- reflex/components/radix/themes/components/hover_card.pyi +4 -6
- reflex/components/radix/themes/components/icon_button.py +7 -8
- reflex/components/radix/themes/components/icon_button.pyi +1 -3
- reflex/components/radix/themes/components/inset.py +1 -2
- reflex/components/radix/themes/components/inset.pyi +1 -3
- reflex/components/radix/themes/components/popover.py +4 -2
- reflex/components/radix/themes/components/popover.pyi +4 -6
- reflex/components/radix/themes/components/progress.py +1 -2
- reflex/components/radix/themes/components/progress.pyi +1 -3
- reflex/components/radix/themes/components/radio.py +1 -2
- reflex/components/radix/themes/components/radio.pyi +1 -3
- reflex/components/radix/themes/components/radio_cards.py +1 -2
- reflex/components/radix/themes/components/radio_cards.pyi +1 -4
- reflex/components/radix/themes/components/radio_group.py +7 -5
- reflex/components/radix/themes/components/radio_group.pyi +1 -6
- reflex/components/radix/themes/components/scroll_area.py +1 -2
- reflex/components/radix/themes/components/scroll_area.pyi +1 -3
- reflex/components/radix/themes/components/segmented_control.py +1 -2
- reflex/components/radix/themes/components/segmented_control.pyi +1 -4
- reflex/components/radix/themes/components/select.py +5 -2
- reflex/components/radix/themes/components/select.pyi +1 -11
- reflex/components/radix/themes/components/separator.py +1 -2
- reflex/components/radix/themes/components/separator.pyi +1 -3
- reflex/components/radix/themes/components/skeleton.py +1 -2
- reflex/components/radix/themes/components/skeleton.pyi +1 -3
- reflex/components/radix/themes/components/slider.py +1 -2
- reflex/components/radix/themes/components/slider.pyi +1 -3
- reflex/components/radix/themes/components/spinner.py +1 -2
- reflex/components/radix/themes/components/spinner.pyi +1 -3
- reflex/components/radix/themes/components/switch.py +1 -2
- reflex/components/radix/themes/components/switch.pyi +1 -3
- reflex/components/radix/themes/components/table.py +1 -2
- reflex/components/radix/themes/components/table.pyi +1 -9
- reflex/components/radix/themes/components/tabs.py +1 -2
- reflex/components/radix/themes/components/tabs.pyi +1 -7
- reflex/components/radix/themes/components/text_area.py +5 -2
- reflex/components/radix/themes/components/text_area.pyi +2 -4
- reflex/components/radix/themes/components/text_field.py +5 -2
- reflex/components/radix/themes/components/text_field.pyi +1 -5
- reflex/components/radix/themes/components/tooltip.py +1 -2
- reflex/components/radix/themes/components/tooltip.pyi +1 -3
- reflex/components/radix/themes/layout/base.py +5 -2
- reflex/components/radix/themes/layout/base.pyi +5 -3
- reflex/components/radix/themes/layout/box.py +1 -2
- reflex/components/radix/themes/layout/box.pyi +1 -3
- reflex/components/radix/themes/layout/center.pyi +0 -1
- reflex/components/radix/themes/layout/container.py +1 -2
- reflex/components/radix/themes/layout/container.pyi +1 -3
- reflex/components/radix/themes/layout/flex.py +6 -2
- reflex/components/radix/themes/layout/flex.pyi +1 -3
- reflex/components/radix/themes/layout/grid.py +6 -2
- reflex/components/radix/themes/layout/grid.pyi +1 -3
- reflex/components/radix/themes/layout/list.py +2 -1
- reflex/components/radix/themes/layout/list.pyi +0 -5
- reflex/components/radix/themes/layout/section.py +1 -2
- reflex/components/radix/themes/layout/section.pyi +1 -3
- reflex/components/radix/themes/layout/spacer.pyi +0 -1
- reflex/components/radix/themes/layout/stack.py +1 -1
- reflex/components/radix/themes/layout/stack.pyi +0 -3
- reflex/components/radix/themes/typography/blockquote.py +1 -1
- reflex/components/radix/themes/typography/blockquote.pyi +1 -3
- reflex/components/radix/themes/typography/code.py +5 -1
- reflex/components/radix/themes/typography/code.pyi +1 -3
- reflex/components/radix/themes/typography/heading.py +1 -1
- reflex/components/radix/themes/typography/heading.pyi +1 -3
- reflex/components/radix/themes/typography/link.py +3 -2
- reflex/components/radix/themes/typography/link.pyi +1 -3
- reflex/components/radix/themes/typography/text.py +1 -1
- reflex/components/radix/themes/typography/text.pyi +1 -9
- reflex/components/react_player/audio.py +0 -2
- reflex/components/react_player/audio.pyi +0 -3
- reflex/components/react_player/react_player.pyi +0 -1
- reflex/components/react_player/video.py +0 -2
- reflex/components/react_player/video.pyi +0 -3
- reflex/components/recharts/__init__.py +1 -1
- reflex/components/recharts/__init__.pyi +1 -1
- reflex/components/recharts/cartesian.py +20 -25
- reflex/components/recharts/cartesian.pyi +20 -37
- reflex/components/recharts/charts.py +2 -1
- reflex/components/recharts/charts.pyi +0 -12
- reflex/components/recharts/general.pyi +0 -6
- reflex/components/recharts/polar.py +5 -4
- reflex/components/recharts/polar.pyi +4 -10
- reflex/components/recharts/recharts.py +12 -10
- reflex/components/recharts/recharts.pyi +10 -11
- reflex/components/sonner/toast.py +2 -2
- reflex/components/sonner/toast.pyi +0 -2
- reflex/components/suneditor/editor.py +2 -1
- reflex/components/suneditor/editor.pyi +0 -1
- reflex/components/tags/iter_tag.py +4 -2
- reflex/config.py +41 -615
- reflex/constants/base.py +6 -6
- reflex/constants/compiler.py +8 -6
- reflex/constants/installer.py +25 -16
- reflex/custom_components/custom_components.py +1 -2
- reflex/environment.py +606 -0
- reflex/event.py +58 -60
- reflex/experimental/__init__.py +2 -2
- reflex/experimental/client_state.py +9 -4
- reflex/experimental/layout.pyi +0 -5
- reflex/istate/manager.py +17 -20
- reflex/istate/proxy.py +19 -12
- reflex/model.py +8 -5
- reflex/plugins/base.py +8 -0
- reflex/plugins/tailwind_v3.py +8 -0
- reflex/plugins/tailwind_v4.py +8 -0
- reflex/reflex.py +11 -12
- reflex/route.py +7 -9
- reflex/state.py +67 -71
- reflex/style.py +3 -1
- reflex/testing.py +49 -30
- reflex/utils/build.py +2 -1
- reflex/utils/console.py +70 -17
- reflex/utils/exec.py +113 -39
- reflex/utils/export.py +2 -1
- reflex/utils/format.py +21 -24
- reflex/utils/imports.py +4 -3
- reflex/utils/lazy_loader.py +3 -3
- reflex/utils/misc.py +2 -1
- reflex/utils/net.py +2 -2
- reflex/utils/path_ops.py +4 -2
- reflex/utils/prerequisites.py +69 -39
- reflex/utils/processes.py +5 -7
- reflex/utils/pyi_generator.py +46 -41
- reflex/utils/redir.py +1 -1
- reflex/utils/registry.py +1 -1
- reflex/utils/serializers.py +4 -4
- reflex/utils/telemetry.py +36 -3
- reflex/utils/types.py +16 -13
- reflex/vars/base.py +96 -109
- reflex/vars/datetime.py +2 -1
- reflex/vars/dep_tracking.py +19 -28
- reflex/vars/number.py +6 -7
- reflex/vars/object.py +5 -6
- reflex/vars/sequence.py +11 -11
- {reflex-0.7.13a2.dist-info → reflex-0.7.14.dist-info}/METADATA +1 -1
- reflex-0.7.14.dist-info/RECORD +408 -0
- reflex-0.7.13a2.dist-info/RECORD +0 -407
- {reflex-0.7.13a2.dist-info → reflex-0.7.14.dist-info}/WHEEL +0 -0
- {reflex-0.7.13a2.dist-info → reflex-0.7.14.dist-info}/entry_points.txt +0 -0
- {reflex-0.7.13a2.dist-info → reflex-0.7.14.dist-info}/licenses/LICENSE +0 -0
reflex/app.py
CHANGED
|
@@ -68,7 +68,8 @@ from reflex.components.core.sticky import sticky
|
|
|
68
68
|
from reflex.components.core.upload import Upload, get_upload_dir
|
|
69
69
|
from reflex.components.radix import themes
|
|
70
70
|
from reflex.components.sonner.toast import toast
|
|
71
|
-
from reflex.config import
|
|
71
|
+
from reflex.config import get_config
|
|
72
|
+
from reflex.environment import ExecutorType, environment
|
|
72
73
|
from reflex.event import (
|
|
73
74
|
_EVENT_FIELDS,
|
|
74
75
|
Event,
|
|
@@ -229,8 +230,6 @@ def default_error_boundary(*children: Component) -> Component:
|
|
|
229
230
|
class OverlayFragment(Fragment):
|
|
230
231
|
"""Alias for Fragment, used to wrap the overlay_component."""
|
|
231
232
|
|
|
232
|
-
pass
|
|
233
|
-
|
|
234
233
|
|
|
235
234
|
@dataclasses.dataclass(frozen=True)
|
|
236
235
|
class UploadFile(StarletteUploadFile):
|
|
@@ -262,6 +261,7 @@ class UploadFile(StarletteUploadFile):
|
|
|
262
261
|
"""
|
|
263
262
|
if self.path:
|
|
264
263
|
return self.path.name
|
|
264
|
+
return None
|
|
265
265
|
|
|
266
266
|
@property
|
|
267
267
|
def filename(self) -> str | None:
|
|
@@ -481,9 +481,8 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
481
481
|
# Special case to allow test cases have multiple subclasses of rx.BaseState.
|
|
482
482
|
if not is_testing_env() and BaseState.__subclasses__() != [State]:
|
|
483
483
|
# Only rx.State is allowed as Base State subclass.
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
)
|
|
484
|
+
msg = "rx.BaseState cannot be subclassed directly. Use rx.State instead"
|
|
485
|
+
raise ValueError(msg)
|
|
487
486
|
|
|
488
487
|
get_config(reload=True)
|
|
489
488
|
|
|
@@ -552,9 +551,8 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
552
551
|
transports=["websocket"],
|
|
553
552
|
)
|
|
554
553
|
elif getattr(self.sio, "async_mode", "") != "asgi":
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
)
|
|
554
|
+
msg = f"Custom `sio` must use `async_mode='asgi'`, not '{self.sio.async_mode}'."
|
|
555
|
+
raise RuntimeError(msg)
|
|
558
556
|
|
|
559
557
|
# Create the socket app. Note event endpoint constant replaces the default 'socket.io' path.
|
|
560
558
|
socket_app = EngineIOApp(self.sio, socketio_path="")
|
|
@@ -633,7 +631,8 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
633
631
|
compile_future.result()
|
|
634
632
|
|
|
635
633
|
if not self._api:
|
|
636
|
-
|
|
634
|
+
msg = "The app has not been initialized."
|
|
635
|
+
raise ValueError(msg)
|
|
637
636
|
|
|
638
637
|
if self._cached_fastapi_app is not None:
|
|
639
638
|
asgi_app = self._cached_fastapi_app
|
|
@@ -741,7 +740,8 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
741
740
|
ValueError: if the state has not been initialized.
|
|
742
741
|
"""
|
|
743
742
|
if self._state_manager is None:
|
|
744
|
-
|
|
743
|
+
msg = "The state manager has not been initialized."
|
|
744
|
+
raise ValueError(msg)
|
|
745
745
|
return self._state_manager
|
|
746
746
|
|
|
747
747
|
@staticmethod
|
|
@@ -791,9 +791,8 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
791
791
|
# If the route is not set, get it from the callable.
|
|
792
792
|
if route is None:
|
|
793
793
|
if not isinstance(component, Callable):
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
)
|
|
794
|
+
msg = "Route must be set if component is not a callable."
|
|
795
|
+
raise exceptions.RouteValueError(msg)
|
|
797
796
|
# Format the route.
|
|
798
797
|
route = format.format_route(component.__name__)
|
|
799
798
|
else:
|
|
@@ -808,9 +807,8 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
808
807
|
image = image or constants.Page404.IMAGE
|
|
809
808
|
else:
|
|
810
809
|
if component is None:
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
)
|
|
810
|
+
msg = "Component must be set for a non-404 page."
|
|
811
|
+
raise exceptions.PageValueError(msg)
|
|
814
812
|
|
|
815
813
|
# Check if the route given is valid
|
|
816
814
|
verify_route_validity(route)
|
|
@@ -841,11 +839,12 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
841
839
|
else f"`{route}`"
|
|
842
840
|
)
|
|
843
841
|
existing_component = self._unevaluated_pages[route].component
|
|
844
|
-
|
|
842
|
+
msg = (
|
|
845
843
|
f"Tried to add page {readable_name_from_component(component)} with route {route_name} but "
|
|
846
844
|
f"page {readable_name_from_component(existing_component)} with the same route already exists. "
|
|
847
845
|
"Make sure you do not have two pages with the same route."
|
|
848
846
|
)
|
|
847
|
+
raise exceptions.RouteValueError(msg)
|
|
849
848
|
|
|
850
849
|
# Setup dynamic args for the route.
|
|
851
850
|
# this state assignment is only required for tests using the deprecated state kwarg for App
|
|
@@ -930,10 +929,9 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
930
929
|
):
|
|
931
930
|
if rw in segments and r != nr:
|
|
932
931
|
# If the slugs in the segments of both routes are not the same, then the route is invalid
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
elif rw not in segments and r != nr:
|
|
932
|
+
msg = f"You cannot use different slug names for the same dynamic path in {route} and {new_route} ('{r}' != '{nr}')"
|
|
933
|
+
raise RouteValueError(msg)
|
|
934
|
+
if rw not in segments and r != nr:
|
|
937
935
|
# if the section being compared in both routes is not a dynamic segment(i.e not wrapped in brackets)
|
|
938
936
|
# then we are guaranteed that the route is valid and there's no need checking the rest.
|
|
939
937
|
# eg. /posts/[id]/info/[slug1] and /posts/[id]/info1/[slug1] is always going to be valid since
|
|
@@ -1019,11 +1017,13 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1019
1017
|
Example:
|
|
1020
1018
|
>>> _get_frontend_packages({"react": "16.14.0", "react-dom": "16.14.0"})
|
|
1021
1019
|
"""
|
|
1020
|
+
dependencies = constants.PackageJson.DEPENDENCIES
|
|
1021
|
+
dev_dependencies = constants.PackageJson.DEV_DEPENDENCIES
|
|
1022
1022
|
page_imports = {
|
|
1023
1023
|
i
|
|
1024
1024
|
for i, tags in imports.items()
|
|
1025
|
-
if i not in
|
|
1026
|
-
and i not in
|
|
1025
|
+
if i not in dependencies
|
|
1026
|
+
and i not in dev_dependencies
|
|
1027
1027
|
and not any(i.startswith(prefix) for prefix in ["/", "$/", ".", "next/"])
|
|
1028
1028
|
and i != ""
|
|
1029
1029
|
and any(tag.install for tag in tags)
|
|
@@ -1086,9 +1086,7 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1086
1086
|
return component
|
|
1087
1087
|
|
|
1088
1088
|
# recreate OverlayFragment with overlay_component as first child
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
return component
|
|
1089
|
+
return OverlayFragment.create(overlay_component, *children)
|
|
1092
1090
|
|
|
1093
1091
|
def _setup_overlay_component(self):
|
|
1094
1092
|
"""If a State is not used and no overlay_component is specified, do not render the connection modal."""
|
|
@@ -1150,9 +1148,8 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1150
1148
|
)
|
|
1151
1149
|
for dep in dep_set:
|
|
1152
1150
|
if dep not in state_cls.vars and dep not in state_cls.backend_vars:
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
)
|
|
1151
|
+
msg = f"ComputedVar {var._js_expr} on state {state.__name__} has an invalid dependency {state_name}.{dep}"
|
|
1152
|
+
raise exceptions.VarDependencyError(msg)
|
|
1156
1153
|
|
|
1157
1154
|
for substate in state.class_subclasses:
|
|
1158
1155
|
self._validate_var_dependencies(substate)
|
|
@@ -1296,15 +1293,6 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1296
1293
|
# Track imports found.
|
|
1297
1294
|
all_imports = {}
|
|
1298
1295
|
|
|
1299
|
-
# This has to happen before compiling stateful components as that
|
|
1300
|
-
# prevents recursive functions from reaching all components.
|
|
1301
|
-
for component in self._pages.values():
|
|
1302
|
-
# Add component._get_all_imports() to all_imports.
|
|
1303
|
-
all_imports.update(component._get_all_imports())
|
|
1304
|
-
|
|
1305
|
-
# Add the app wrappers from this component.
|
|
1306
|
-
app_wrappers.update(component._get_all_app_wrap_components())
|
|
1307
|
-
|
|
1308
1296
|
if (toaster := self.toaster) is not None:
|
|
1309
1297
|
from reflex.components.component import memo
|
|
1310
1298
|
|
|
@@ -1322,6 +1310,25 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1322
1310
|
if component is not None:
|
|
1323
1311
|
app_wrappers[key] = component
|
|
1324
1312
|
|
|
1313
|
+
# Compile custom components.
|
|
1314
|
+
(
|
|
1315
|
+
custom_components_output,
|
|
1316
|
+
custom_components_result,
|
|
1317
|
+
custom_components_imports,
|
|
1318
|
+
) = compiler.compile_components(dict.fromkeys(CUSTOM_COMPONENTS.values()))
|
|
1319
|
+
compile_results.append((custom_components_output, custom_components_result))
|
|
1320
|
+
all_imports.update(custom_components_imports)
|
|
1321
|
+
progress.advance(task)
|
|
1322
|
+
|
|
1323
|
+
# This has to happen before compiling stateful components as that
|
|
1324
|
+
# prevents recursive functions from reaching all components.
|
|
1325
|
+
for component in self._pages.values():
|
|
1326
|
+
# Add component._get_all_imports() to all_imports.
|
|
1327
|
+
all_imports.update(component._get_all_imports())
|
|
1328
|
+
|
|
1329
|
+
# Add the app wrappers from this component.
|
|
1330
|
+
app_wrappers.update(component._get_all_app_wrap_components())
|
|
1331
|
+
|
|
1325
1332
|
if self.error_boundary:
|
|
1326
1333
|
from reflex.compiler.compiler import into_component
|
|
1327
1334
|
|
|
@@ -1344,10 +1351,11 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1344
1351
|
|
|
1345
1352
|
# Catch "static" apps (that do not define a rx.State subclass) which are trying to access rx.State.
|
|
1346
1353
|
if code_uses_state_contexts(stateful_components_code) and self._state is None:
|
|
1347
|
-
|
|
1354
|
+
msg = (
|
|
1348
1355
|
"To access rx.State in frontend components, at least one "
|
|
1349
1356
|
"subclass of rx.State must be defined in the app."
|
|
1350
1357
|
)
|
|
1358
|
+
raise ReflexRuntimeError(msg)
|
|
1351
1359
|
compile_results.append((stateful_components_path, stateful_components_code))
|
|
1352
1360
|
|
|
1353
1361
|
progress.advance(task)
|
|
@@ -1467,16 +1475,6 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1467
1475
|
)
|
|
1468
1476
|
progress.advance(task)
|
|
1469
1477
|
|
|
1470
|
-
# Compile custom components.
|
|
1471
|
-
(
|
|
1472
|
-
custom_components_output,
|
|
1473
|
-
custom_components_result,
|
|
1474
|
-
custom_components_imports,
|
|
1475
|
-
) = compiler.compile_components(dict.fromkeys(CUSTOM_COMPONENTS.values()))
|
|
1476
|
-
compile_results.append((custom_components_output, custom_components_result))
|
|
1477
|
-
all_imports.update(custom_components_imports)
|
|
1478
|
-
|
|
1479
|
-
progress.advance(task)
|
|
1480
1478
|
progress.stop()
|
|
1481
1479
|
|
|
1482
1480
|
if dry_run:
|
|
@@ -1541,9 +1539,8 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1541
1539
|
if path.exists():
|
|
1542
1540
|
file_content = path.read_text()
|
|
1543
1541
|
else:
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
)
|
|
1542
|
+
msg = f"Plugin {plugin_name} is trying to modify {path} but it does not exist."
|
|
1543
|
+
raise FileNotFoundError(msg)
|
|
1547
1544
|
output_mapping[path] = modify_fn(file_content)
|
|
1548
1545
|
|
|
1549
1546
|
with console.timing("Write to Disk"):
|
|
@@ -1586,7 +1583,8 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1586
1583
|
RuntimeError: If the app has not been initialized yet.
|
|
1587
1584
|
"""
|
|
1588
1585
|
if self.event_namespace is None:
|
|
1589
|
-
|
|
1586
|
+
msg = "App has not been initialized yet."
|
|
1587
|
+
raise RuntimeError(msg)
|
|
1590
1588
|
|
|
1591
1589
|
# Get exclusive access to the state.
|
|
1592
1590
|
async with self.state_manager.modify_state(token) as state:
|
|
@@ -1625,7 +1623,8 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1625
1623
|
RuntimeError: If the app has not been initialized yet.
|
|
1626
1624
|
"""
|
|
1627
1625
|
if self.event_namespace is None:
|
|
1628
|
-
|
|
1626
|
+
msg = "App has not been initialized yet."
|
|
1627
|
+
raise RuntimeError(msg)
|
|
1629
1628
|
|
|
1630
1629
|
# Process the event.
|
|
1631
1630
|
async for update in state._process_event(
|
|
@@ -1676,20 +1675,17 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1676
1675
|
_fn_name = type(handler_fn).__name__
|
|
1677
1676
|
|
|
1678
1677
|
if isinstance(handler_fn, functools.partial):
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
)
|
|
1678
|
+
msg = f"Provided custom {handler_domain} exception handler `{_fn_name}` is a partial function. Please provide a named function instead."
|
|
1679
|
+
raise ValueError(msg)
|
|
1682
1680
|
|
|
1683
1681
|
if not callable(handler_fn):
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
)
|
|
1682
|
+
msg = f"Provided custom {handler_domain} exception handler `{_fn_name}` is not a function."
|
|
1683
|
+
raise ValueError(msg)
|
|
1687
1684
|
|
|
1688
1685
|
# Allow named functions only as lambda functions cannot be introspected
|
|
1689
1686
|
if _fn_name == "<lambda>":
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
)
|
|
1687
|
+
msg = f"Provided custom {handler_domain} exception handler `{_fn_name}` is a lambda function. Please use a named function instead."
|
|
1688
|
+
raise ValueError(msg)
|
|
1693
1689
|
|
|
1694
1690
|
# Check if the function has the necessary annotations and types in the right order
|
|
1695
1691
|
argspec = inspect.getfullargspec(handler_fn)
|
|
@@ -1701,22 +1697,21 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1701
1697
|
|
|
1702
1698
|
for required_arg_index, required_arg in enumerate(handler_spec):
|
|
1703
1699
|
if required_arg not in arg_annotations:
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
not list(arg_annotations.keys())[required_arg_index] == required_arg
|
|
1709
|
-
):
|
|
1710
|
-
raise ValueError(
|
|
1700
|
+
msg = f"Provided custom {handler_domain} exception handler `{_fn_name}` does not take the required argument `{required_arg}`"
|
|
1701
|
+
raise ValueError(msg)
|
|
1702
|
+
if list(arg_annotations.keys())[required_arg_index] != required_arg:
|
|
1703
|
+
msg = (
|
|
1711
1704
|
f"Provided custom {handler_domain} exception handler `{_fn_name}` has the wrong argument order."
|
|
1712
1705
|
f"Expected `{required_arg}` as the {required_arg_index + 1} argument but got `{list(arg_annotations.keys())[required_arg_index]}`"
|
|
1713
1706
|
)
|
|
1707
|
+
raise ValueError(msg)
|
|
1714
1708
|
|
|
1715
1709
|
if not issubclass(arg_annotations[required_arg], Exception):
|
|
1716
|
-
|
|
1710
|
+
msg = (
|
|
1717
1711
|
f"Provided custom {handler_domain} exception handler `{_fn_name}` has the wrong type for {required_arg} argument."
|
|
1718
1712
|
f"Expected to be `Exception` but got `{arg_annotations[required_arg]}`"
|
|
1719
1713
|
)
|
|
1714
|
+
raise ValueError(msg)
|
|
1720
1715
|
|
|
1721
1716
|
# Check if the return type is valid for backend exception handler
|
|
1722
1717
|
if handler_domain == "backend":
|
|
@@ -1736,10 +1731,11 @@ class App(MiddlewareMixin, LifespanMixin):
|
|
|
1736
1731
|
)
|
|
1737
1732
|
|
|
1738
1733
|
if not valid:
|
|
1739
|
-
|
|
1734
|
+
msg = (
|
|
1740
1735
|
f"Provided custom {handler_domain} exception handler `{_fn_name}` has the wrong return type."
|
|
1741
1736
|
f"Expected `EventSpec | list[EventSpec] | None` but got `{return_type}`"
|
|
1742
1737
|
)
|
|
1738
|
+
raise ValueError(msg)
|
|
1743
1739
|
|
|
1744
1740
|
|
|
1745
1741
|
async def process(
|
|
@@ -1908,7 +1904,8 @@ def upload(app: App):
|
|
|
1908
1904
|
return Response() # user cancelled
|
|
1909
1905
|
files = files.getlist("files")
|
|
1910
1906
|
if not files:
|
|
1911
|
-
|
|
1907
|
+
msg = "No files were uploaded."
|
|
1908
|
+
raise UploadValueError(msg)
|
|
1912
1909
|
|
|
1913
1910
|
token = request.headers.get("reflex-client-token")
|
|
1914
1911
|
handler = request.headers.get("reflex-event-handler")
|
|
@@ -1935,9 +1932,8 @@ def upload(app: App):
|
|
|
1935
1932
|
# check if there exists any handler args with annotation, list[UploadFile]
|
|
1936
1933
|
if isinstance(func, EventHandler):
|
|
1937
1934
|
if func.is_background:
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
)
|
|
1935
|
+
msg = f"@rx.event(background=True) is not supported for upload handler `{handler}`."
|
|
1936
|
+
raise UploadTypeError(msg)
|
|
1941
1937
|
func = func.fn
|
|
1942
1938
|
if isinstance(func, functools.partial):
|
|
1943
1939
|
func = func.func
|
|
@@ -1950,10 +1946,11 @@ def upload(app: App):
|
|
|
1950
1946
|
break
|
|
1951
1947
|
|
|
1952
1948
|
if not handler_upload_param:
|
|
1953
|
-
|
|
1949
|
+
msg = (
|
|
1954
1950
|
f"`{handler}` handler should have a parameter annotated as "
|
|
1955
1951
|
"list[rx.UploadFile]"
|
|
1956
1952
|
)
|
|
1953
|
+
raise UploadValueError(msg)
|
|
1957
1954
|
|
|
1958
1955
|
# Make a copy of the files as they are closed after the request.
|
|
1959
1956
|
# This behaviour changed from fastapi 0.103.0 to 0.103.1 as the
|
|
@@ -2096,32 +2093,31 @@ class EventNamespace(AsyncNamespace):
|
|
|
2096
2093
|
try:
|
|
2097
2094
|
fields = json.loads(fields)
|
|
2098
2095
|
except json.JSONDecodeError as ex:
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
) from ex
|
|
2096
|
+
msg = f"Failed to deserialize event data: {fields}."
|
|
2097
|
+
raise exceptions.EventDeserializationError(msg) from ex
|
|
2102
2098
|
|
|
2103
2099
|
if not isinstance(fields, dict):
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
)
|
|
2100
|
+
msg = f"Event data must be a dictionary, but received {fields} of type {type(fields)}."
|
|
2101
|
+
raise exceptions.EventDeserializationError(msg)
|
|
2107
2102
|
|
|
2108
2103
|
try:
|
|
2109
2104
|
# Get the event.
|
|
2110
2105
|
event = Event(**{k: v for k, v in fields.items() if k in _EVENT_FIELDS})
|
|
2111
2106
|
except (TypeError, ValueError) as ex:
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
) from ex
|
|
2107
|
+
msg = f"Failed to deserialize event data: {fields}."
|
|
2108
|
+
raise exceptions.EventDeserializationError(msg) from ex
|
|
2115
2109
|
|
|
2116
2110
|
self.token_to_sid[event.token] = sid
|
|
2117
2111
|
self.sid_to_token[sid] = event.token
|
|
2118
2112
|
|
|
2119
2113
|
# Get the event environment.
|
|
2120
2114
|
if self.app.sio is None:
|
|
2121
|
-
|
|
2115
|
+
msg = "Socket.IO is not initialized."
|
|
2116
|
+
raise RuntimeError(msg)
|
|
2122
2117
|
environ = self.app.sio.get_environ(sid, self.namespace)
|
|
2123
2118
|
if environ is None:
|
|
2124
|
-
|
|
2119
|
+
msg = "Socket.IO environ is not initialized."
|
|
2120
|
+
raise RuntimeError(msg)
|
|
2125
2121
|
|
|
2126
2122
|
# Get the client headers.
|
|
2127
2123
|
headers = {
|
reflex/app_mixins/lifespan.py
CHANGED
|
@@ -67,9 +67,8 @@ class LifespanMixin(AppMixin):
|
|
|
67
67
|
InvalidLifespanTaskTypeError: If the task is a generator function.
|
|
68
68
|
"""
|
|
69
69
|
if inspect.isgeneratorfunction(task) or inspect.isasyncgenfunction(task):
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
)
|
|
70
|
+
msg = f"Task {task.__name__} of type generator must be decorated with contextlib.asynccontextmanager."
|
|
71
|
+
raise InvalidLifespanTaskTypeError(msg)
|
|
73
72
|
|
|
74
73
|
if task_kwargs:
|
|
75
74
|
original_task = task
|
reflex/app_mixins/middleware.py
CHANGED
reflex/app_mixins/mixin.py
CHANGED
reflex/assets.py
CHANGED
|
@@ -4,7 +4,7 @@ import inspect
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
|
|
6
6
|
from reflex import constants
|
|
7
|
-
from reflex.
|
|
7
|
+
from reflex.environment import EnvironmentVariables
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def asset(
|
|
@@ -58,9 +58,11 @@ def asset(
|
|
|
58
58
|
cwd = Path.cwd()
|
|
59
59
|
src_file_local = cwd / assets / path
|
|
60
60
|
if subfolder is not None:
|
|
61
|
-
|
|
61
|
+
msg = "Subfolder is not supported for local assets."
|
|
62
|
+
raise ValueError(msg)
|
|
62
63
|
if not backend_only and not src_file_local.exists():
|
|
63
|
-
|
|
64
|
+
msg = f"File not found: {src_file_local}"
|
|
65
|
+
raise FileNotFoundError(msg)
|
|
64
66
|
return f"/{path}"
|
|
65
67
|
|
|
66
68
|
# Shared asset handling
|
|
@@ -73,7 +75,8 @@ def asset(
|
|
|
73
75
|
external = constants.Dirs.EXTERNAL_APP_ASSETS
|
|
74
76
|
src_file_shared = Path(calling_file).parent / path
|
|
75
77
|
if not src_file_shared.exists():
|
|
76
|
-
|
|
78
|
+
msg = f"File not found: {src_file_shared}"
|
|
79
|
+
raise FileNotFoundError(msg)
|
|
77
80
|
|
|
78
81
|
caller_module_path = module.__name__.replace(".", "/")
|
|
79
82
|
subfolder = f"{caller_module_path}/{subfolder}" if subfolder else caller_module_path
|
reflex/base.py
CHANGED
|
@@ -30,10 +30,11 @@ def validate_field_name(bases: list[type[BaseModel]], field_name: str) -> None:
|
|
|
30
30
|
if not reload and getattr(base, field_name, None):
|
|
31
31
|
pass
|
|
32
32
|
except TypeError as te:
|
|
33
|
-
|
|
33
|
+
msg = (
|
|
34
34
|
f'State var "{field_name}" in {base} has been shadowed by a substate var; '
|
|
35
35
|
f'use a different field name instead".'
|
|
36
|
-
)
|
|
36
|
+
)
|
|
37
|
+
raise VarNameError(msg) from te
|
|
37
38
|
|
|
38
39
|
|
|
39
40
|
# monkeypatch pydantic validate_field_name method to skip validating
|