kcl-lib 0.12.2__cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.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.
@@ -0,0 +1,3 @@
1
+ from .plugin import Plugin, register_plugin, plugin_agent_addr
2
+
3
+ __all__ = ["Plugin", "register_plugin", "plugin_agent_addr"]
@@ -0,0 +1,82 @@
1
+ import json
2
+ import typing
3
+ from ctypes import *
4
+ from dataclasses import dataclass
5
+
6
+
7
+ @dataclass
8
+ class Plugin:
9
+ name: str
10
+ method_map: typing.Dict[str, typing.Callable]
11
+
12
+
13
+ class PluginContext:
14
+ def __init__(self):
15
+ self._plugin_dict: typing.Dict[str, Plugin] = {}
16
+
17
+ def call_method(self, name: str, args_json: str, kwargs_json: str) -> str:
18
+ return self._call_py_method(name, args_json, kwargs_json)
19
+
20
+ def _call_py_method(self, name: str, args_json: str, kwargs_json: str) -> str:
21
+ try:
22
+ return self._call_py_method_unsafe(name, args_json, kwargs_json)
23
+ except Exception as e:
24
+ return json.dumps({"__kcl_PanicInfo__": f"{e}"})
25
+
26
+ def _call_py_method_unsafe(
27
+ self, name: str, args_json: str, kwargs_json: str
28
+ ) -> str:
29
+ dotIdx = name.rfind(".")
30
+ if dotIdx < 0:
31
+ return ""
32
+
33
+ # kcl_plugin.<module_path>.<method_name>
34
+ module_path = name[:dotIdx]
35
+ method_name = name[dotIdx + 1 :]
36
+ plugin_name = module_path[module_path.rfind(".") + 1 :]
37
+
38
+ method_func = self._plugin_dict.get(
39
+ plugin_name, Plugin(name="", method_map={})
40
+ ).method_map.get(method_name, None)
41
+
42
+ args = []
43
+ kwargs = {}
44
+
45
+ if args_json:
46
+ args = json.loads(args_json)
47
+ if not isinstance(args, list):
48
+ return ""
49
+
50
+ if kwargs_json:
51
+ kwargs = json.loads(kwargs_json)
52
+ if not isinstance(kwargs, dict):
53
+ return ""
54
+
55
+ result = method_func(*args, **kwargs) if method_func else None
56
+ return json.dumps(result)
57
+
58
+
59
+ __plugin_context__ = PluginContext()
60
+ __plugin_method_agent_buffer__ = create_string_buffer(1024)
61
+
62
+
63
+ def register_plugin(
64
+ name: str, method_map: typing.Dict[str, typing.Callable]
65
+ ) -> c_char_p:
66
+ __plugin_context__._plugin_dict[name] = Plugin(name, method_map)
67
+
68
+
69
+ @CFUNCTYPE(c_char_p, c_char_p, c_char_p, c_char_p)
70
+ def plugin_method_agent(method: str, args_json: str, kwargs_json: str) -> c_char_p:
71
+ method = str(method, encoding="utf-8")
72
+ args_json = str(args_json, encoding="utf-8")
73
+ kwargs_json = str(kwargs_json, encoding="utf-8")
74
+
75
+ json_result = __plugin_context__.call_method(method, args_json, kwargs_json)
76
+
77
+ global __plugin_method_agent_buffer__
78
+ __plugin_method_agent_buffer__ = create_string_buffer(json_result.encode("utf-8"))
79
+ return addressof(__plugin_method_agent_buffer__)
80
+
81
+
82
+ plugin_agent_addr = cast(plugin_method_agent, c_void_p).value
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.4
2
+ Name: kcl_lib
3
+ Version: 0.12.2
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
7
+ Requires-Dist: protobuf>=6.33.1
8
+ Requires-Dist: pdoc ; extra == 'docs'
9
+ Requires-Dist: ruff ; extra == 'lint'
10
+ Requires-Dist: pytest ; extra == 'test'
11
+ Provides-Extra: docs
12
+ Provides-Extra: lint
13
+ Provides-Extra: test
14
+ Summary: KCL Programming Language Python Lib
15
+ License: Apache-2.0
16
+ Requires-Python: >=3.7
17
+ Project-URL: Documentation, https://kcl-lang.io
18
+ Project-URL: Homepage, https://kcl-lang.io
19
+ Project-URL: Repository, https://github.com/kcl-lang/kcl
@@ -0,0 +1,11 @@
1
+ kcl_lib-0.12.2.dist-info/METADATA,sha256=f6z3YXCGFqOMl-yMI9y_7fHrKjPGoLaWlGDhYqOAcKc,681
2
+ kcl_lib-0.12.2.dist-info/WHEEL,sha256=vLuciupqNeFiT_BM3X2FEnuMXxwTX2LGE0wz2PyGEtI,145
3
+ kcl_lib/__init__.py,sha256=3EKn2Bb6NvoajnhLym-yQiobUBgdnj46bhe5u_GYo5A,24
4
+ kcl_lib/_kcl_lib.cpython-38-aarch64-linux-gnu.so,sha256=xboBXDmUXejHMc56sTWWkO6-OROffF0IumFvw7cnS30,23463504
5
+ kcl_lib/api/__init__.py,sha256=iB8eYHqS-E1R-mVeuie3dXjLx5CgY-erlLuOI0zHTbo,2775
6
+ kcl_lib/api/service.py,sha256=xJpRoJ0DdtTM5vgKFVcIhQalUWF-W4jqBZuCHgq0vYk,22600
7
+ kcl_lib/api/spec_pb2.py,sha256=-ZXQbRvbgBvldJySSoiasF5hfMNRxg1kFWrNI1Evcc8,30195
8
+ kcl_lib/api/spec_pb2.pyi,sha256=C-0wFGMnsH0E8hBTzjV0hutT6S7tqShPSl9RIpbTZro,39366
9
+ kcl_lib/plugin/__init__.py,sha256=8n67HzfKI8I2E-OWZmE68ZRh88Jzq-Pc61qAmCdMUj8,125
10
+ kcl_lib/plugin/plugin.py,sha256=shHQS4atDxfctMOinoSUOO6Z568P9xB7BoT_aNn-xOw,2505
11
+ kcl_lib-0.12.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.10.2)
3
+ Root-Is-Purelib: false
4
+ Tag: cp38-cp38-manylinux_2_17_aarch64
5
+ Tag: cp38-cp38-manylinux2014_aarch64