sier2 0.23__tar.gz → 0.24__tar.gz

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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sier2
3
- Version: 0.23
3
+ Version: 0.24
4
4
  Summary: Blocks of code that are executed in dags
5
5
  Author: algol60
6
6
  Author-email: algol60@users.noreply.github.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "sier2"
3
- version = "0.23"
3
+ version = "0.24"
4
4
  description = "Blocks of code that are executed in dags"
5
5
  authors = ["algol60 <algol60@users.noreply.github.com>"]
6
6
  readme = "README.rst"
@@ -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._stopper.event.set()
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._stopper.event.set()
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
- self._stopper = _Stopper()
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
- self._stopper.event.set()
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
- self._stopper.event.clear()
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._stopper.is_stopped:
294
- can_execute = False
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._stopper.event.set()
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.
@@ -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
- pn.extension('floatpanel', inline=True, nthreads=NTHREADS, loading_spinner='bar', notifications=True)
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._stopper.event.set()
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._stopper.event.set()
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):
@@ -296,8 +316,9 @@ class BlockCard(pn.Card):
296
316
  # current values on the queue.
297
317
  # If their values are already there, it doesn't matter.
298
318
  #
299
- w.param.trigger(*w._block_out_params)
300
319
  parent_template.main[0].loading = True
320
+ w.param.trigger(*w._block_out_params)
321
+
301
322
  try:
302
323
  if dag_logger:
303
324
  dag_logger.info('', block_name=None, block_state=None)
@@ -320,10 +341,9 @@ class BlockCard(pn.Card):
320
341
  pn.state.notifications.error(notif, duration=0)
321
342
  finally:
322
343
  parent_template.main[0].loading = False
323
-
324
344
  c_button = pn.widgets.Button(name=w.continue_label, button_type='primary')
325
345
  c_button.on_click(on_continue)
326
-
346
+
327
347
  w_ = pn.Column(
328
348
  w,
329
349
  pn.Row(c_button, align='end'),
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes