happyscript 0.0.8__tar.gz → 0.0.9__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.
Files changed (48) hide show
  1. {happyscript-0.0.8 → happyscript-0.0.9}/PKG-INFO +1 -1
  2. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/__init__.py +1 -1
  3. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/scriptcontrol.py +8 -11
  4. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/scriptgui.py +15 -0
  5. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/scriptmanager.py +1 -1
  6. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/scriptparams.py +1 -0
  7. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/scriptrunner.py +64 -17
  8. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript.egg-info/PKG-INFO +1 -1
  9. {happyscript-0.0.8 → happyscript-0.0.9}/pyproject.toml +1 -1
  10. {happyscript-0.0.8 → happyscript-0.0.9}/README.md +0 -0
  11. {happyscript-0.0.8 → happyscript-0.0.9}/copy_code.py +0 -0
  12. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/charts/__init__.py +0 -0
  13. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/charts/chart.py +0 -0
  14. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/charts/histogram_chart.py +0 -0
  15. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/charts/histogram_series.py +0 -0
  16. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/charts/matplotlib_chart.py +0 -0
  17. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/charts/panel_charts.py +0 -0
  18. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/charts/scatter_chart.py +0 -0
  19. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/charts/scatter_series.py +0 -0
  20. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/charts/time_chart.py +0 -0
  21. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/charts/time_series.py +0 -0
  22. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/forms/form_askchoice.py +0 -0
  23. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/forms/form_askimage.py +0 -0
  24. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/forms/form_main.py +0 -0
  25. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/forms/form_ontestfailure.py +0 -0
  26. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/forms/form_serials.py +0 -0
  27. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/forms/form_stop.py +0 -0
  28. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/forms/formsbase.py +0 -0
  29. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/imglib.py +0 -0
  30. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/panels/panel_log.py +0 -0
  31. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/panels/panel_messages.py +0 -0
  32. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/panels/panel_scripts2.py +0 -0
  33. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/panels/panel_tests.py +0 -0
  34. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/panels/panelsbase.py +0 -0
  35. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/scriptartwork.py +0 -0
  36. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/scriptexceptions.py +0 -0
  37. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/scriptinfo.py +0 -0
  38. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/scriptreader.py +0 -0
  39. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/testlog/global_log_handler.py +0 -0
  40. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/testlog/log_to_text.py +0 -0
  41. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/testlog/logtoxml.py +0 -0
  42. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript/testlog/printredirect.py +0 -0
  43. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript.egg-info/SOURCES.txt +0 -0
  44. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript.egg-info/dependency_links.txt +0 -0
  45. {happyscript-0.0.8 → happyscript-0.0.9}/happyscript.egg-info/top_level.txt +0 -0
  46. {happyscript-0.0.8 → happyscript-0.0.9}/increment_version.py +0 -0
  47. {happyscript-0.0.8 → happyscript-0.0.9}/publish.bat +0 -0
  48. {happyscript-0.0.8 → happyscript-0.0.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: happyscript
3
- Version: 0.0.8
3
+ Version: 0.0.9
4
4
  Summary: Framework for running scripts
5
5
  Requires-Python: >=3.5
6
6
  Description-Content-Type: text/markdown
@@ -1,2 +1,2 @@
1
- __version__ = "0.0.8"
1
+ __version__ = "0.0.9"
2
2
  from .scriptmanager import ScriptManager
@@ -1,11 +1,12 @@
1
- import wx
2
1
  import time
3
2
  from .scriptexceptions import ScriptUserAbortException
4
3
  class ScriptControl:
5
4
  def __init__(self):
6
5
  self.m_stop_script = False
7
6
  self._is_busy = False
8
- self.on_run_script = None
7
+ self._script_runner = None
8
+ def set_script_runner(self, runner):
9
+ self._script_runner = runner
9
10
  def set_busy(self, is_busy):
10
11
  self._is_busy = is_busy
11
12
  self.m_stop_script = False
@@ -18,26 +19,22 @@ class ScriptControl:
18
19
  print("Normally no script is active, but I'll set the 'stop' flag anyway.")
19
20
  self.m_stop_script = True
20
21
  def ok(self):
21
- wx.Yield()
22
22
  return not self.m_stop_script
23
23
  def check(self):
24
- wx.Yield()
25
24
  if self.m_stop_script:
26
25
  raise ScriptUserAbortException( "Script stopping on user request" )
27
26
  def sleep(self, time_in_seconds):
28
27
  t = time_in_seconds
29
- wx.Yield()
30
28
  while t>0:
31
29
  if t > 0.5:
32
30
  time.sleep(0.5)
33
31
  else:
34
32
  time.sleep(t)
35
- t = t-0.5;
36
- wx.Yield()
33
+ t = t-0.5
37
34
  if self.m_stop_script:
38
35
  raise ScriptUserAbortException( "Script stopping on user request" )
39
36
  def run(self, script_name, **argv):
40
- if self.on_run_script is None:
41
- raise ScriptUserAbortException( "Cannot start script : no callback function is set." )
42
- else:
43
- return self.on_run_script(script_name, **argv)
37
+ assert self._script_runner is not None, "Internal error: scriptrunner is not set"
38
+ return self._script_runner.run_script(script_name, **argv)
39
+ def run_parallel(self, func, parname, parvalues, **extra_params):
40
+ return self._script_runner.run_parallel(func, parname, parvalues, **extra_params)
@@ -29,6 +29,7 @@ class ScriptGui:
29
29
  raise self.__reply
30
30
  return self.__reply
31
31
  def do_func(self, func, *params):
32
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
32
33
  if func is None or not callable(func):
33
34
  raise Exception("Given function to execute is not something callable.")
34
35
  if threading.currentThread().getName()=="ScriptThread":
@@ -36,6 +37,7 @@ class ScriptGui:
36
37
  else:
37
38
  return func(*params)
38
39
  def ask(self, message, default_value="" ):
40
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
39
41
  if threading.currentThread().getName()=="ScriptThread":
40
42
  return self.__run_with_timer(self.ask, message, default_value )
41
43
  result = None
@@ -47,6 +49,7 @@ class ScriptGui:
47
49
  raise ScriptUserAbortException( "User did not provide value in dialog" )
48
50
  return result
49
51
  def ask_number(self, message, default_value=None ):
52
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
50
53
  if threading.currentThread().getName()=="ScriptThread":
51
54
  return self.__run_with_timer(self.ask_number, message, default_value )
52
55
  result = None
@@ -69,6 +72,7 @@ class ScriptGui:
69
72
  raise ScriptUserAbortException( "User did not provide value in dialog" )
70
73
  return result
71
74
  def ask_yesno(self, message, cancel = False):
75
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
72
76
  if threading.currentThread().getName()=="ScriptThread":
73
77
  return self.__run_with_timer(self.ask_yesno, message, cancel )
74
78
  style = wx.YES_NO|wx.CANCEL if cancel else wx.YES_NO
@@ -81,6 +85,7 @@ class ScriptGui:
81
85
  return False
82
86
  raise ScriptUserAbortException( "User did not answer yes/no dialog" )
83
87
  def ask_image(self, message, filename, arrow_pos=None, yesno=False, cancel=False, numeric=False):
88
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
84
89
  if threading.currentThread().getName()=="ScriptThread":
85
90
  return self.__run_with_timer(self.ask_image, message, filename, arrow_pos, yesno, cancel, numeric )
86
91
  form = FormAskImage(message, filename, arrow_pos, yesno, cancel, numeric )
@@ -91,6 +96,7 @@ class ScriptGui:
91
96
  form.Destroy()
92
97
  return result
93
98
  def ask_choice(self, message, choices, do_assert = True):
99
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
94
100
  if threading.currentThread().getName()=="ScriptThread":
95
101
  return self.__run_with_timer(self.ask_choice, message, choices )
96
102
  form = FormAskChoice(message, choices )
@@ -102,6 +108,7 @@ class ScriptGui:
102
108
  form.Destroy()
103
109
  return result
104
110
  def ask_open_file(self, message, wildcard):
111
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
105
112
  if threading.currentThread().getName() == "ScriptThread":
106
113
  return self.__run_with_timer(self.ask_open_file, message, wildcard)
107
114
  style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
@@ -111,6 +118,7 @@ class ScriptGui:
111
118
  return None
112
119
  return dlg.GetPath()
113
120
  def show_stop_dialog(self, message=None ):
121
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
114
122
  if threading.currentThread().getName() == "ScriptThread":
115
123
  return self.__run_with_timer(self.show_stop_dialog, message)
116
124
  if message is None:
@@ -121,6 +129,7 @@ class ScriptGui:
121
129
  self.m_stop_dialog.update_message(message)
122
130
  self.m_stop_dialog.Show()
123
131
  def close_stop_dialog(self):
132
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
124
133
  if self.m_stop_dialog is None:
125
134
  return
126
135
  if threading.currentThread().getName() == "ScriptThread":
@@ -128,24 +137,30 @@ class ScriptGui:
128
137
  self.m_stop_dialog.Destroy()
129
138
  self.m_stop_dialog = None
130
139
  def add_scatter_chart(self, name):
140
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
131
141
  if threading.currentThread().getName() == "ScriptThread":
132
142
  return self.__run_with_timer(self.add_scatter_chart, name)
133
143
  return self._mngr.charts.add_scatter_chart(name)
134
144
  def add_time_chart(self, name):
145
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
135
146
  if threading.currentThread().getName() == "ScriptThread":
136
147
  return self.__run_with_timer(self.add_time_chart, name)
137
148
  return self._mngr.charts.add_time_chart(name)
138
149
  def add_histogram(self, name, binsize):
150
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
139
151
  if threading.currentThread().getName() == "ScriptThread":
140
152
  return self.__run_with_timer(self.add_histogram, name, binsize)
141
153
  return self._mngr.charts.add_histogram(name, binsize)
142
154
  def add_matplotlib(self, name):
155
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
143
156
  if threading.currentThread().getName() == "ScriptThread":
144
157
  return self.__run_with_timer(self.add_matplotlib, name)
145
158
  return self._mngr.charts.add_matplotlib(name)
146
159
  def get_chart(self, name):
160
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
147
161
  return self._mngr.charts.get_chart(name)
148
162
  def delete_chart(self, name):
163
+ assert not threading.currentThread().getName().startswith("Parallel"), "GUI functions cannot be called from a parallel thread"
149
164
  if threading.currentThread().getName() == "ScriptThread":
150
165
  return self.__run_with_timer(self.delete_chart, name)
151
166
  self._mngr.charts.delete_chart(name)
@@ -63,7 +63,7 @@ class ScriptManager(object):
63
63
  self._script_params.on_add_object = self._on_add_object
64
64
  self._script_readers = dict()
65
65
  self._script_runner = ScriptRunner(self._script_params, self._script_readers, self.ctrl)
66
- self.ctrl.on_run_script = self._script_runner.run_script
66
+ self.ctrl.set_script_runner( self._script_runner )
67
67
  self._script_params.add_objects( ctrl=self.ctrl, gui=self.gui, info=self.info )
68
68
  self.dialog.pnlTests.on_sequence_start_callback = self.handle_batch_start
69
69
  self.dialog.pnlTests.on_sequence_end_callback = self.handle_batch_end
@@ -56,6 +56,7 @@ class ScriptParams(object):
56
56
  missing.append(x)
57
57
  return (argvalues, missing)
58
58
  def _find_missing_parameter(self, paramName, docTxt ):
59
+ if docTxt is None: return None
59
60
  result = None
60
61
  lines = docTxt.splitlines()
61
62
  for line in lines:
@@ -2,7 +2,7 @@ import datetime, logging, threading
2
2
  from .scriptexceptions import ScriptUserAbortException
3
3
  from .scriptexceptions import ScriptRecursiveAbortException
4
4
  class ScriptThreadRunner:
5
- logger = logging.getLogger("happyscript.runner")
5
+ logger = logging.getLogger("happyscript.scriptrunner")
6
6
  MARKER_LEVEL = 25
7
7
  def __init__(self, ctrl):
8
8
  self._ctrl = ctrl
@@ -56,6 +56,29 @@ class ScriptThreadRunner:
56
56
  self.last_result = test_passed
57
57
  self._ctrl.set_busy(False)
58
58
  self.busy = False
59
+ class ScriptParallelThread(threading.Thread):
60
+ thread_counter = 0
61
+ def __init__(self, ctrl, func, arg_list):
62
+ thread_name = "Parallel" + str(ScriptParallelThread.thread_counter)
63
+ threading.Thread.__init__(self, name=thread_name)
64
+ ScriptParallelThread.thread_counter += 1
65
+ self._ctrl = ctrl
66
+ self.the_func = func
67
+ self.arg_list = arg_list
68
+ self.success = False
69
+ self.stopped_by_user = False
70
+ self.start()
71
+ def run(self):
72
+ try:
73
+ self.the_func( *self.arg_list )
74
+ self.success = True
75
+ except ScriptUserAbortException as _:
76
+ pass
77
+ except Exception as e:
78
+ if self._ctrl.m_stop_script:
79
+ self.stopped_by_user = True
80
+ else:
81
+ logging.error(str(e), exc_info = e)
59
82
  class ScriptRunner:
60
83
  logger = logging.getLogger("happyscript.runner")
61
84
  def __init__(self, script_params, script_readers, script_control):
@@ -63,6 +86,7 @@ class ScriptRunner:
63
86
  self._readers = script_readers
64
87
  self._recurse_count = 0
65
88
  self.start_ok = False
89
+ self._ctrl = script_control
66
90
  self.thread_runner = ScriptThreadRunner(script_control)
67
91
  @property
68
92
  def test_passed(self):
@@ -70,29 +94,52 @@ class ScriptRunner:
70
94
  @property
71
95
  def busy(self):
72
96
  return self.thread_runner.busy
73
- def run_script(self, script_name, **argv):
97
+ def find_scriptfunct(self, script_name):
74
98
  parts = script_name.split(".")
75
99
  if len(parts) != 3:
76
100
  self.logger.error("Must provide script name as dirname.filename.scriptname")
77
- return
78
- self.start_script(parts[0], parts[1], parts[2], **argv)
79
- def start_script(self, group_name, filename, funcname, **extra_params):
80
- self.start_ok = False
81
- scriptname = "%s.%s.%s" % (group_name, filename, funcname)
82
- if not group_name in self._readers:
83
- self.logger.error("Cannot start %s : group %s not found" % (scriptname, group_name))
84
- return
85
- func = self._readers[group_name].get_func(filename, funcname)
101
+ return None
102
+ if not parts[0] in self._readers:
103
+ self.logger.error("Cannot start %s : group %s not found", script_name, parts[0])
104
+ return None
105
+ func = self._readers[parts[0]].get_func(parts[1], parts[2])
86
106
  if func is None:
87
- self.logger.error("Cannot start %s : function not found" % scriptname)
107
+ self.logger.error("Cannot start %s : function not found", script_name)
108
+ return func
109
+ def run_script(self, script_name, **extra_params):
110
+ self.start_ok = False
111
+ if threading.currentThread().getName().startswith("Parallel"):
112
+ self.logger.error("You cannot start other scripts in a parallel thread.")
88
113
  return
89
- if (extra_params is None) or (not isinstance(extra_params,dict)):
90
- extra_params = dict()
114
+ func = self.find_scriptfunct(script_name)
115
+ if func is None: return
91
116
  (argvalues, missing) = self.script_params.get_parameters(func, extra_params)
92
117
  if len(missing)>0:
93
118
  self.logger.error( "Error : missing value for parameter(s) %s" % ("".join(missing) ) )
94
- self.logger.error( " Make sure to use valid names as parameters for your function.")
95
- self.logger.log(self.MARKER_LEVEL, "\\_________%s_________ ERROR ______/" % scriptname )
96
119
  return
97
- self.thread_runner.execute_script(scriptname, func, argvalues)
120
+ self.thread_runner.execute_script(script_name, func, argvalues)
98
121
  self.start_ok = True
122
+ def run_parallel(self, func, parname, parvalues, **extra_params):
123
+ assert threading.currentThread().getName()=="ScriptThread", "run_parallel() can only be executed from within a (non-parallel) script function"
124
+ if not callable(func):
125
+ func = self.find_scriptfunct(func)
126
+ assert func is not None, f"Parameter 'func' of run_parallel is no function or script name."
127
+ threads = list()
128
+ for val in parvalues:
129
+ extra_params[parname] = val
130
+ (argvalues, missing) = self.script_params.get_parameters(func, extra_params)
131
+ if len(missing)>0:
132
+ self.logger.error( "Error : missing value for parameter(s) %s" % ("".join(missing) ) )
133
+ return
134
+ threads.append( ScriptParallelThread(self._ctrl, func, argvalues) )
135
+ fail_count = 0
136
+ stopped_by_user = 0
137
+ for thread in threads:
138
+ thread.join()
139
+ if not thread.success:
140
+ fail_count += 1
141
+ if thread.stopped_by_user:
142
+ stopped_by_user += 1
143
+ if stopped_by_user>0:
144
+ self.logger.error(f"{stopped_by_user} scripts stopped by user")
145
+ assert fail_count==0, f"Parallel executiong failed on {fail_count} threads"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: happyscript
3
- Version: 0.0.8
3
+ Version: 0.0.9
4
4
  Summary: Framework for running scripts
5
5
  Requires-Python: >=3.5
6
6
  Description-Content-Type: text/markdown
@@ -17,7 +17,7 @@ build-backend = "setuptools.build_meta"
17
17
  [project]
18
18
  name = "happyscript"
19
19
  description = "Framework for running scripts"
20
- version = "0.0.8"
20
+ version = "0.0.9"
21
21
  readme = "README.md"
22
22
  requires-python = ">=3.5"
23
23
  dependencies = [ ]
File without changes
File without changes
File without changes
File without changes