reflex 0.8.12a2__py3-none-any.whl → 0.8.13__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/app.py +7 -2
- reflex/components/core/upload.pyi +8 -0
- reflex/components/react_player/audio.pyi +23 -46
- reflex/components/react_player/react_player.py +159 -19
- reflex/components/react_player/react_player.pyi +40 -45
- reflex/components/react_player/video.pyi +23 -46
- reflex/components/recharts/recharts.py +2 -2
- reflex/constants/colors.py +3 -1
- reflex/constants/installer.py +2 -2
- reflex/environment.py +3 -0
- reflex/plugins/shared_tailwind.py +1 -1
- reflex/reflex.py +36 -3
- reflex/state.py +13 -3
- reflex/utils/build.py +10 -4
- reflex/utils/exec.py +11 -0
- reflex/utils/export.py +3 -1
- reflex/utils/prerequisites.py +82 -7
- reflex/utils/serializers.py +8 -4
- reflex/vars/__init__.py +56 -26
- reflex/vars/base.py +20 -113
- reflex/vars/color.py +214 -0
- reflex/vars/number.py +2 -2
- reflex/vars/sequence.py +0 -136
- {reflex-0.8.12a2.dist-info → reflex-0.8.13.dist-info}/METADATA +1 -1
- {reflex-0.8.12a2.dist-info → reflex-0.8.13.dist-info}/RECORD +28 -27
- {reflex-0.8.12a2.dist-info → reflex-0.8.13.dist-info}/WHEEL +0 -0
- {reflex-0.8.12a2.dist-info → reflex-0.8.13.dist-info}/entry_points.txt +0 -0
- {reflex-0.8.12a2.dist-info → reflex-0.8.13.dist-info}/licenses/LICENSE +0 -0
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
from collections.abc import Mapping, Sequence
|
|
7
7
|
from typing import Any
|
|
8
8
|
|
|
9
|
-
import reflex
|
|
10
9
|
from reflex.components.core.breakpoints import Breakpoints
|
|
11
10
|
from reflex.components.react_player.react_player import ReactPlayer
|
|
12
11
|
from reflex.event import EventType, PointerEventInfo
|
|
@@ -17,13 +16,18 @@ class Video(ReactPlayer):
|
|
|
17
16
|
def create(
|
|
18
17
|
cls,
|
|
19
18
|
*children,
|
|
20
|
-
|
|
19
|
+
src: Var[list[dict[str, str]] | list[str] | str]
|
|
20
|
+
| list[dict[str, str]]
|
|
21
|
+
| list[str]
|
|
22
|
+
| str
|
|
23
|
+
| None = None,
|
|
21
24
|
playing: Var[bool] | bool | None = None,
|
|
22
25
|
loop: Var[bool] | bool | None = None,
|
|
23
26
|
controls: Var[bool] | bool | None = None,
|
|
24
27
|
light: Var[bool] | bool | None = None,
|
|
25
28
|
volume: Var[float] | float | None = None,
|
|
26
29
|
muted: Var[bool] | bool | None = None,
|
|
30
|
+
config: Var[dict[str, Any]] | dict[str, Any] | None = None,
|
|
27
31
|
style: Sequence[Mapping[str, Any]]
|
|
28
32
|
| Mapping[str, Any]
|
|
29
33
|
| Var[Mapping[str, Any]]
|
|
@@ -35,18 +39,16 @@ class Video(ReactPlayer):
|
|
|
35
39
|
class_name: Any | None = None,
|
|
36
40
|
custom_attrs: dict[str, Var | Any] | None = None,
|
|
37
41
|
on_blur: EventType[()] | None = None,
|
|
38
|
-
on_buffer: EventType[()] | None = None,
|
|
39
|
-
on_buffer_end: EventType[()] | None = None,
|
|
40
42
|
on_click: EventType[()] | EventType[PointerEventInfo] | None = None,
|
|
41
43
|
on_click_preview: EventType[()] | None = None,
|
|
42
44
|
on_context_menu: EventType[()] | EventType[PointerEventInfo] | None = None,
|
|
43
|
-
on_disable_pip: EventType[()] | None = None,
|
|
44
45
|
on_double_click: EventType[()] | EventType[PointerEventInfo] | None = None,
|
|
45
|
-
|
|
46
|
-
on_enable_pip: EventType[()] | None = None,
|
|
46
|
+
on_duration_change: EventType[Any] | None = None,
|
|
47
47
|
on_ended: EventType[()] | None = None,
|
|
48
|
+
on_enter_picture_in_picture: EventType[()] | None = None,
|
|
48
49
|
on_error: EventType[()] | None = None,
|
|
49
50
|
on_focus: EventType[()] | None = None,
|
|
51
|
+
on_leave_picture_in_picture: EventType[()] | None = None,
|
|
50
52
|
on_mount: EventType[()] | None = None,
|
|
51
53
|
on_mouse_down: EventType[()] | None = None,
|
|
52
54
|
on_mouse_enter: EventType[()] | None = None,
|
|
@@ -57,54 +59,29 @@ class Video(ReactPlayer):
|
|
|
57
59
|
on_mouse_up: EventType[()] | None = None,
|
|
58
60
|
on_pause: EventType[()] | None = None,
|
|
59
61
|
on_play: EventType[()] | None = None,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
| EventType[reflex.components.react_player.react_player.Progress]
|
|
64
|
-
| None = None,
|
|
62
|
+
on_playing: EventType[()] | None = None,
|
|
63
|
+
on_progress: EventType[Any] | None = None,
|
|
64
|
+
on_rate_change: EventType[Any] | None = None,
|
|
65
65
|
on_ready: EventType[()] | None = None,
|
|
66
66
|
on_scroll: EventType[()] | None = None,
|
|
67
67
|
on_scroll_end: EventType[()] | None = None,
|
|
68
|
-
|
|
68
|
+
on_seeked: EventType[Any] | None = None,
|
|
69
|
+
on_seeking: EventType[()] | None = None,
|
|
69
70
|
on_start: EventType[()] | None = None,
|
|
71
|
+
on_time_update: EventType[Any] | None = None,
|
|
70
72
|
on_unmount: EventType[()] | None = None,
|
|
73
|
+
on_waiting: EventType[()] | None = None,
|
|
71
74
|
**props,
|
|
72
75
|
) -> Video:
|
|
73
|
-
"""Create
|
|
76
|
+
"""Create a component.
|
|
74
77
|
|
|
75
78
|
Args:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
playing: Set to true or false to pause or play the media
|
|
79
|
-
loop: Set to true or false to loop the media
|
|
80
|
-
controls: Set to true or false to display native player controls.
|
|
81
|
-
light: Set to true to show just the video thumbnail, which loads the full player on click
|
|
82
|
-
volume: Set the volume of the player, between 0 and 1
|
|
83
|
-
muted: Mutes the player
|
|
84
|
-
on_ready: Called when media is loaded and ready to play. If playing is set to true, media will play immediately.
|
|
85
|
-
on_start: Called when media starts playing.
|
|
86
|
-
on_play: Called when media starts or resumes playing after pausing or buffering.
|
|
87
|
-
on_progress: Callback containing played and loaded progress as a fraction, and playedSeconds and loadedSeconds in seconds. eg { played: 0.12, playedSeconds: 11.3, loaded: 0.34, loadedSeconds: 16.7 }
|
|
88
|
-
on_duration: Callback containing duration of the media, in seconds.
|
|
89
|
-
on_pause: Called when media is paused.
|
|
90
|
-
on_buffer: Called when media starts buffering.
|
|
91
|
-
on_buffer_end: Called when media has finished buffering. Works for files, YouTube and Facebook.
|
|
92
|
-
on_seek: Called when media seeks with seconds parameter.
|
|
93
|
-
on_playback_rate_change: Called when playback rate of the player changed. Only supported by YouTube, Vimeo (if enabled), Wistia, and file paths.
|
|
94
|
-
on_playback_quality_change: Called when playback quality of the player changed. Only supported by YouTube (if enabled).
|
|
95
|
-
on_ended: Called when media finishes playing. Does not fire when loop is set to true.
|
|
96
|
-
on_error: Called when an error occurs whilst attempting to play media.
|
|
97
|
-
on_click_preview: Called when user clicks the light mode preview.
|
|
98
|
-
on_enable_pip: Called when picture-in-picture mode is enabled.
|
|
99
|
-
on_disable_pip: Called when picture-in-picture mode is disabled.
|
|
100
|
-
style: The style of the component.
|
|
101
|
-
key: A unique key for the component.
|
|
102
|
-
id: The id for the component.
|
|
103
|
-
ref: The Var to pass as the ref to the component.
|
|
104
|
-
class_name: The class name for the component.
|
|
105
|
-
custom_attrs: custom attribute
|
|
106
|
-
**props: The props of the component.
|
|
79
|
+
children: The children of the component.
|
|
80
|
+
props: The props of the component.
|
|
107
81
|
|
|
108
82
|
Returns:
|
|
109
|
-
The component.
|
|
83
|
+
The created component.
|
|
84
|
+
|
|
85
|
+
Raises:
|
|
86
|
+
ValueError: If both a deprecated prop and its replacement are both passed.
|
|
110
87
|
"""
|
|
@@ -8,7 +8,7 @@ from reflex.components.component import Component, MemoizationLeaf, NoSSRCompone
|
|
|
8
8
|
class Recharts(Component):
|
|
9
9
|
"""A component that wraps a recharts lib."""
|
|
10
10
|
|
|
11
|
-
library = "recharts@3.2.
|
|
11
|
+
library = "recharts@3.2.1"
|
|
12
12
|
|
|
13
13
|
def _get_style(self) -> dict:
|
|
14
14
|
return {"wrapperStyle": self.style}
|
|
@@ -17,7 +17,7 @@ class Recharts(Component):
|
|
|
17
17
|
class RechartsCharts(NoSSRComponent, MemoizationLeaf):
|
|
18
18
|
"""A component that wraps a recharts lib."""
|
|
19
19
|
|
|
20
|
-
library = "recharts@3.2.
|
|
20
|
+
library = "recharts@3.2.1"
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
LiteralAnimationEasing = Literal["ease", "ease-in", "ease-out", "ease-in-out", "linear"]
|
reflex/constants/colors.py
CHANGED
reflex/constants/installer.py
CHANGED
|
@@ -143,11 +143,11 @@ class PackageJson(SimpleNamespace):
|
|
|
143
143
|
"postcss-import": "16.1.1",
|
|
144
144
|
"@react-router/dev": _react_router_version,
|
|
145
145
|
"@react-router/fs-routes": _react_router_version,
|
|
146
|
-
"vite": "npm:rolldown-vite@7.1.
|
|
146
|
+
"vite": "npm:rolldown-vite@7.1.12",
|
|
147
147
|
}
|
|
148
148
|
OVERRIDES = {
|
|
149
149
|
# This should always match the `react` version in DEPENDENCIES for recharts compatibility.
|
|
150
150
|
"react-is": _react_version,
|
|
151
151
|
"cookie": "1.0.2",
|
|
152
|
-
"vite": "npm:rolldown-vite@7.1.
|
|
152
|
+
"vite": "npm:rolldown-vite@7.1.12",
|
|
153
153
|
}
|
reflex/environment.py
CHANGED
|
@@ -657,6 +657,9 @@ class EnvironmentVariables:
|
|
|
657
657
|
# Whether to force a full reload on changes.
|
|
658
658
|
VITE_FORCE_FULL_RELOAD: EnvVar[bool] = env_var(False)
|
|
659
659
|
|
|
660
|
+
# Whether to enable SSR for the frontend.
|
|
661
|
+
REFLEX_SSR: EnvVar[bool] = env_var(True)
|
|
662
|
+
|
|
660
663
|
|
|
661
664
|
environment = EnvironmentVariables()
|
|
662
665
|
|
reflex/reflex.py
CHANGED
|
@@ -204,7 +204,7 @@ def _run(
|
|
|
204
204
|
args = (frontend,)
|
|
205
205
|
kwargs = {
|
|
206
206
|
"check_if_schema_up_to_date": True,
|
|
207
|
-
"prerender_routes":
|
|
207
|
+
"prerender_routes": exec.should_prerender_routes(),
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
# Granian fails if the app is already imported.
|
|
@@ -216,9 +216,12 @@ def _run(
|
|
|
216
216
|
*args,
|
|
217
217
|
**kwargs,
|
|
218
218
|
)
|
|
219
|
-
compile_future.result()
|
|
219
|
+
return_result = compile_future.result()
|
|
220
220
|
else:
|
|
221
|
-
app_task(*args, **kwargs)
|
|
221
|
+
return_result = app_task(*args, **kwargs)
|
|
222
|
+
|
|
223
|
+
if not return_result:
|
|
224
|
+
raise SystemExit(1)
|
|
222
225
|
|
|
223
226
|
# Get the frontend and backend commands, based on the environment.
|
|
224
227
|
setup_frontend = frontend_cmd = backend_cmd = None
|
|
@@ -429,6 +432,14 @@ def compile(dry: bool, rich: bool):
|
|
|
429
432
|
type=click.Path(exists=True, path_type=Path, resolve_path=True),
|
|
430
433
|
help="Files or directories to exclude from the backend zip. Can be used multiple times.",
|
|
431
434
|
)
|
|
435
|
+
@click.option(
|
|
436
|
+
"--server-side-rendering/--no-server-side-rendering",
|
|
437
|
+
"--ssr/--no-ssr",
|
|
438
|
+
"ssr",
|
|
439
|
+
default=True,
|
|
440
|
+
is_flag=True,
|
|
441
|
+
help="Whether to enable server side rendering for the frontend.",
|
|
442
|
+
)
|
|
432
443
|
def export(
|
|
433
444
|
zip: bool,
|
|
434
445
|
frontend_only: bool,
|
|
@@ -437,11 +448,17 @@ def export(
|
|
|
437
448
|
upload_db_file: bool,
|
|
438
449
|
env: LITERAL_ENV,
|
|
439
450
|
backend_excluded_dirs: tuple[Path, ...] = (),
|
|
451
|
+
ssr: bool = True,
|
|
440
452
|
):
|
|
441
453
|
"""Export the app to a zip file."""
|
|
442
454
|
from reflex.utils import export as export_utils
|
|
443
455
|
from reflex.utils import prerequisites
|
|
444
456
|
|
|
457
|
+
if not environment.REFLEX_SSR.is_set():
|
|
458
|
+
environment.REFLEX_SSR.set(ssr)
|
|
459
|
+
elif environment.REFLEX_SSR.get() != ssr:
|
|
460
|
+
ssr = environment.REFLEX_SSR.get()
|
|
461
|
+
|
|
445
462
|
environment.REFLEX_COMPILE_CONTEXT.set(constants.CompileContext.EXPORT)
|
|
446
463
|
|
|
447
464
|
should_frontend_run, should_backend_run = prerequisites.check_running_mode(
|
|
@@ -464,6 +481,7 @@ def export(
|
|
|
464
481
|
env=constants.Env.DEV if env == constants.Env.DEV else constants.Env.PROD,
|
|
465
482
|
loglevel=config.loglevel.subprocess_level(),
|
|
466
483
|
backend_excluded_dirs=backend_excluded_dirs,
|
|
484
|
+
prerender_routes=ssr,
|
|
467
485
|
)
|
|
468
486
|
|
|
469
487
|
|
|
@@ -676,6 +694,14 @@ def makemigrations(message: str | None):
|
|
|
676
694
|
type=click.Path(exists=True, path_type=Path, resolve_path=True),
|
|
677
695
|
help="Files or directories to exclude from the backend zip. Can be used multiple times.",
|
|
678
696
|
)
|
|
697
|
+
@click.option(
|
|
698
|
+
"--server-side-rendering/--no-server-side-rendering",
|
|
699
|
+
"--ssr/--no-ssr",
|
|
700
|
+
"ssr",
|
|
701
|
+
default=True,
|
|
702
|
+
is_flag=True,
|
|
703
|
+
help="Whether to enable server side rendering for the frontend.",
|
|
704
|
+
)
|
|
679
705
|
def deploy(
|
|
680
706
|
app_name: str | None,
|
|
681
707
|
app_id: str | None,
|
|
@@ -690,6 +716,7 @@ def deploy(
|
|
|
690
716
|
token: str | None,
|
|
691
717
|
config_path: str | None,
|
|
692
718
|
backend_excluded_dirs: tuple[Path, ...] = (),
|
|
719
|
+
ssr: bool = True,
|
|
693
720
|
):
|
|
694
721
|
"""Deploy the app to the Reflex hosting service."""
|
|
695
722
|
from reflex_cli.utils import dependency
|
|
@@ -707,6 +734,11 @@ def deploy(
|
|
|
707
734
|
|
|
708
735
|
environment.REFLEX_COMPILE_CONTEXT.set(constants.CompileContext.DEPLOY)
|
|
709
736
|
|
|
737
|
+
if not environment.REFLEX_SSR.is_set():
|
|
738
|
+
environment.REFLEX_SSR.set(ssr)
|
|
739
|
+
elif environment.REFLEX_SSR.get() != ssr:
|
|
740
|
+
ssr = environment.REFLEX_SSR.get()
|
|
741
|
+
|
|
710
742
|
# Only check requirements if interactive.
|
|
711
743
|
# There is user interaction for requirements update.
|
|
712
744
|
if interactive:
|
|
@@ -739,6 +771,7 @@ def deploy(
|
|
|
739
771
|
loglevel=config.loglevel.subprocess_level(),
|
|
740
772
|
upload_db_file=upload_db,
|
|
741
773
|
backend_excluded_dirs=backend_excluded_dirs,
|
|
774
|
+
prerender_routes=ssr,
|
|
742
775
|
)
|
|
743
776
|
),
|
|
744
777
|
regions=list(region),
|
reflex/state.py
CHANGED
|
@@ -7,6 +7,7 @@ import builtins
|
|
|
7
7
|
import contextlib
|
|
8
8
|
import copy
|
|
9
9
|
import dataclasses
|
|
10
|
+
import datetime
|
|
10
11
|
import functools
|
|
11
12
|
import inspect
|
|
12
13
|
import pickle
|
|
@@ -306,6 +307,14 @@ async def _resolve_delta(delta: Delta) -> Delta:
|
|
|
306
307
|
return delta
|
|
307
308
|
|
|
308
309
|
|
|
310
|
+
_deserializers = {
|
|
311
|
+
int: int,
|
|
312
|
+
float: float,
|
|
313
|
+
datetime.datetime: datetime.datetime.fromisoformat,
|
|
314
|
+
datetime.date: datetime.date.fromisoformat,
|
|
315
|
+
datetime.time: datetime.time.fromisoformat,
|
|
316
|
+
}
|
|
317
|
+
|
|
309
318
|
all_base_state_classes: dict[str, None] = {}
|
|
310
319
|
|
|
311
320
|
|
|
@@ -1872,11 +1881,12 @@ class BaseState(EvenMoreBasicBaseState):
|
|
|
1872
1881
|
hinted_args is tuple or hinted_args is tuple
|
|
1873
1882
|
):
|
|
1874
1883
|
payload[arg] = tuple(value)
|
|
1875
|
-
elif
|
|
1876
|
-
|
|
1884
|
+
elif (
|
|
1885
|
+
isinstance(value, str)
|
|
1886
|
+
and (deserializer := _deserializers.get(hinted_args)) is not None
|
|
1877
1887
|
):
|
|
1878
1888
|
try:
|
|
1879
|
-
payload[arg] =
|
|
1889
|
+
payload[arg] = deserializer(value)
|
|
1880
1890
|
except ValueError:
|
|
1881
1891
|
msg = f"Received a string value ({value}) for {arg} but expected a {hinted_args}"
|
|
1882
1892
|
raise ValueError(msg) from None
|
reflex/utils/build.py
CHANGED
|
@@ -215,10 +215,16 @@ def build():
|
|
|
215
215
|
)
|
|
216
216
|
processes.show_progress("Creating Production Build", process, checkpoints)
|
|
217
217
|
_duplicate_index_html_to_parent_directory(wdir / constants.Dirs.STATIC)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
|
|
219
|
+
spa_fallback = wdir / constants.Dirs.STATIC / constants.ReactRouter.SPA_FALLBACK
|
|
220
|
+
if not spa_fallback.exists():
|
|
221
|
+
spa_fallback = wdir / constants.Dirs.STATIC / "index.html"
|
|
222
|
+
|
|
223
|
+
if spa_fallback.exists():
|
|
224
|
+
path_ops.cp(
|
|
225
|
+
spa_fallback,
|
|
226
|
+
wdir / constants.Dirs.STATIC / "404.html",
|
|
227
|
+
)
|
|
222
228
|
|
|
223
229
|
config = get_config()
|
|
224
230
|
|
reflex/utils/exec.py
CHANGED
|
@@ -743,6 +743,17 @@ def is_prod_mode() -> bool:
|
|
|
743
743
|
return current_mode == constants.Env.PROD
|
|
744
744
|
|
|
745
745
|
|
|
746
|
+
def should_prerender_routes() -> bool:
|
|
747
|
+
"""Check if the app should prerender routes.
|
|
748
|
+
|
|
749
|
+
Returns:
|
|
750
|
+
True if the app should prerender routes.
|
|
751
|
+
"""
|
|
752
|
+
if not environment.REFLEX_SSR.is_set():
|
|
753
|
+
return is_prod_mode()
|
|
754
|
+
return environment.REFLEX_SSR.get()
|
|
755
|
+
|
|
756
|
+
|
|
746
757
|
def get_compile_context() -> constants.CompileContext:
|
|
747
758
|
"""Check if the app is compiled for deploy.
|
|
748
759
|
|
reflex/utils/export.py
CHANGED
|
@@ -19,6 +19,7 @@ def export(
|
|
|
19
19
|
env: constants.Env = constants.Env.PROD,
|
|
20
20
|
loglevel: constants.LogLevel = console._LOG_LEVEL,
|
|
21
21
|
backend_excluded_dirs: tuple[Path, ...] = (),
|
|
22
|
+
prerender_routes: bool = True,
|
|
22
23
|
):
|
|
23
24
|
"""Export the app to a zip file.
|
|
24
25
|
|
|
@@ -33,6 +34,7 @@ def export(
|
|
|
33
34
|
env: The environment to use. Defaults to constants.Env.PROD.
|
|
34
35
|
loglevel: The log level to use. Defaults to console._LOG_LEVEL.
|
|
35
36
|
backend_excluded_dirs: A tuple of files or directories to exclude from the backend zip. Defaults to ().
|
|
37
|
+
prerender_routes: Whether to prerender the routes. Defaults to True.
|
|
36
38
|
"""
|
|
37
39
|
config = get_config()
|
|
38
40
|
|
|
@@ -58,7 +60,7 @@ def export(
|
|
|
58
60
|
|
|
59
61
|
if frontend:
|
|
60
62
|
# Ensure module can be imported and app.compile() is called.
|
|
61
|
-
prerequisites.get_compiled_app(prerender_routes=
|
|
63
|
+
prerequisites.get_compiled_app(prerender_routes=prerender_routes)
|
|
62
64
|
# Set up .web directory and install frontend dependencies.
|
|
63
65
|
build.setup_frontend(Path.cwd())
|
|
64
66
|
|
reflex/utils/prerequisites.py
CHANGED
|
@@ -269,25 +269,100 @@ def get_compiled_app(
|
|
|
269
269
|
return app_module
|
|
270
270
|
|
|
271
271
|
|
|
272
|
+
def _can_colorize() -> bool:
|
|
273
|
+
"""Check if the output can be colorized.
|
|
274
|
+
|
|
275
|
+
Copied from _colorize.can_colorize.
|
|
276
|
+
|
|
277
|
+
https://raw.githubusercontent.com/python/cpython/refs/heads/main/Lib/_colorize.py
|
|
278
|
+
|
|
279
|
+
Returns:
|
|
280
|
+
If the output can be colorized
|
|
281
|
+
"""
|
|
282
|
+
import io
|
|
283
|
+
import os
|
|
284
|
+
|
|
285
|
+
def _safe_getenv(k: str, fallback: str | None = None) -> str | None:
|
|
286
|
+
"""Exception-safe environment retrieval. See gh-128636.
|
|
287
|
+
|
|
288
|
+
Args:
|
|
289
|
+
k: The environment variable key.
|
|
290
|
+
fallback: The fallback value if the environment variable is not set.
|
|
291
|
+
|
|
292
|
+
Returns:
|
|
293
|
+
The value of the environment variable or the fallback value.
|
|
294
|
+
"""
|
|
295
|
+
try:
|
|
296
|
+
return os.environ.get(k, fallback)
|
|
297
|
+
except Exception:
|
|
298
|
+
return fallback
|
|
299
|
+
|
|
300
|
+
file = sys.stdout
|
|
301
|
+
|
|
302
|
+
if not sys.flags.ignore_environment:
|
|
303
|
+
if _safe_getenv("PYTHON_COLORS") == "0":
|
|
304
|
+
return False
|
|
305
|
+
if _safe_getenv("PYTHON_COLORS") == "1":
|
|
306
|
+
return True
|
|
307
|
+
if _safe_getenv("NO_COLOR"):
|
|
308
|
+
return False
|
|
309
|
+
if _safe_getenv("FORCE_COLOR"):
|
|
310
|
+
return True
|
|
311
|
+
if _safe_getenv("TERM") == "dumb":
|
|
312
|
+
return False
|
|
313
|
+
|
|
314
|
+
if not hasattr(file, "fileno"):
|
|
315
|
+
return False
|
|
316
|
+
|
|
317
|
+
if sys.platform == "win32":
|
|
318
|
+
try:
|
|
319
|
+
import nt
|
|
320
|
+
|
|
321
|
+
if not nt._supports_virtual_terminal():
|
|
322
|
+
return False
|
|
323
|
+
except (ImportError, AttributeError):
|
|
324
|
+
return False
|
|
325
|
+
|
|
326
|
+
try:
|
|
327
|
+
return os.isatty(file.fileno())
|
|
328
|
+
except io.UnsupportedOperation:
|
|
329
|
+
return hasattr(file, "isatty") and file.isatty()
|
|
330
|
+
|
|
331
|
+
|
|
272
332
|
def compile_or_validate_app(
|
|
273
333
|
compile: bool = False,
|
|
274
334
|
check_if_schema_up_to_date: bool = False,
|
|
275
335
|
prerender_routes: bool = False,
|
|
276
|
-
):
|
|
336
|
+
) -> bool:
|
|
277
337
|
"""Compile or validate the app module based on the default config.
|
|
278
338
|
|
|
279
339
|
Args:
|
|
280
340
|
compile: Whether to compile the app.
|
|
281
341
|
check_if_schema_up_to_date: If True, check if the schema is up to date.
|
|
282
342
|
prerender_routes: Whether to prerender routes.
|
|
343
|
+
|
|
344
|
+
Returns:
|
|
345
|
+
True if the app was successfully compiled or validated, False otherwise.
|
|
283
346
|
"""
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
347
|
+
try:
|
|
348
|
+
if compile:
|
|
349
|
+
get_compiled_app(
|
|
350
|
+
check_if_schema_up_to_date=check_if_schema_up_to_date,
|
|
351
|
+
prerender_routes=prerender_routes,
|
|
352
|
+
)
|
|
353
|
+
else:
|
|
354
|
+
get_and_validate_app(check_if_schema_up_to_date=check_if_schema_up_to_date)
|
|
355
|
+
except Exception as e:
|
|
356
|
+
import traceback
|
|
357
|
+
|
|
358
|
+
try:
|
|
359
|
+
colorize = _can_colorize()
|
|
360
|
+
traceback.print_exception(e, colorize=colorize) # pyright: ignore[reportCallIssue]
|
|
361
|
+
except Exception:
|
|
362
|
+
traceback.print_exception(e)
|
|
363
|
+
return False
|
|
289
364
|
else:
|
|
290
|
-
|
|
365
|
+
return True
|
|
291
366
|
|
|
292
367
|
|
|
293
368
|
def get_redis() -> Redis | None:
|
reflex/utils/serializers.py
CHANGED
|
@@ -20,7 +20,7 @@ from pydantic import BaseModel as BaseModelV2
|
|
|
20
20
|
from pydantic.v1 import BaseModel as BaseModelV1
|
|
21
21
|
|
|
22
22
|
from reflex.base import Base
|
|
23
|
-
from reflex.constants.colors import Color
|
|
23
|
+
from reflex.constants.colors import Color
|
|
24
24
|
from reflex.utils import console, types
|
|
25
25
|
|
|
26
26
|
# Mapping from type to a serializer.
|
|
@@ -413,8 +413,8 @@ def serialize_decimal(value: decimal.Decimal) -> float:
|
|
|
413
413
|
return float(value)
|
|
414
414
|
|
|
415
415
|
|
|
416
|
-
@serializer(to=
|
|
417
|
-
def serialize_color(color: Color) ->
|
|
416
|
+
@serializer(to=dict)
|
|
417
|
+
def serialize_color(color: Color) -> dict:
|
|
418
418
|
"""Serialize a color.
|
|
419
419
|
|
|
420
420
|
Args:
|
|
@@ -423,7 +423,11 @@ def serialize_color(color: Color) -> str:
|
|
|
423
423
|
Returns:
|
|
424
424
|
The serialized color.
|
|
425
425
|
"""
|
|
426
|
-
return
|
|
426
|
+
return {
|
|
427
|
+
"color": color.color,
|
|
428
|
+
"shade": color.shade,
|
|
429
|
+
"alpha": color.alpha,
|
|
430
|
+
}
|
|
427
431
|
|
|
428
432
|
|
|
429
433
|
with contextlib.suppress(ImportError):
|
reflex/vars/__init__.py
CHANGED
|
@@ -1,28 +1,58 @@
|
|
|
1
1
|
"""Immutable-Based Var System."""
|
|
2
2
|
|
|
3
|
-
from .base import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
from .
|
|
17
|
-
from .
|
|
18
|
-
from .
|
|
19
|
-
from .number import LiteralBooleanVar
|
|
20
|
-
from .
|
|
21
|
-
from .
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
3
|
+
from .base import (
|
|
4
|
+
BaseStateMeta,
|
|
5
|
+
EvenMoreBasicBaseState,
|
|
6
|
+
Field,
|
|
7
|
+
LiteralVar,
|
|
8
|
+
Var,
|
|
9
|
+
VarData,
|
|
10
|
+
field,
|
|
11
|
+
get_unique_variable_name,
|
|
12
|
+
get_uuid_string_var,
|
|
13
|
+
var_operation,
|
|
14
|
+
var_operation_return,
|
|
15
|
+
)
|
|
16
|
+
from .color import ColorVar, LiteralColorVar
|
|
17
|
+
from .datetime import DateTimeVar
|
|
18
|
+
from .function import FunctionStringVar, FunctionVar, VarOperationCall
|
|
19
|
+
from .number import BooleanVar, LiteralBooleanVar, LiteralNumberVar, NumberVar
|
|
20
|
+
from .object import LiteralObjectVar, ObjectVar
|
|
21
|
+
from .sequence import (
|
|
22
|
+
ArrayVar,
|
|
23
|
+
ConcatVarOperation,
|
|
24
|
+
LiteralArrayVar,
|
|
25
|
+
LiteralStringVar,
|
|
26
|
+
StringVar,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"ArrayVar",
|
|
31
|
+
"BaseStateMeta",
|
|
32
|
+
"BooleanVar",
|
|
33
|
+
"ColorVar",
|
|
34
|
+
"ConcatVarOperation",
|
|
35
|
+
"DateTimeVar",
|
|
36
|
+
"EvenMoreBasicBaseState",
|
|
37
|
+
"Field",
|
|
38
|
+
"FunctionStringVar",
|
|
39
|
+
"FunctionVar",
|
|
40
|
+
"LiteralArrayVar",
|
|
41
|
+
"LiteralBooleanVar",
|
|
42
|
+
"LiteralColorVar",
|
|
43
|
+
"LiteralNumberVar",
|
|
44
|
+
"LiteralObjectVar",
|
|
45
|
+
"LiteralStringVar",
|
|
46
|
+
"LiteralVar",
|
|
47
|
+
"NumberVar",
|
|
48
|
+
"ObjectVar",
|
|
49
|
+
"StringVar",
|
|
50
|
+
"Var",
|
|
51
|
+
"VarData",
|
|
52
|
+
"VarOperationCall",
|
|
53
|
+
"field",
|
|
54
|
+
"get_unique_variable_name",
|
|
55
|
+
"get_uuid_string_var",
|
|
56
|
+
"var_operation",
|
|
57
|
+
"var_operation_return",
|
|
58
|
+
]
|