reflex 0.4.8.post1__py3-none-any.whl → 0.4.9__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 +3 -0
- reflex/components/component.py +10 -3
- reflex/components/core/debounce.py +4 -1
- reflex/experimental/__init__.py +2 -0
- reflex/experimental/hooks.py +19 -1
- reflex/experimental/layout.py +223 -0
- reflex/testing.py +23 -6
- reflex/utils/prerequisites.py +5 -3
- reflex/utils/processes.py +22 -1
- reflex/utils/pyi_generator.py +6 -1
- reflex/utils/serializers.py +14 -0
- reflex/vars.py +1 -1
- {reflex-0.4.8.post1.dist-info → reflex-0.4.9.dist-info}/METADATA +1 -1
- {reflex-0.4.8.post1.dist-info → reflex-0.4.9.dist-info}/RECORD +17 -29
- reflex/components/radix/themes/components/alertdialog.pyi +0 -1128
- reflex/components/radix/themes/components/aspectratio.pyi +0 -162
- reflex/components/radix/themes/components/contextmenu.pyi +0 -1249
- reflex/components/radix/themes/components/dropdownmenu.pyi +0 -1350
- reflex/components/radix/themes/components/hovercard.pyi +0 -700
- reflex/components/radix/themes/components/iconbutton.pyi +0 -284
- reflex/components/radix/themes/components/radiogroup.pyi +0 -701
- reflex/components/radix/themes/components/scrollarea.pyi +0 -176
- reflex/components/radix/themes/components/textfield.pyi +0 -1092
- reflex/components/radix/themes/typography/em.pyi +0 -213
- reflex/components/radix/themes/typography/kbd.pyi +0 -222
- reflex/components/radix/themes/typography/quote.pyi +0 -215
- reflex/components/radix/themes/typography/strong.pyi +0 -213
- {reflex-0.4.8.post1.dist-info → reflex-0.4.9.dist-info}/LICENSE +0 -0
- {reflex-0.4.8.post1.dist-info → reflex-0.4.9.dist-info}/WHEEL +0 -0
- {reflex-0.4.8.post1.dist-info → reflex-0.4.9.dist-info}/entry_points.txt +0 -0
reflex/app.py
CHANGED
|
@@ -839,6 +839,9 @@ class App(Base):
|
|
|
839
839
|
compile_results.append(
|
|
840
840
|
compiler.compile_contexts(self.state, self.theme),
|
|
841
841
|
)
|
|
842
|
+
# Fix #2992 by removing the top-level appearance prop
|
|
843
|
+
if self.theme is not None:
|
|
844
|
+
self.theme.appearance = None
|
|
842
845
|
|
|
843
846
|
app_root = self._app_root(app_wrappers=app_wrappers)
|
|
844
847
|
|
reflex/components/component.py
CHANGED
|
@@ -662,9 +662,11 @@ class Component(BaseComponent, ABC):
|
|
|
662
662
|
(
|
|
663
663
|
child
|
|
664
664
|
if isinstance(child, Component)
|
|
665
|
-
else
|
|
666
|
-
|
|
667
|
-
|
|
665
|
+
else (
|
|
666
|
+
Fragment.create(*child)
|
|
667
|
+
if isinstance(child, tuple)
|
|
668
|
+
else Bare.create(contents=Var.create(child, _var_is_string=True))
|
|
669
|
+
)
|
|
668
670
|
)
|
|
669
671
|
for child in children
|
|
670
672
|
]
|
|
@@ -1053,6 +1055,11 @@ class Component(BaseComponent, ABC):
|
|
|
1053
1055
|
ImportVar(tag="useEffect"),
|
|
1054
1056
|
},
|
|
1055
1057
|
)
|
|
1058
|
+
|
|
1059
|
+
user_hooks = self._get_hooks()
|
|
1060
|
+
if user_hooks is not None and isinstance(user_hooks, Var):
|
|
1061
|
+
_imports = imports.merge_imports(_imports, user_hooks._var_data.imports) # type: ignore
|
|
1062
|
+
|
|
1056
1063
|
return _imports
|
|
1057
1064
|
|
|
1058
1065
|
def _get_imports(self) -> imports.ImportDict:
|
|
@@ -79,7 +79,9 @@ class DebounceInput(Component):
|
|
|
79
79
|
for p in cls.get_props()
|
|
80
80
|
if getattr(child, p, None) is not None
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
props[EventTriggers.ON_CHANGE] = child.event_triggers.pop(
|
|
83
|
+
EventTriggers.ON_CHANGE
|
|
84
|
+
)
|
|
83
85
|
props = {**props_from_child, **props}
|
|
84
86
|
|
|
85
87
|
# Carry all other child props directly via custom_attrs
|
|
@@ -117,6 +119,7 @@ class DebounceInput(Component):
|
|
|
117
119
|
|
|
118
120
|
component = super().create(**props)
|
|
119
121
|
component._get_style = child._get_style
|
|
122
|
+
component.event_triggers.update(child.event_triggers)
|
|
120
123
|
return component
|
|
121
124
|
|
|
122
125
|
def get_event_triggers(self) -> dict[str, Any]:
|
reflex/experimental/__init__.py
CHANGED
|
@@ -4,6 +4,7 @@ from types import SimpleNamespace
|
|
|
4
4
|
|
|
5
5
|
from ..utils.console import warn
|
|
6
6
|
from . import hooks as hooks
|
|
7
|
+
from .layout import layout as layout
|
|
7
8
|
from .misc import run_in_thread as run_in_thread
|
|
8
9
|
|
|
9
10
|
warn(
|
|
@@ -12,5 +13,6 @@ warn(
|
|
|
12
13
|
|
|
13
14
|
_x = SimpleNamespace(
|
|
14
15
|
hooks=hooks,
|
|
16
|
+
layout=layout,
|
|
15
17
|
run_in_thread=run_in_thread,
|
|
16
18
|
)
|
reflex/experimental/hooks.py
CHANGED
|
@@ -12,7 +12,7 @@ def _add_react_import(v: Var | None, tags: str | list):
|
|
|
12
12
|
tags = [tags]
|
|
13
13
|
|
|
14
14
|
v._var_data = VarData( # type: ignore
|
|
15
|
-
imports={"react": [ImportVar(tag=tag) for tag in tags]},
|
|
15
|
+
imports={"react": [ImportVar(tag=tag, install=False) for tag in tags]},
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
|
|
@@ -26,6 +26,8 @@ def const(name, value) -> Var | None:
|
|
|
26
26
|
Returns:
|
|
27
27
|
The constant Var.
|
|
28
28
|
"""
|
|
29
|
+
if isinstance(name, list):
|
|
30
|
+
return Var.create(f"const [{', '.join(name)}] = {value}")
|
|
29
31
|
return Var.create(f"const {name} = {value}")
|
|
30
32
|
|
|
31
33
|
|
|
@@ -73,3 +75,19 @@ def useRef(default) -> Var | None:
|
|
|
73
75
|
v = Var.create(f"useRef({default})")
|
|
74
76
|
_add_react_import(v, "useRef")
|
|
75
77
|
return v
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def useState(var_name, default=None) -> Var | None:
|
|
81
|
+
"""Create a useState hook with a variable name and setter name.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
var_name: The name of the variable.
|
|
85
|
+
default: The default value of the variable.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
A useState hook.
|
|
89
|
+
"""
|
|
90
|
+
setter_name = f"set{var_name.capitalize()}"
|
|
91
|
+
v = const([var_name, setter_name], f"useState({default})")
|
|
92
|
+
_add_react_import(v, "useState")
|
|
93
|
+
return v
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""To experiment with layout component, move them to reflex/components later."""
|
|
2
|
+
|
|
3
|
+
from reflex import color, cond
|
|
4
|
+
from reflex.components.base.fragment import Fragment
|
|
5
|
+
from reflex.components.component import Component, ComponentNamespace, MemoizationLeaf
|
|
6
|
+
from reflex.components.radix.primitives.drawer import DrawerRoot, drawer
|
|
7
|
+
from reflex.components.radix.themes.components.icon_button import IconButton
|
|
8
|
+
from reflex.components.radix.themes.layout import Box, Container, HStack
|
|
9
|
+
from reflex.event import call_script
|
|
10
|
+
from reflex.experimental import hooks
|
|
11
|
+
from reflex.state import ComponentState
|
|
12
|
+
from reflex.vars import Var
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Sidebar(Box, MemoizationLeaf):
|
|
16
|
+
"""A component that renders the sidebar."""
|
|
17
|
+
|
|
18
|
+
@classmethod
|
|
19
|
+
def create(cls, *children, **props):
|
|
20
|
+
"""Create the sidebar component.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
children: The children components.
|
|
24
|
+
props: The properties of the sidebar.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
The sidebar component.
|
|
28
|
+
"""
|
|
29
|
+
props.setdefault("border_right", f"1px solid {color('accent', 12)}")
|
|
30
|
+
props.setdefault("background_color", color("accent", 1))
|
|
31
|
+
props.setdefault("width", "20vw")
|
|
32
|
+
props.setdefault("height", "100vh")
|
|
33
|
+
props.setdefault("position", "fixed")
|
|
34
|
+
|
|
35
|
+
return super().create(
|
|
36
|
+
Box.create(*children, **props), # sidebar for content
|
|
37
|
+
Box.create(width=props.get("width")), # spacer for layout
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def _apply_theme(self, theme: Component | None):
|
|
41
|
+
sidebar: Component = self.children[-2] # type: ignore
|
|
42
|
+
spacer: Component = self.children[-1] # type: ignore
|
|
43
|
+
open = self.State.open if self.State else Var.create("open") # type: ignore
|
|
44
|
+
sidebar.style["display"] = spacer.style["display"] = cond(open, "block", "none")
|
|
45
|
+
|
|
46
|
+
def _get_hooks(self) -> Var | None:
|
|
47
|
+
return hooks.useState("open", "true") if not self.State else None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class StatefulSidebar(ComponentState):
|
|
51
|
+
"""Bind a state to a sidebar component."""
|
|
52
|
+
|
|
53
|
+
open: bool = True
|
|
54
|
+
|
|
55
|
+
def toggle(self):
|
|
56
|
+
"""Toggle the sidebar."""
|
|
57
|
+
self.open = not self.open
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def get_component(cls, *children, **props):
|
|
61
|
+
"""Get the stateful sidebar component.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
children: The children components.
|
|
65
|
+
props: The properties of the sidebar.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
The stateful sidebar component.
|
|
69
|
+
"""
|
|
70
|
+
return Sidebar.create(*children, **props)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class DrawerSidebar(DrawerRoot):
|
|
74
|
+
"""A component that renders a drawer sidebar."""
|
|
75
|
+
|
|
76
|
+
@classmethod
|
|
77
|
+
def create(cls, *children, **props):
|
|
78
|
+
"""Create the sidebar component.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
children: The children components.
|
|
82
|
+
props: The properties of the sidebar.
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
The drawer sidebar component.
|
|
86
|
+
"""
|
|
87
|
+
direction = props.pop("direction", "left")
|
|
88
|
+
props.setdefault("border_right", f"1px solid {color('accent', 12)}")
|
|
89
|
+
props.setdefault("background_color", color("accent", 1))
|
|
90
|
+
props.setdefault("width", "20vw")
|
|
91
|
+
props.setdefault("height", "100vh")
|
|
92
|
+
return super().create(
|
|
93
|
+
drawer.trigger(
|
|
94
|
+
IconButton.create(
|
|
95
|
+
"arrow-right-from-line",
|
|
96
|
+
background_color="transparent",
|
|
97
|
+
),
|
|
98
|
+
position="absolute",
|
|
99
|
+
top="15",
|
|
100
|
+
left="15",
|
|
101
|
+
),
|
|
102
|
+
drawer.portal(
|
|
103
|
+
drawer.content(
|
|
104
|
+
*children,
|
|
105
|
+
**props,
|
|
106
|
+
)
|
|
107
|
+
),
|
|
108
|
+
direction=direction,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
sidebar_trigger_style = {
|
|
113
|
+
"position": "fixed",
|
|
114
|
+
"z_index": "15",
|
|
115
|
+
"color": color("accent", 12),
|
|
116
|
+
"background_color": "transparent",
|
|
117
|
+
"padding": "0",
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class SidebarTrigger(Fragment):
|
|
122
|
+
"""A component that renders the sidebar trigger."""
|
|
123
|
+
|
|
124
|
+
@classmethod
|
|
125
|
+
def create(cls, sidebar: Component, **props):
|
|
126
|
+
"""Create the sidebar trigger component.
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
sidebar: The sidebar component.
|
|
130
|
+
props: The properties of the sidebar trigger.
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
The sidebar trigger component.
|
|
134
|
+
"""
|
|
135
|
+
trigger_props = {**props, **sidebar_trigger_style}
|
|
136
|
+
|
|
137
|
+
inner_sidebar: Component = sidebar.children[0] # type: ignore
|
|
138
|
+
sidebar_width = inner_sidebar.style.get("width")
|
|
139
|
+
|
|
140
|
+
if sidebar.State:
|
|
141
|
+
open, toggle = sidebar.State.open, sidebar.State.toggle # type: ignore
|
|
142
|
+
else:
|
|
143
|
+
open, toggle = Var.create("open"), call_script(Var.create("setOpen(!open)")) # type: ignore
|
|
144
|
+
|
|
145
|
+
trigger_props["left"] = cond(open, f"calc({sidebar_width} - 32px)", "0")
|
|
146
|
+
|
|
147
|
+
trigger = cond(
|
|
148
|
+
open,
|
|
149
|
+
IconButton.create(
|
|
150
|
+
"arrow-left-from-line",
|
|
151
|
+
on_click=toggle,
|
|
152
|
+
**trigger_props,
|
|
153
|
+
),
|
|
154
|
+
IconButton.create(
|
|
155
|
+
"arrow-right-from-line",
|
|
156
|
+
on_click=toggle,
|
|
157
|
+
**trigger_props,
|
|
158
|
+
),
|
|
159
|
+
)
|
|
160
|
+
return super().create(trigger)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class Layout(Box):
|
|
164
|
+
"""A component that renders the layout."""
|
|
165
|
+
|
|
166
|
+
@classmethod
|
|
167
|
+
def create(
|
|
168
|
+
cls,
|
|
169
|
+
*content: Component,
|
|
170
|
+
sidebar: Component | None = None,
|
|
171
|
+
**props,
|
|
172
|
+
):
|
|
173
|
+
"""Create the layout component.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
content: The content component.
|
|
177
|
+
sidebar: The sidebar component.
|
|
178
|
+
props: The properties of the layout.
|
|
179
|
+
|
|
180
|
+
Returns:
|
|
181
|
+
The layout component.
|
|
182
|
+
"""
|
|
183
|
+
layout_root = HStack.create
|
|
184
|
+
|
|
185
|
+
if sidebar is None:
|
|
186
|
+
return Container.create(*content, **props)
|
|
187
|
+
|
|
188
|
+
if isinstance(sidebar, DrawerSidebar):
|
|
189
|
+
return super().create(
|
|
190
|
+
sidebar,
|
|
191
|
+
Container.create(*content, height="100%"),
|
|
192
|
+
**props,
|
|
193
|
+
width="100vw",
|
|
194
|
+
min_height="100vh",
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
if not isinstance(sidebar, Sidebar):
|
|
198
|
+
sidebar = Sidebar.create(sidebar)
|
|
199
|
+
|
|
200
|
+
# Add the sidebar trigger to the sidebar as first child to not mess up the rendering.
|
|
201
|
+
sidebar.children.insert(0, SidebarTrigger.create(sidebar))
|
|
202
|
+
|
|
203
|
+
return super().create(
|
|
204
|
+
layout_root(
|
|
205
|
+
sidebar,
|
|
206
|
+
Container.create(*content, height="100%"),
|
|
207
|
+
**props,
|
|
208
|
+
width="100vw",
|
|
209
|
+
min_height="100vh",
|
|
210
|
+
)
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
class LayoutNamespace(ComponentNamespace):
|
|
215
|
+
"""Namespace for layout components."""
|
|
216
|
+
|
|
217
|
+
drawer_sidebar = staticmethod(DrawerSidebar.create)
|
|
218
|
+
stateful_sidebar = staticmethod(StatefulSidebar.create)
|
|
219
|
+
sidebar = staticmethod(Sidebar.create)
|
|
220
|
+
__call__ = staticmethod(Layout.create)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
layout = LayoutNamespace()
|
reflex/testing.py
CHANGED
|
@@ -112,7 +112,9 @@ class AppHarness:
|
|
|
112
112
|
"""AppHarness executes a reflex app in-process for testing."""
|
|
113
113
|
|
|
114
114
|
app_name: str
|
|
115
|
-
app_source: Optional[
|
|
115
|
+
app_source: Optional[
|
|
116
|
+
types.FunctionType | types.ModuleType | str | functools.partial
|
|
117
|
+
]
|
|
116
118
|
app_path: pathlib.Path
|
|
117
119
|
app_module_path: pathlib.Path
|
|
118
120
|
app_module: Optional[types.ModuleType] = None
|
|
@@ -124,6 +126,7 @@ class AppHarness:
|
|
|
124
126
|
backend: Optional[uvicorn.Server] = None
|
|
125
127
|
state_manager: Optional[StateManagerMemory | StateManagerRedis] = None
|
|
126
128
|
_frontends: list["WebDriver"] = dataclasses.field(default_factory=list)
|
|
129
|
+
_decorated_pages: list = dataclasses.field(default_factory=list)
|
|
127
130
|
|
|
128
131
|
@classmethod
|
|
129
132
|
def create(
|
|
@@ -149,15 +152,21 @@ class AppHarness:
|
|
|
149
152
|
"""
|
|
150
153
|
if app_name is None:
|
|
151
154
|
if app_source is None:
|
|
152
|
-
app_name = root.name
|
|
155
|
+
app_name = root.name
|
|
153
156
|
elif isinstance(app_source, functools.partial):
|
|
154
|
-
|
|
157
|
+
keywords = app_source.keywords
|
|
158
|
+
slug_suffix = "_".join([str(v) for v in keywords.values()])
|
|
159
|
+
func_name = app_source.func.__name__
|
|
160
|
+
app_name = f"{func_name}_{slug_suffix}"
|
|
161
|
+
app_name = re.sub(r"[^a-zA-Z0-9_]", "_", app_name)
|
|
155
162
|
elif isinstance(app_source, str):
|
|
156
163
|
raise ValueError(
|
|
157
164
|
"app_name must be provided when app_source is a string."
|
|
158
165
|
)
|
|
159
166
|
else:
|
|
160
|
-
app_name = app_source.__name__
|
|
167
|
+
app_name = app_source.__name__
|
|
168
|
+
|
|
169
|
+
app_name = app_name.lower()
|
|
161
170
|
return cls(
|
|
162
171
|
app_name=app_name,
|
|
163
172
|
app_source=app_source,
|
|
@@ -230,11 +239,15 @@ class AppHarness:
|
|
|
230
239
|
with chdir(self.app_path):
|
|
231
240
|
# ensure config and app are reloaded when testing different app
|
|
232
241
|
reflex.config.get_config(reload=True)
|
|
233
|
-
#
|
|
234
|
-
reflex.app.DECORATED_PAGES.
|
|
242
|
+
# Save decorated pages before importing the test app module
|
|
243
|
+
before_decorated_pages = reflex.app.DECORATED_PAGES.copy()
|
|
235
244
|
# Ensure the AppHarness test does not skip State assignment due to running via pytest
|
|
236
245
|
os.environ.pop(reflex.constants.PYTEST_CURRENT_TEST, None)
|
|
237
246
|
self.app_module = reflex.utils.prerequisites.get_compiled_app(reload=True)
|
|
247
|
+
# Save the pages that were added during testing
|
|
248
|
+
self._decorated_pages = [
|
|
249
|
+
p for p in reflex.app.DECORATED_PAGES if p not in before_decorated_pages
|
|
250
|
+
]
|
|
238
251
|
self.app_instance = self.app_module.app
|
|
239
252
|
if isinstance(self.app_instance._state_manager, StateManagerRedis):
|
|
240
253
|
# Create our own redis connection for testing.
|
|
@@ -396,6 +409,10 @@ class AppHarness:
|
|
|
396
409
|
for driver in self._frontends:
|
|
397
410
|
driver.quit()
|
|
398
411
|
|
|
412
|
+
# Cleanup decorated pages added during testing
|
|
413
|
+
for page in self._decorated_pages:
|
|
414
|
+
reflex.app.DECORATED_PAGES.remove(page)
|
|
415
|
+
|
|
399
416
|
def __exit__(self, *excinfo) -> None:
|
|
400
417
|
"""Contextmanager protocol for `stop()`.
|
|
401
418
|
|
reflex/utils/prerequisites.py
CHANGED
|
@@ -821,14 +821,16 @@ def install_frontend_packages(packages: set[str], config: Config):
|
|
|
821
821
|
Example:
|
|
822
822
|
>>> install_frontend_packages(["react", "react-dom"], get_config())
|
|
823
823
|
"""
|
|
824
|
-
# unsupported archs will use npm anyway. so we dont have to run npm twice
|
|
824
|
+
# unsupported archs(arm and 32bit machines) will use npm anyway. so we dont have to run npm twice
|
|
825
825
|
fallback_command = (
|
|
826
826
|
get_package_manager()
|
|
827
|
-
if constants.IS_WINDOWS
|
|
827
|
+
if not constants.IS_WINDOWS
|
|
828
|
+
or constants.IS_WINDOWS
|
|
829
|
+
and constants.IS_WINDOWS_BUN_SUPPORTED_MACHINE
|
|
828
830
|
else None
|
|
829
831
|
)
|
|
830
832
|
processes.run_process_with_fallback(
|
|
831
|
-
[get_install_package_manager(), "install",
|
|
833
|
+
[get_install_package_manager(), "install"], # type: ignore
|
|
832
834
|
fallback=fallback_command,
|
|
833
835
|
show_status_message="Installing base frontend packages",
|
|
834
836
|
cwd=constants.Dirs.WEB,
|
reflex/utils/processes.py
CHANGED
|
@@ -8,6 +8,7 @@ import os
|
|
|
8
8
|
import signal
|
|
9
9
|
import subprocess
|
|
10
10
|
from concurrent import futures
|
|
11
|
+
from pathlib import Path
|
|
11
12
|
from typing import Callable, Generator, List, Optional, Tuple, Union
|
|
12
13
|
|
|
13
14
|
import psutil
|
|
@@ -145,6 +146,7 @@ def new_process(args, run: bool = False, show_logs: bool = False, **kwargs):
|
|
|
145
146
|
"stdout": None if show_logs else subprocess.PIPE,
|
|
146
147
|
"universal_newlines": True,
|
|
147
148
|
"encoding": "UTF-8",
|
|
149
|
+
"errors": "replace", # Avoid UnicodeDecodeError in unknown command output
|
|
148
150
|
**kwargs,
|
|
149
151
|
}
|
|
150
152
|
console.debug(f"Running command: {args}")
|
|
@@ -296,6 +298,25 @@ def atexit_handler():
|
|
|
296
298
|
console.log("Reflex app stopped.")
|
|
297
299
|
|
|
298
300
|
|
|
301
|
+
def get_command_with_loglevel(command: list[str]) -> list[str]:
|
|
302
|
+
"""Add the right loglevel flag to the designated command.
|
|
303
|
+
npm uses --loglevel <level>, Bun doesnt use the --loglevel flag and
|
|
304
|
+
runs in debug mode by default.
|
|
305
|
+
|
|
306
|
+
Args:
|
|
307
|
+
command:The command to add loglevel flag.
|
|
308
|
+
|
|
309
|
+
Returns:
|
|
310
|
+
The updated command list
|
|
311
|
+
"""
|
|
312
|
+
npm_path = path_ops.get_npm_path()
|
|
313
|
+
npm_path = str(Path(npm_path).resolve()) if npm_path else npm_path
|
|
314
|
+
|
|
315
|
+
if command[0] == npm_path:
|
|
316
|
+
return command + ["--loglevel", "silly"]
|
|
317
|
+
return command
|
|
318
|
+
|
|
319
|
+
|
|
299
320
|
def run_process_with_fallback(args, *, show_status_message, fallback=None, **kwargs):
|
|
300
321
|
"""Run subprocess and retry using fallback command if initial command fails.
|
|
301
322
|
|
|
@@ -305,7 +326,7 @@ def run_process_with_fallback(args, *, show_status_message, fallback=None, **kwa
|
|
|
305
326
|
fallback: The fallback command to run.
|
|
306
327
|
kwargs: Kwargs to pass to new_process function.
|
|
307
328
|
"""
|
|
308
|
-
process = new_process(args, **kwargs)
|
|
329
|
+
process = new_process(get_command_with_loglevel(args), **kwargs)
|
|
309
330
|
if fallback is None:
|
|
310
331
|
# No fallback given, or this _is_ the fallback command.
|
|
311
332
|
show_status(show_status_message, process)
|
reflex/utils/pyi_generator.py
CHANGED
|
@@ -34,6 +34,7 @@ PWD = Path(".").resolve()
|
|
|
34
34
|
|
|
35
35
|
EXCLUDED_FILES = [
|
|
36
36
|
"__init__.py",
|
|
37
|
+
"app.py",
|
|
37
38
|
"component.py",
|
|
38
39
|
"bare.py",
|
|
39
40
|
"foreach.py",
|
|
@@ -795,7 +796,11 @@ class PyiGenerator:
|
|
|
795
796
|
file_targets = []
|
|
796
797
|
for target in targets:
|
|
797
798
|
target_path = Path(target)
|
|
798
|
-
if
|
|
799
|
+
if (
|
|
800
|
+
target_path.is_file()
|
|
801
|
+
and target_path.suffix == ".py"
|
|
802
|
+
and target_path.name not in EXCLUDED_FILES
|
|
803
|
+
):
|
|
799
804
|
file_targets.append(target_path)
|
|
800
805
|
continue
|
|
801
806
|
if not target_path.is_dir():
|
reflex/utils/serializers.py
CHANGED
|
@@ -7,6 +7,7 @@ import types as builtin_types
|
|
|
7
7
|
import warnings
|
|
8
8
|
from datetime import date, datetime, time, timedelta
|
|
9
9
|
from enum import Enum
|
|
10
|
+
from pathlib import Path
|
|
10
11
|
from typing import Any, Callable, Dict, List, Set, Tuple, Type, Union, get_type_hints
|
|
11
12
|
|
|
12
13
|
from reflex.base import Base
|
|
@@ -233,6 +234,19 @@ def serialize_datetime(dt: Union[date, datetime, time, timedelta]) -> str:
|
|
|
233
234
|
return str(dt)
|
|
234
235
|
|
|
235
236
|
|
|
237
|
+
@serializer
|
|
238
|
+
def serialize_path(path: Path):
|
|
239
|
+
"""Serialize a pathlib.Path to a JSON string.
|
|
240
|
+
|
|
241
|
+
Args:
|
|
242
|
+
path: The path to serialize.
|
|
243
|
+
|
|
244
|
+
Returns:
|
|
245
|
+
The serialized path.
|
|
246
|
+
"""
|
|
247
|
+
return str(path.as_posix())
|
|
248
|
+
|
|
249
|
+
|
|
236
250
|
@serializer
|
|
237
251
|
def serialize_enum(en: Enum) -> str:
|
|
238
252
|
"""Serialize a enum to a JSON string.
|
reflex/vars.py
CHANGED
|
@@ -1340,7 +1340,7 @@ class Var:
|
|
|
1340
1340
|
Returns:
|
|
1341
1341
|
A var representing the contain check.
|
|
1342
1342
|
"""
|
|
1343
|
-
if not (types._issubclass(self._var_type, Union[dict, list, tuple, str])):
|
|
1343
|
+
if not (types._issubclass(self._var_type, Union[dict, list, tuple, str, set])):
|
|
1344
1344
|
raise TypeError(
|
|
1345
1345
|
f"Var {self._var_full_name} of type {self._var_type} does not support contains check."
|
|
1346
1346
|
)
|