sier2 0.22__py3-none-any.whl → 0.24__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 sier2 might be problematic. Click here for more details.
sier2/_dag.py
CHANGED
|
@@ -3,6 +3,7 @@ from dataclasses import dataclass, field #, KW_ONLY, field
|
|
|
3
3
|
from collections import defaultdict, deque
|
|
4
4
|
import holoviews as hv
|
|
5
5
|
import threading
|
|
6
|
+
import sys
|
|
6
7
|
from typing import Any
|
|
7
8
|
|
|
8
9
|
# By default, loops in a dag aren't allowed.
|
|
@@ -70,7 +71,8 @@ class _BlockContext:
|
|
|
70
71
|
self.block._block_state = BlockState.WAITING if isinstance(self.block, InputBlock) else BlockState.SUCCESSFUL
|
|
71
72
|
elif exc_type is KeyboardInterrupt:
|
|
72
73
|
self.block_state._block_state = BlockState.INTERRUPTED
|
|
73
|
-
self.dag.
|
|
74
|
+
if not self.dag._is_pyodide:
|
|
75
|
+
self.dag._stopper.event.set()
|
|
74
76
|
print(f'KEYBOARD INTERRUPT IN BLOCK {self.name}')
|
|
75
77
|
else:
|
|
76
78
|
state = BlockState.ERROR
|
|
@@ -87,7 +89,8 @@ class _BlockContext:
|
|
|
87
89
|
|
|
88
90
|
# msg = f'While in {self.block.name}.execute(): {exc_val}'
|
|
89
91
|
# LOGGER.exception(msg)
|
|
90
|
-
self.dag.
|
|
92
|
+
if not self.dag._is_pyodide:
|
|
93
|
+
self.dag._stopper.event.set()
|
|
91
94
|
|
|
92
95
|
if not issubclass(exc_type, BlockError):
|
|
93
96
|
# Convert non-BlockErrors in the block to a BlockError.
|
|
@@ -118,11 +121,14 @@ class Dag:
|
|
|
118
121
|
|
|
119
122
|
def __init__(self, *, site: str='Block', title: str, doc: str):
|
|
120
123
|
self._block_pairs: list[tuple[Block, Block]] = []
|
|
121
|
-
|
|
124
|
+
|
|
122
125
|
self.site = site
|
|
123
126
|
self.title = title
|
|
124
127
|
self.doc = doc
|
|
125
128
|
|
|
129
|
+
if not self._is_pyodide:
|
|
130
|
+
self._stopper = _Stopper()
|
|
131
|
+
|
|
126
132
|
# We watch output params to be notified when they are set.
|
|
127
133
|
# Events are queued here.
|
|
128
134
|
#
|
|
@@ -132,6 +138,10 @@ class Dag:
|
|
|
132
138
|
#
|
|
133
139
|
self._block_context = _BlockContext
|
|
134
140
|
|
|
141
|
+
@property
|
|
142
|
+
def _is_pyodide(self) -> bool:
|
|
143
|
+
return '_pyodide' in sys.modules
|
|
144
|
+
|
|
135
145
|
def _for_each_once(self):
|
|
136
146
|
"""Yield each connected block once."""
|
|
137
147
|
|
|
@@ -144,13 +154,13 @@ class Dag:
|
|
|
144
154
|
|
|
145
155
|
def stop(self):
|
|
146
156
|
"""Stop further execution of Block instances in this dag."""
|
|
147
|
-
|
|
148
|
-
|
|
157
|
+
if not self._is_pyodide:
|
|
158
|
+
self._stopper.event.set()
|
|
149
159
|
|
|
150
160
|
def unstop(self):
|
|
151
161
|
"""Enable further execution of Block instances in this dag."""
|
|
152
|
-
|
|
153
|
-
|
|
162
|
+
if not self._is_pyodide:
|
|
163
|
+
self._stopper.event.clear()
|
|
154
164
|
|
|
155
165
|
def connect(self, src: Block, dst: Block, *connections: Connection):
|
|
156
166
|
if any(not isinstance(c, Connection) for c in connections):
|
|
@@ -290,15 +300,17 @@ class Dag:
|
|
|
290
300
|
# The user has set the "stop executing" flag.
|
|
291
301
|
# Continue to set params, but don't execute anything
|
|
292
302
|
#
|
|
293
|
-
if self.
|
|
294
|
-
|
|
303
|
+
if not self._is_pyodide:
|
|
304
|
+
if self._stopper.is_stopped:
|
|
305
|
+
can_execute = False
|
|
295
306
|
|
|
296
307
|
item = self._block_queue.popleft()
|
|
297
308
|
try:
|
|
298
309
|
item.dst.param.update(item.values)
|
|
299
310
|
except ValueError as e:
|
|
300
311
|
msg = f'While in {item.dst.name} setting a parameter: {e}'
|
|
301
|
-
self.
|
|
312
|
+
if not self._is_pyodide:
|
|
313
|
+
self._stopper.event.set()
|
|
302
314
|
raise BlockError(msg) from e
|
|
303
315
|
|
|
304
316
|
# Execute the block.
|
sier2/panel/_panel.py
CHANGED
|
@@ -10,8 +10,6 @@ from .._dag import _InputValues
|
|
|
10
10
|
from ._feedlogger import getDagPanelLogger, getBlockPanelLogger
|
|
11
11
|
from ._panel_util import _get_state_color, dag_doc
|
|
12
12
|
|
|
13
|
-
NTHREADS = 2
|
|
14
|
-
|
|
15
13
|
# From https://tabler.io/icons/icon/info-circle
|
|
16
14
|
#
|
|
17
15
|
INFO_SVG = '''<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
@@ -22,7 +20,26 @@ INFO_SVG = '''<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" vie
|
|
|
22
20
|
</svg>
|
|
23
21
|
'''
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
if '_pyodide' in sys.modules:
|
|
24
|
+
# Pyodide (to be specific, WASM) doesn't allow threads.
|
|
25
|
+
# Specifying one thread for panel for some reason tries to start one, so we need to rely on the default.
|
|
26
|
+
#
|
|
27
|
+
pn.extension(
|
|
28
|
+
'floatpanel',
|
|
29
|
+
inline=True,
|
|
30
|
+
loading_spinner='bar',
|
|
31
|
+
notifications=True,
|
|
32
|
+
)
|
|
33
|
+
else:
|
|
34
|
+
pn.extension(
|
|
35
|
+
'floatpanel',
|
|
36
|
+
inline=True,
|
|
37
|
+
nthreads=2,
|
|
38
|
+
loading_spinner='bar',
|
|
39
|
+
notifications=True,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
26
43
|
|
|
27
44
|
def _hms(sec):
|
|
28
45
|
h, sec = divmod(int(sec), 3600)
|
|
@@ -60,6 +77,8 @@ class _PanelContext:
|
|
|
60
77
|
return self.block
|
|
61
78
|
|
|
62
79
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
80
|
+
|
|
81
|
+
print('c')
|
|
63
82
|
delta = (datetime.now() - self.t0).total_seconds()
|
|
64
83
|
|
|
65
84
|
if self.block._progress:
|
|
@@ -73,7 +92,8 @@ class _PanelContext:
|
|
|
73
92
|
elif isinstance(exc_type, KeyboardInterrupt):
|
|
74
93
|
state = BlockState.INTERRUPTED
|
|
75
94
|
self.block_state._block_state = state
|
|
76
|
-
self.dag.
|
|
95
|
+
if not self.dag._is_pyodide:
|
|
96
|
+
self.dag._stopper.event.set()
|
|
77
97
|
if self.dag_logger:
|
|
78
98
|
self.dag_logger.exception(f'KEYBOARD INTERRUPT after {_hms(delta)}', block_name=self.block.name, block_state=state)
|
|
79
99
|
else:
|
|
@@ -88,13 +108,13 @@ class _PanelContext:
|
|
|
88
108
|
)
|
|
89
109
|
|
|
90
110
|
# msg = f'While in {self.block.name}.execute(): {exc_val}'
|
|
91
|
-
self.dag.
|
|
111
|
+
if not self.dag._is_pyodide:
|
|
112
|
+
self.dag._stopper.event.set()
|
|
92
113
|
|
|
93
114
|
if not issubclass(exc_type, BlockError):
|
|
94
115
|
# Convert the error in the block to a BlockError.
|
|
95
116
|
#
|
|
96
117
|
raise BlockError(f'Block {self.block.name}: {str(exc_val)}') from exc_val
|
|
97
|
-
|
|
98
118
|
return False
|
|
99
119
|
|
|
100
120
|
def _quit(session_context):
|
|
@@ -116,10 +136,8 @@ def interrupt_thread(tid, exctype):
|
|
|
116
136
|
#
|
|
117
137
|
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_ulong(tid), None)
|
|
118
138
|
raise SystemError('PyThreadState_SetAsyncExc failed')
|
|
119
|
-
|
|
120
|
-
def
|
|
121
|
-
"""Display the dag in a panel template."""
|
|
122
|
-
|
|
139
|
+
|
|
140
|
+
def _prepare_to_show(dag: Dag):
|
|
123
141
|
# Replace the default text-based context with the panel-based context.
|
|
124
142
|
#
|
|
125
143
|
dag._block_context = _PanelContext
|
|
@@ -220,10 +238,26 @@ def _show_dag(dag: Dag):
|
|
|
220
238
|
)
|
|
221
239
|
)
|
|
222
240
|
|
|
241
|
+
return template
|
|
242
|
+
|
|
243
|
+
def _show_dag(dag: Dag):
|
|
244
|
+
"""Display the dag in a panel template."""
|
|
245
|
+
|
|
246
|
+
template = _prepare_to_show(dag)
|
|
247
|
+
|
|
223
248
|
pn.state.on_session_destroyed(_quit)
|
|
224
249
|
|
|
225
250
|
template.show(threaded=False)
|
|
226
251
|
|
|
252
|
+
def _serveable_dag(dag: Dag):
|
|
253
|
+
"""Serve the dag in a panel template."""
|
|
254
|
+
|
|
255
|
+
template = _prepare_to_show(dag)
|
|
256
|
+
|
|
257
|
+
pn.state.on_session_destroyed(_quit)
|
|
258
|
+
|
|
259
|
+
template.servable()
|
|
260
|
+
|
|
227
261
|
class BlockCard(pn.Card):
|
|
228
262
|
"""A custom card to wrap around a block.
|
|
229
263
|
|
|
@@ -282,8 +316,9 @@ class BlockCard(pn.Card):
|
|
|
282
316
|
# current values on the queue.
|
|
283
317
|
# If their values are already there, it doesn't matter.
|
|
284
318
|
#
|
|
285
|
-
w.param.trigger(*w._block_out_params)
|
|
286
319
|
parent_template.main[0].loading = True
|
|
320
|
+
w.param.trigger(*w._block_out_params)
|
|
321
|
+
|
|
287
322
|
try:
|
|
288
323
|
if dag_logger:
|
|
289
324
|
dag_logger.info('', block_name=None, block_state=None)
|
|
@@ -306,10 +341,9 @@ class BlockCard(pn.Card):
|
|
|
306
341
|
pn.state.notifications.error(notif, duration=0)
|
|
307
342
|
finally:
|
|
308
343
|
parent_template.main[0].loading = False
|
|
309
|
-
|
|
310
344
|
c_button = pn.widgets.Button(name=w.continue_label, button_type='primary')
|
|
311
345
|
c_button.on_click(on_continue)
|
|
312
|
-
|
|
346
|
+
|
|
313
347
|
w_ = pn.Column(
|
|
314
348
|
w,
|
|
315
349
|
pn.Row(c_button, align='end'),
|
|
@@ -345,3 +379,6 @@ class PanelDag(Dag):
|
|
|
345
379
|
|
|
346
380
|
def show(self):
|
|
347
381
|
_show_dag(self)
|
|
382
|
+
|
|
383
|
+
def servable(self):
|
|
384
|
+
_serveable_dag(self)
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
sier2/__init__.py,sha256=t1dLAlWzyhcRxkH-lcmN4NmPFs1Z57iQ93HBO8Fcpmo,186
|
|
2
2
|
sier2/__main__.py,sha256=HZfzJLaD2_JOyKFkFYTD2vs-UARxNMjP4D7ZdJg405A,3140
|
|
3
3
|
sier2/_block.py,sha256=wEXIk5UtV7utYSUNzQuXshgkKg6dVb7SGm4E6tfoTmM,6590
|
|
4
|
-
sier2/_dag.py,sha256=
|
|
4
|
+
sier2/_dag.py,sha256=MVQB7Za-1f8zBIf1650IYqWQxiM9DzOPhudB8F_KS7M,21683
|
|
5
5
|
sier2/_library.py,sha256=aG1f6xHE2qtzvlFCgIp0cMXd6OKlkW_OvbQQb-b2l_8,7536
|
|
6
6
|
sier2/_logger.py,sha256=lwRmYjXMkP7TyURo5gvOf266vwGDFkLGau-EXpo5eEw,2379
|
|
7
7
|
sier2/_util.py,sha256=NmXI7QMSdkoSMe6EYJ-q8zI9iGJeMUto3g4314UVoM8,1932
|
|
8
8
|
sier2/_version.py,sha256=K5EdVMOTOHqhr-mIMjXhh84WHTSES2K-MJ_b--KryBM,71
|
|
9
9
|
sier2/panel/__init__.py,sha256=wDEf_v859flQX4udAVYZW1m79sfB1NIrI3pyNIpNiEM,29
|
|
10
10
|
sier2/panel/_feedlogger.py,sha256=tsrA8R2FZUecVY2egifVu2qosRfjccgvGRE0lLZSXZY,5270
|
|
11
|
-
sier2/panel/_panel.py,sha256=
|
|
11
|
+
sier2/panel/_panel.py,sha256=en9NytoJCbciR5v5iY_qjyTe3Mb_bUltteSFagaRolA,12968
|
|
12
12
|
sier2/panel/_panel_util.py,sha256=omcLO0OIHhH00l9YXv09Qv8lnaY6VKsQ1F0qbsrs3vk,2450
|
|
13
|
-
sier2-0.
|
|
14
|
-
sier2-0.
|
|
15
|
-
sier2-0.
|
|
16
|
-
sier2-0.
|
|
13
|
+
sier2-0.24.dist-info/LICENSE,sha256=2AKq0yxLLDdGsj6xQuNjDPG5d2IbFWFGiB_cnCBtMp4,1064
|
|
14
|
+
sier2-0.24.dist-info/METADATA,sha256=wFgF6qRM5OxUy-ZRr1IzOYKJY4wrtsbnZWscyTJJmNE,2492
|
|
15
|
+
sier2-0.24.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
16
|
+
sier2-0.24.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|