pykardia 0.1.0.dev1__tar.gz → 0.2.0__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 (106) hide show
  1. {pykardia-0.1.0.dev1/pykardia.egg-info → pykardia-0.2.0}/PKG-INFO +17 -5
  2. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/README.md +13 -3
  3. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/config.py +1 -0
  4. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/fiber.py +13 -0
  5. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/json.py +1 -0
  6. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/state.py +16 -0
  7. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/value.py +1 -0
  8. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/wire.py +1 -0
  9. pykardia-0.2.0/pykardia/guest/LICENSE-APACHE +176 -0
  10. pykardia-0.2.0/pykardia/guest/LICENSE-MIT +21 -0
  11. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/guest/__init__.py +1 -0
  12. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/guest/abi.py +1 -0
  13. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/guest/api.py +24 -0
  14. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/guest/export.py +13 -3
  15. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/guest/meta.py +1 -0
  16. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/guest/native.py +29 -1
  17. pykardia-0.2.0/pykardia/guest/process.py +163 -0
  18. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/guest/runtime.py +1 -0
  19. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/guest/templates/wasm.c +10 -0
  20. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/guest/wasm_build.py +2 -1
  21. pykardia-0.2.0/pykardia/hmr/__init__.py +77 -0
  22. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/hmr/dylib.py +29 -22
  23. pykardia-0.2.0/pykardia/hmr/exit.py +134 -0
  24. pykardia-0.2.0/pykardia/hmr/guest.py +524 -0
  25. pykardia-0.2.0/pykardia/hmr/pipes.py +317 -0
  26. pykardia-0.2.0/pykardia/hmr/process.py +408 -0
  27. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/hmr/wasm.py +41 -32
  28. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/version.py +1 -1
  29. {pykardia-0.1.0.dev1 → pykardia-0.2.0/pykardia.egg-info}/PKG-INFO +17 -5
  30. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia.egg-info/SOURCES.txt +4 -0
  31. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pyproject.toml +3 -3
  32. pykardia-0.1.0.dev1/pykardia/guest/process.py +0 -91
  33. pykardia-0.1.0.dev1/pykardia/hmr/__init__.py +0 -37
  34. pykardia-0.1.0.dev1/pykardia/hmr/guest.py +0 -292
  35. pykardia-0.1.0.dev1/pykardia/hmr/process.py +0 -170
  36. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/LICENSE +0 -0
  37. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/NOTICE +0 -0
  38. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/__init__.py +0 -0
  39. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/__main__.py +0 -0
  40. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/catalog.py +0 -0
  41. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/cli.py +0 -0
  42. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/__init__.py +0 -0
  43. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/cleanup.py +0 -0
  44. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/context.py +0 -0
  45. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/deps.py +0 -0
  46. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/effect.py +0 -0
  47. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/error.py +0 -0
  48. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/events.py +0 -0
  49. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/id_table.py +0 -0
  50. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/key.py +0 -0
  51. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/logger.py +0 -0
  52. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/plugin.py +0 -0
  53. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/registry.py +0 -0
  54. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/root.py +0 -0
  55. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/runtime.py +0 -0
  56. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/scope.py +0 -0
  57. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/service.py +0 -0
  58. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/core/status.py +0 -0
  59. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/decorators.py +0 -0
  60. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/fs/__init__.py +0 -0
  61. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/fs/filter.py +0 -0
  62. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/fs/glob.py +0 -0
  63. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/fs/native.py +0 -0
  64. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/fs/service.py +0 -0
  65. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/fs/watcher.py +0 -0
  66. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/hmr/graph.py +0 -0
  67. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/hmr/hmr.py +0 -0
  68. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/hmr/transaction.py +0 -0
  69. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/hmr/watch.py +0 -0
  70. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/include/__init__.py +0 -0
  71. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/include/document.py +0 -0
  72. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/include/identity.py +0 -0
  73. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/include/include.py +0 -0
  74. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/include/journal.py +0 -0
  75. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/include/patch.py +0 -0
  76. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/include/tree.py +0 -0
  77. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/include/yaml.py +0 -0
  78. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/loader/__init__.py +0 -0
  79. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/loader/_unicode.py +0 -0
  80. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/loader/backend.py +0 -0
  81. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/loader/catalog.py +0 -0
  82. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/loader/expr.py +0 -0
  83. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/loader/group.py +0 -0
  84. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/loader/handles.py +0 -0
  85. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/loader/loader.py +0 -0
  86. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/loader/options.py +0 -0
  87. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/loader/state.py +0 -0
  88. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/logger_console/__init__.py +0 -0
  89. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/logger_console/config.py +0 -0
  90. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/logger_console/exporter.py +0 -0
  91. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/logger_console/format.py +0 -0
  92. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/logger_console/plugin.py +0 -0
  93. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/prelude.py +0 -0
  94. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/py.typed +0 -0
  95. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/timer/__init__.py +0 -0
  96. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/timer/context.py +0 -0
  97. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/timer/schedule.py +0 -0
  98. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/timer/service.py +0 -0
  99. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia/timer/ticks.py +0 -0
  100. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia.egg-info/dependency_links.txt +0 -0
  101. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia.egg-info/entry_points.txt +0 -0
  102. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia.egg-info/requires.txt +0 -0
  103. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/pykardia.egg-info/top_level.txt +0 -0
  104. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/setup.cfg +0 -0
  105. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/tests/test_architecture.py +0 -0
  106. {pykardia-0.1.0.dev1 → pykardia-0.2.0}/tests/test_cli.py +0 -0
@@ -1,12 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pykardia
3
- Version: 0.1.0.dev1
3
+ Version: 0.2.0
4
4
  Summary: Plugin framework with revertible effects and reactive services
5
- License-Expression: GPL-3.0-only
5
+ License-Expression: GPL-3.0-only AND (MIT OR Apache-2.0)
6
6
  Requires-Python: >=3.10
7
7
  Description-Content-Type: text/markdown
8
8
  License-File: LICENSE
9
9
  License-File: NOTICE
10
+ License-File: pykardia/guest/LICENSE-MIT
11
+ License-File: pykardia/guest/LICENSE-APACHE
10
12
  Requires-Dist: PyYAML<7,>=6.0.3
11
13
  Requires-Dist: watchdog<7,>=6
12
14
  Requires-Dist: wasmtime==34.0.0
@@ -25,6 +27,11 @@ Dynamic: license-file
25
27
 
26
28
  # pykardia
27
29
 
30
+ [![PyPI](https://img.shields.io/pypi/v/pykardia)](https://pypi.org/project/pykardia/)
31
+ [![Python](https://img.shields.io/pypi/pyversions/pykardia)](https://pypi.org/project/pykardia/)
32
+ [![CI](https://github.com/licyk/pykardia/actions/workflows/ci.yml/badge.svg)](https://github.com/licyk/pykardia/actions/workflows/ci.yml)
33
+ [![License](https://img.shields.io/badge/license-GPL--3.0--only-blue)](LICENSE)
34
+
28
35
  pykardia 是一个 Python 插件框架,用来组织可动态加载、更新和卸载的功能。
29
36
  插件可以提供服务、声明依赖,并把计时器、监听器和清理动作交给框架管理。
30
37
  当服务被替换或撤销时,依赖它的插件会随之重新加载或等待。
@@ -37,10 +44,15 @@ pykardia 是一个 Python 插件框架,用来组织可动态加载、更新和
37
44
  ## 开始使用
38
45
 
39
46
  需要 Python 3.10 或更高版本。
40
- 在本仓库源码目录安装并运行示例:
47
+ 从 PyPI 安装:
48
+
49
+ ```sh
50
+ python -m pip install pykardia
51
+ ```
52
+
53
+ 下载或克隆本仓库后,在仓库目录运行示例:
41
54
 
42
55
  ```sh
43
- python -m pip install .
44
56
  python examples/provider_consumer.py
45
57
  ```
46
58
 
@@ -67,4 +79,4 @@ pykardia examples/pykardia.yml
67
79
  | 查找常用类型和方法 | [API 参考](docs/api.md) |
68
80
  | 处理启动、依赖和运行时问题 | [故障排查](docs/troubleshooting.md) |
69
81
 
70
- 许可证为 [GPL-3.0-only](LICENSE),第三方声明见 [NOTICE](NOTICE)。
82
+ 许可证为 [GPL-3.0-only](LICENSE),第三方声明见 [NOTICE](NOTICE)。guest SDK(`pykardia/guest/` 及其打包进 guest 的模块,文件头标有 SPDX)可任选 [MIT](pykardia/guest/LICENSE-MIT) 或 [Apache-2.0](pykardia/guest/LICENSE-APACHE),guest 可以自行选择许可证。
@@ -1,5 +1,10 @@
1
1
  # pykardia
2
2
 
3
+ [![PyPI](https://img.shields.io/pypi/v/pykardia)](https://pypi.org/project/pykardia/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/pykardia)](https://pypi.org/project/pykardia/)
5
+ [![CI](https://github.com/licyk/pykardia/actions/workflows/ci.yml/badge.svg)](https://github.com/licyk/pykardia/actions/workflows/ci.yml)
6
+ [![License](https://img.shields.io/badge/license-GPL--3.0--only-blue)](LICENSE)
7
+
3
8
  pykardia 是一个 Python 插件框架,用来组织可动态加载、更新和卸载的功能。
4
9
  插件可以提供服务、声明依赖,并把计时器、监听器和清理动作交给框架管理。
5
10
  当服务被替换或撤销时,依赖它的插件会随之重新加载或等待。
@@ -12,10 +17,15 @@ pykardia 是一个 Python 插件框架,用来组织可动态加载、更新和
12
17
  ## 开始使用
13
18
 
14
19
  需要 Python 3.10 或更高版本。
15
- 在本仓库源码目录安装并运行示例:
20
+ 从 PyPI 安装:
21
+
22
+ ```sh
23
+ python -m pip install pykardia
24
+ ```
25
+
26
+ 下载或克隆本仓库后,在仓库目录运行示例:
16
27
 
17
28
  ```sh
18
- python -m pip install .
19
29
  python examples/provider_consumer.py
20
30
  ```
21
31
 
@@ -42,4 +52,4 @@ pykardia examples/pykardia.yml
42
52
  | 查找常用类型和方法 | [API 参考](docs/api.md) |
43
53
  | 处理启动、依赖和运行时问题 | [故障排查](docs/troubleshooting.md) |
44
54
 
45
- 许可证为 [GPL-3.0-only](LICENSE),第三方声明见 [NOTICE](NOTICE)。
55
+ 许可证为 [GPL-3.0-only](LICENSE),第三方声明见 [NOTICE](NOTICE)。guest SDK(`pykardia/guest/` 及其打包进 guest 的模块,文件头标有 SPDX)可任选 [MIT](pykardia/guest/LICENSE-MIT) 或 [Apache-2.0](pykardia/guest/LICENSE-APACHE),guest 可以自行选择许可证。
@@ -1,3 +1,4 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
1
2
  """Typed configuration decoding and reference-compatible issue paths."""
2
3
 
3
4
  from __future__ import annotations
@@ -202,6 +202,19 @@ class Fiber:
202
202
  return Completion.failed(error)
203
203
  return self.settled()
204
204
 
205
+ def fail(self, error: BaseException) -> Awaitable[None]:
206
+ """Fail the fiber from outside, as a load raising ``error`` would.
207
+
208
+ It unloads, reverting its effects and provisions, and stays Failed until
209
+ ``update`` or ``registry().replace`` clears the error. A load in flight
210
+ finishes first; a fiber that already failed keeps its first error.
211
+ """
212
+ try:
213
+ self._context._root.run(lambda state: state.fail(self.id(), error))
214
+ except Exception as error_:
215
+ return Completion.failed(error_)
216
+ return self.settled()
217
+
205
218
  def dispose(self) -> Disposal:
206
219
  """Retire a child; for the root, start a restart and retain its permanent identity."""
207
220
  if self.is_root():
@@ -1,3 +1,4 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
1
2
  """Strict JSON boundary with source-compatible number, Unicode and error semantics."""
2
3
 
3
4
  import json
@@ -446,6 +446,22 @@ class State:
446
446
  self.fibers[identity].revision += 1
447
447
  self.refresh(identity)
448
448
 
449
+ def fail(self, identity: FiberId, error: BaseException) -> None:
450
+ """Fail like a failed load; an in-flight transition unloads when it finishes."""
451
+ self.assert_active(identity)
452
+ fiber = self.fibers[identity]
453
+ if fiber.error is not None or fiber.removed:
454
+ return
455
+ fiber.error = error
456
+ previous, fiber.target = fiber.target, None
457
+ self.log(identity, Level.Error, error)
458
+ if fiber.inertia:
459
+ return
460
+ if previous is None:
461
+ self.update_state(identity)
462
+ else:
463
+ self.begin_unload(identity)
464
+
449
465
  def set_target(self, identity: FiberId, target: Epoch | None) -> None:
450
466
  """Coalesce changes under inertia without starting concurrent transitions."""
451
467
  fiber = self.fibers[identity]
@@ -1,3 +1,4 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
1
2
  """The recursive JSON value type used at configuration and guest boundaries."""
2
3
 
3
4
  import json
@@ -1,3 +1,4 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
1
2
  """Typed guest JSON decoding with serde's streaming field order and error positions."""
2
3
 
3
4
  from __future__ import annotations
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 licyk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,3 +1,4 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
1
2
  """Python guest SDK for the process, native-library and WASM guest ABI."""
2
3
 
3
4
  from pykardia.core.value import JsonValue
@@ -1,3 +1,4 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
1
2
  """JSON host operations shared by native and WebAssembly guest exports."""
2
3
 
3
4
  from typing import Protocol
@@ -1,3 +1,4 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
1
2
  """Guest implementation interface and synchronous host operations."""
2
3
 
3
4
  from __future__ import annotations
@@ -46,9 +47,32 @@ class Request:
46
47
  args: JsonValue
47
48
 
48
49
 
50
+ class Cancellation:
51
+ """The running ``kardia-guest/2`` export (0: none) and the last one its host cancelled."""
52
+
53
+ def __init__(self) -> None:
54
+ """Start with no export running."""
55
+ self.running = 0
56
+ self.cancelled = 0
57
+
58
+ def is_cancelled(self) -> bool:
59
+ """Report whether the running export was cancelled."""
60
+ return self.running != 0 and self.cancelled == self.running
61
+
62
+
63
+ CANCELLATION = Cancellation()
64
+
65
+
49
66
  class Host(ABC):
50
67
  """Synchronous host calls available while a guest export is running."""
51
68
 
69
+ def cancelled(self) -> bool:
70
+ """Report whether the host cancelled the running export, so a long call may stop.
71
+
72
+ Only a process guest served under ``kardia-guest/2`` is told; elsewhere this is False.
73
+ """
74
+ return CANCELLATION.is_cancelled()
75
+
52
76
  @abstractmethod
53
77
  def log(self, level: Level, text: str) -> None:
54
78
  """Send a log message without writing to the protocol's stdout."""
@@ -1,3 +1,4 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
1
2
  """Build process, native and WASM guest artifacts from a Python module and class."""
2
3
 
3
4
  from __future__ import annotations
@@ -34,6 +35,11 @@ int cordis_meta(void *, const HostApi *);
34
35
  int cordis_apply(void *, const HostApi *, size_t);
35
36
  int cordis_call(void *, const HostApi *, size_t);
36
37
  void cordis_dispose(void *, const HostApi *);
38
+ void *kardia_new(void);
39
+ int kardia_meta(void *, const HostApi *);
40
+ int kardia_apply(void *, const HostApi *, size_t);
41
+ int kardia_call(void *, const HostApi *, size_t);
42
+ void kardia_dispose(void *, const HostApi *);
37
43
  """
38
44
 
39
45
 
@@ -57,8 +63,11 @@ def sources(source: Path, module: str, module_root: Path | None = None) -> dict[
57
63
  if module_root is not None:
58
64
  for path in module_root.rglob("*.py"):
59
65
  files[path.relative_to(module_root).as_posix()] = path.read_bytes()
66
+ # the SDK's own licence: the guest and the modules above are MIT OR Apache-2.0
67
+ for name in ("LICENSE-MIT", "LICENSE-APACHE"):
68
+ files[f"LICENSES/pykardia-guest-{name}"] = (package / "guest" / name).read_bytes()
60
69
  for project, names in (
61
- ("pykardia", ("LICENSE", "NOTICE")),
70
+ ("pykardia", ("NOTICE",)),
62
71
  ("typing_extensions", ("LICENSE",)),
63
72
  ):
64
73
  metadata = distribution(project)
@@ -112,7 +121,7 @@ def export_dylib(
112
121
  libpython: Path | None = None,
113
122
  module_root: Path | None = None,
114
123
  ) -> None:
115
- """Compile all five native C exports with CFFI and embed the SDK and guest source.
124
+ """Compile the C exports, cordis_* and kardia_*, with CFFI and embed the SDK and source.
116
125
 
117
126
  Requires CFFI, a C compiler and this interpreter's shared libpython. The built
118
127
  artifact uses that Python runtime and CFFI backend, without a pykardia install.
@@ -171,7 +180,8 @@ import sys
171
180
  import tempfile
172
181
  from {module}_ffi import ffi
173
182
  _bundle = tempfile.mkdtemp(prefix="pykardia-guest-")
174
- atexit.register(shutil.rmtree, _bundle)
183
+ # the host process may hold the archive open to its exit (importlib.metadata does)
184
+ atexit.register(shutil.rmtree, _bundle, ignore_errors=True)
175
185
  _path = _bundle + "/guest.zip"
176
186
  with open(_path, "wb") as _stream:
177
187
  _stream.write(base64.b64decode({embedded!r}))
@@ -1,3 +1,4 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
1
2
  """Metadata builders for guest modules and their declared service access."""
2
3
 
3
4
  from __future__ import annotations
@@ -1,3 +1,4 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
1
2
  """CFFI embedding callbacks for native guest libraries."""
2
3
 
3
4
  from __future__ import annotations
@@ -79,7 +80,7 @@ class NativeHost:
79
80
 
80
81
 
81
82
  def install(ffi: FFI, guest: type[Guest[object]]) -> None:
82
- """Register five C symbols and retain state handles until their matching disposal."""
83
+ """Register the C symbols, under both names, and retain state handles until disposal."""
83
84
  states: dict[int, object] = {}
84
85
 
85
86
  @ffi.def_extern()
@@ -120,3 +121,30 @@ def install(ffi: FFI, guest: type[Guest[object]]) -> None:
120
121
  dispatch(state, api, "dispose")
121
122
  finally:
122
123
  states.pop(int(ffi.cast("size_t", state)))
124
+
125
+ # the same exports under the kardia_* names; hosts that know only cordis_* use those
126
+
127
+ @ffi.def_extern()
128
+ def kardia_new() -> object:
129
+ """Allocate a state, as cordis_new does."""
130
+ return cordis_new()
131
+
132
+ @ffi.def_extern()
133
+ def kardia_meta(state: object, api: HostApi) -> int:
134
+ """Return metadata, as cordis_meta does."""
135
+ return cordis_meta(state, api)
136
+
137
+ @ffi.def_extern()
138
+ def kardia_apply(state: object, api: HostApi, length: int) -> int:
139
+ """Apply, as cordis_apply does."""
140
+ return cordis_apply(state, api, length)
141
+
142
+ @ffi.def_extern()
143
+ def kardia_call(state: object, api: HostApi, length: int) -> int:
144
+ """Call, as cordis_call does."""
145
+ return cordis_call(state, api, length)
146
+
147
+ @ffi.def_extern()
148
+ def kardia_dispose(state: object, api: HostApi) -> None:
149
+ """Dispose, as cordis_dispose does."""
150
+ cordis_dispose(state, api)