oocana-python-executor 0.16.1__tar.gz → 0.16.3__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.
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/PKG-INFO +1 -1
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/pyproject.toml +1 -1
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/block.py +2 -2
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/context.py +2 -2
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/executor.py +14 -6
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/matplot/oomol_matplot_helper.py +18 -7
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/service.py +1 -1
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/__init__.py +0 -0
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/data.py +0 -0
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/hook.py +0 -0
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/logger.py +0 -0
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/matplot/matplotlib_oomol/__init__.py +0 -0
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/matplot/matplotlib_oomol/oomol.py +0 -0
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/secret.py +0 -0
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/topic.py +0 -0
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/python_executor/utils.py +0 -0
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/tests/test_cli.py +0 -0
- {oocana_python_executor-0.16.1 → oocana_python_executor-0.16.3}/tests/test_secret.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: oocana-python-executor
|
|
3
|
-
Version: 0.16.
|
|
3
|
+
Version: 0.16.3
|
|
4
4
|
Summary: a client subscribe mqtt topic to execute oocana's block
|
|
5
5
|
Author-Email: l1shen <lishen1635@gmail.com>, yleaf <11785335+leavesster@users.noreply.github.com>
|
|
6
6
|
License: MIT
|
|
@@ -82,12 +82,12 @@ def output_return_object(obj, context: Context):
|
|
|
82
82
|
|
|
83
83
|
logger = logging.getLogger(EXECUTOR_NAME)
|
|
84
84
|
|
|
85
|
-
async def run_block(message, mainframe: Mainframe, session_dir: str, tmp_dir: str):
|
|
85
|
+
async def run_block(message, mainframe: Mainframe, session_dir: str, tmp_dir: str, package_name: str):
|
|
86
86
|
|
|
87
87
|
logger.info(f"block {message.get('job_id')} start")
|
|
88
88
|
try:
|
|
89
89
|
payload = ExecutePayload(**message)
|
|
90
|
-
context = createContext(mainframe, payload.session_id, payload.job_id, store, payload.outputs, session_dir, tmp_dir = tmp_dir)
|
|
90
|
+
context = createContext(mainframe, payload.session_id, payload.job_id, store, payload.outputs, session_dir, tmp_dir = tmp_dir, package_name=package_name)
|
|
91
91
|
except Exception:
|
|
92
92
|
traceback_str = traceback.format_exc()
|
|
93
93
|
# rust 那边会保证传过来的 message 一定是符合格式的,所以这里不应该出现异常。这里主要是防止 rust 修改错误。
|
|
@@ -9,7 +9,7 @@ from .data import EXECUTOR_NAME
|
|
|
9
9
|
logger = logging.getLogger(EXECUTOR_NAME)
|
|
10
10
|
|
|
11
11
|
def createContext(
|
|
12
|
-
mainframe: Mainframe, session_id: str, job_id: str, store, output, session_dir: str, tmp_dir: str
|
|
12
|
+
mainframe: Mainframe, session_id: str, job_id: str, store, output, session_dir: str, tmp_dir: str, package_name: str
|
|
13
13
|
) -> Context:
|
|
14
14
|
|
|
15
15
|
node_props = mainframe.notify_block_ready(session_id, job_id)
|
|
@@ -59,7 +59,7 @@ def createContext(
|
|
|
59
59
|
|
|
60
60
|
blockInfo = BlockInfo(**node_props)
|
|
61
61
|
|
|
62
|
-
ctx = Context(inputs, blockInfo, mainframe, store, output, session_dir, tmp_dir)
|
|
62
|
+
ctx = Context(inputs, blockInfo, mainframe, store, output, session_dir, tmp_dir, package_name=package_name)
|
|
63
63
|
# 跟 executor 日志分开,避免有的库在 logger 里面使用 print,导致 hook 出现递归调用。
|
|
64
64
|
block_logger = logging.getLogger(f"block {job_id}")
|
|
65
65
|
ctx_handler = ContextHandler(ctx)
|
|
@@ -49,7 +49,7 @@ def config_logger(session_id: str, identifier: str | None, output: Literal["cons
|
|
|
49
49
|
logger.propagate = False
|
|
50
50
|
|
|
51
51
|
|
|
52
|
-
async def run_executor(address: str, session_id: str, tmp_dir: str, package: str | None, session_dir: str, identifier: str | None = None):
|
|
52
|
+
async def run_executor(address: str, session_id: str, tmp_dir: str, package: str | None, session_dir: str, identifier: str | None = None, debug_port: int | None = None):
|
|
53
53
|
|
|
54
54
|
if identifier is not None:
|
|
55
55
|
mainframe = Mainframe(address, f"python-executor-id-{identifier}", logger)
|
|
@@ -72,6 +72,8 @@ async def run_executor(address: str, session_id: str, tmp_dir: str, package: str
|
|
|
72
72
|
elif os.path.exists("/app/workspace"):
|
|
73
73
|
sys.path.append("/app/workspace")
|
|
74
74
|
|
|
75
|
+
package_name = os.path.basename(package) if package is not None else "workspace"
|
|
76
|
+
|
|
75
77
|
|
|
76
78
|
def not_current_session(message):
|
|
77
79
|
return message.get("session_id") != session_id
|
|
@@ -144,7 +146,7 @@ async def run_executor(address: str, session_id: str, tmp_dir: str, package: str
|
|
|
144
146
|
mainframe.subscribe(exit_report_topic(), service_exit)
|
|
145
147
|
mainframe.subscribe(status_report_topic(), service_status)
|
|
146
148
|
|
|
147
|
-
mainframe.notify_executor_ready(session_id,
|
|
149
|
+
mainframe.notify_executor_ready(session_id, package, identifier, debug_port)
|
|
148
150
|
|
|
149
151
|
async def spawn_service(message: ServiceExecutePayload, service_hash: str):
|
|
150
152
|
logger.info(f"create new service {message.get('dir')}")
|
|
@@ -211,12 +213,12 @@ async def run_executor(address: str, session_id: str, tmp_dir: str, package: str
|
|
|
211
213
|
else:
|
|
212
214
|
if not_current_session(message):
|
|
213
215
|
continue
|
|
214
|
-
run_block_in_new_thread(message, mainframe, session_dir=session_dir, tmp_dir=tmp_dir)
|
|
216
|
+
run_block_in_new_thread(message, mainframe, session_dir=session_dir, tmp_dir=tmp_dir, package_name=package_name)
|
|
215
217
|
|
|
216
|
-
def run_block_in_new_thread(message, mainframe: Mainframe, session_dir: str, tmp_dir: str):
|
|
218
|
+
def run_block_in_new_thread(message, mainframe: Mainframe, session_dir: str, tmp_dir: str, package_name: str):
|
|
217
219
|
|
|
218
220
|
async def run():
|
|
219
|
-
await run_block(message, mainframe, session_dir=session_dir, tmp_dir=tmp_dir)
|
|
221
|
+
await run_block(message, mainframe, session_dir=session_dir, tmp_dir=tmp_dir, package_name=package_name)
|
|
220
222
|
run_in_new_thread(run)
|
|
221
223
|
|
|
222
224
|
def main():
|
|
@@ -254,6 +256,7 @@ def main():
|
|
|
254
256
|
if len(unknown_args) > 0:
|
|
255
257
|
logger.warning(f"receive unknown args: {unknown_args}")
|
|
256
258
|
|
|
259
|
+
debug_port = None
|
|
257
260
|
if namespace.debug_port is not None and namespace.debug_port.isdigit():
|
|
258
261
|
try:
|
|
259
262
|
import debugpy
|
|
@@ -263,12 +266,17 @@ def main():
|
|
|
263
266
|
logger.info("wait for client to connect")
|
|
264
267
|
debugpy.wait_for_client()
|
|
265
268
|
logger.info("client connected")
|
|
269
|
+
debug_port = int(namespace.debug_port)
|
|
266
270
|
except ImportError:
|
|
267
271
|
logger.warning("Warning: debugpy not installed, debugging functionality will not be available")
|
|
272
|
+
debug_port = None
|
|
268
273
|
except Exception as e:
|
|
269
274
|
logger.warning(f"Warning: debugpy listen failed: {e}")
|
|
275
|
+
debug_port = None
|
|
276
|
+
else:
|
|
277
|
+
debug_port = None
|
|
270
278
|
|
|
271
|
-
run_async_code(run_executor(address=address, tmp_dir=tmp_dir, session_id=session_id, package=package, session_dir=session_dir, identifier=identifier))
|
|
279
|
+
run_async_code(run_executor(address=address, tmp_dir=tmp_dir, session_id=session_id, package=package, session_dir=session_dir, identifier=identifier, debug_port=debug_port))
|
|
272
280
|
|
|
273
281
|
if __name__ == '__main__':
|
|
274
282
|
main()
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
from python_executor.data import block_var
|
|
2
|
+
from logging import Logger
|
|
3
|
+
|
|
4
|
+
__all__ = ["add_matplot_module", "import_helper"]
|
|
2
5
|
|
|
3
6
|
def add_matplot_module():
|
|
4
7
|
import sys
|
|
@@ -6,13 +9,14 @@ def add_matplot_module():
|
|
|
6
9
|
dir = os.path.dirname(os.path.abspath(__file__))
|
|
7
10
|
sys.path.insert(0, dir)
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
|
|
13
|
+
def setup_matplot(logger: Logger):
|
|
10
14
|
# matplotlib 的 use() 替换
|
|
11
15
|
try:
|
|
12
16
|
import matplotlib # type: ignore
|
|
13
17
|
matplotlib.use('module://matplotlib_oomol') # matplotlib_oomol.py 文件所在目录加入 PYTHONPATH
|
|
14
|
-
except:
|
|
15
|
-
logger.
|
|
18
|
+
except Exception as e:
|
|
19
|
+
logger.warning("import matplotlib failed", e)
|
|
16
20
|
return
|
|
17
21
|
|
|
18
22
|
# matplotlib 主题替换
|
|
@@ -21,9 +25,11 @@ def import_helper(logger):
|
|
|
21
25
|
import matplotlib.pyplot as plt # type: ignore
|
|
22
26
|
plt.style.use("classic" if os.getenv("OOMOL_COLOR_SCHEME", "dark") == "light" else "dark_background")
|
|
23
27
|
plt.rcParams['font.sans-serif'] = ['Source Han Sans SC']
|
|
24
|
-
except:
|
|
25
|
-
|
|
28
|
+
except Exception as e:
|
|
29
|
+
logger.warning("matplotlib theme setup failed", e)
|
|
30
|
+
|
|
26
31
|
|
|
32
|
+
def setup_plotly(logger: Logger):
|
|
27
33
|
# plotly 的 show() 替换
|
|
28
34
|
try:
|
|
29
35
|
import os
|
|
@@ -65,5 +71,10 @@ def import_helper(logger):
|
|
|
65
71
|
|
|
66
72
|
renderers['oomol'] = OomolRenderer()
|
|
67
73
|
renderers.default = 'oomol'
|
|
68
|
-
except:
|
|
69
|
-
logger.warning("import plotly failed")
|
|
74
|
+
except Exception as e:
|
|
75
|
+
logger.warning("import plotly failed", e)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def import_helper(logger: Logger):
|
|
79
|
+
setup_matplot(logger)
|
|
80
|
+
setup_plotly(logger)
|
|
@@ -179,7 +179,7 @@ class ServiceRuntime(ServiceContextAbstractClass):
|
|
|
179
179
|
self._runningBlocks.add(job_id)
|
|
180
180
|
self._jobs.add(job_id)
|
|
181
181
|
|
|
182
|
-
context = createContext(self._mainframe, payload["session_id"], payload["job_id"], self._store, payload["outputs"], self._session_dir, tmp_dir=self._session_dir) # TODO: tmp_dir need consider global service.
|
|
182
|
+
context = createContext(self._mainframe, payload["session_id"], payload["job_id"], self._store, payload["outputs"], self._session_dir, tmp_dir=self._session_dir, package_name=service_hash) # TODO: tmp_dir need consider global service.
|
|
183
183
|
|
|
184
184
|
if isinstance(self.block_handler, dict):
|
|
185
185
|
handler = self.block_handler.get(block_name)
|
|
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
|
|
File without changes
|