tsurara-plugin 0.1.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 (173) hide show
  1. tsurara_plugin-0.1.0/.gitignore +3 -0
  2. tsurara_plugin-0.1.0/LICENSE +21 -0
  3. tsurara_plugin-0.1.0/PKG-INFO +38 -0
  4. tsurara_plugin-0.1.0/README.md +27 -0
  5. tsurara_plugin-0.1.0/pyproject.toml +27 -0
  6. tsurara_plugin-0.1.0/pyrightconfig.json +12 -0
  7. tsurara_plugin-0.1.0/src/tsurara_plugin/__init__.py +60 -0
  8. tsurara_plugin-0.1.0/src/tsurara_plugin/__main__.py +71 -0
  9. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/__init__.py +321 -0
  10. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/_support.py +5 -0
  11. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/_typedefs.py +4077 -0
  12. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/allocated_names.py +20 -0
  13. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/body.py +17 -0
  14. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/body_kind.py +12 -0
  15. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/body_kind1.py +13 -0
  16. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/callback.py +15 -0
  17. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/capabilities.py +34 -0
  18. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/case_.py +9 -0
  19. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/channel.py +41 -0
  20. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/channel_param.py +15 -0
  21. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/choice.py +18 -0
  22. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/context_rules.py +33 -0
  23. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/data_policy.py +19 -0
  24. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/decl.py +27 -0
  25. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/decl_id.py +9 -0
  26. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/decl_kind.py +15 -0
  27. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/decl_kind1.py +14 -0
  28. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/decl_kind2.py +14 -0
  29. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/decl_kind3.py +15 -0
  30. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/decl_kind4.py +15 -0
  31. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/decl_kind5.py +14 -0
  32. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/decl_names.py +17 -0
  33. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/describe.py +28 -0
  34. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/discriminator.py +19 -0
  35. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/doc.py +19 -0
  36. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/encoding.py +16 -0
  37. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/enum_decl.py +19 -0
  38. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/enum_model.py +17 -0
  39. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/enum_repr.py +8 -0
  40. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/enums.py +11 -0
  41. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/enums1.py +10 -0
  42. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/events.py +21 -0
  43. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/export.py +14 -0
  44. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr.py +22 -0
  45. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr1.py +13 -0
  46. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr10.py +14 -0
  47. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr11.py +14 -0
  48. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr12.py +14 -0
  49. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr2.py +14 -0
  50. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr3.py +14 -0
  51. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr4.py +14 -0
  52. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr5.py +14 -0
  53. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr5tuple.py +16 -0
  54. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr6.py +14 -0
  55. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr6named.py +16 -0
  56. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr7.py +14 -0
  57. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr7external.py +16 -0
  58. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr8.py +14 -0
  59. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/expr9.py +15 -0
  60. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/extend_input.py +28 -0
  61. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/external.py +18 -0
  62. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/field.py +22 -0
  63. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/files.py +11 -0
  64. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/filter.py +21 -0
  65. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/framing.py +9 -0
  66. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/generate_request.py +29 -0
  67. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/generate_response.py +21 -0
  68. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/import_.py +13 -0
  69. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/inheritance.py +11 -0
  70. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/inline.py +20 -0
  71. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/items.py +19 -0
  72. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/json_events.py +11 -0
  73. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/json_events2.py +10 -0
  74. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/literal1.py +10 -0
  75. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/literal2.py +10 -0
  76. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/literal3.py +10 -0
  77. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/literal_model.py +13 -0
  78. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/loc.py +14 -0
  79. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/lowering.py +17 -0
  80. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/manifest.py +24 -0
  81. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/mapped.py +21 -0
  82. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/markers.py +23 -0
  83. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/media_content.py +29 -0
  84. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/model.py +39 -0
  85. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/module.py +19 -0
  86. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_id.py +9 -0
  87. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind.py +16 -0
  88. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind1.py +14 -0
  89. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind1schema.py +11 -0
  90. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind2.py +14 -0
  91. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind2writable.py +14 -0
  92. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind3.py +14 -0
  93. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind3operation.py +14 -0
  94. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind4.py +14 -0
  95. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind4webhook.py +10 -0
  96. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind5.py +14 -0
  97. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind5channel.py +10 -0
  98. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind6.py +14 -0
  99. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_kind6callback.py +17 -0
  100. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_ref.py +16 -0
  101. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/name_request.py +22 -0
  102. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/object.py +17 -0
  103. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/operation.py +47 -0
  104. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/operation_entry.py +31 -0
  105. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/operation_kind.py +10 -0
  106. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/operation_names.py +11 -0
  107. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/operation_types.py +27 -0
  108. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/options.py +42 -0
  109. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/origin.py +11 -0
  110. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/origin1.py +14 -0
  111. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/output_file.py +12 -0
  112. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/pagination.py +25 -0
  113. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/param.py +29 -0
  114. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/param_in.py +11 -0
  115. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/param_in1.py +12 -0
  116. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/presence.py +12 -0
  117. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/presence1.py +11 -0
  118. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/property.py +19 -0
  119. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/record.py +21 -0
  120. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/response.py +21 -0
  121. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/runtime_source.py +9 -0
  122. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/scalar.py +18 -0
  123. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/scalar_kind.py +11 -0
  124. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/security_use.py +28 -0
  125. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/sequence.py +9 -0
  126. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/server.py +18 -0
  127. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/server_variable.py +12 -0
  128. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/session_request.py +13 -0
  129. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/session_request1.py +13 -0
  130. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/session_request2.py +17 -0
  131. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/session_response.py +14 -0
  132. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/session_response1.py +18 -0
  133. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/session_response2.py +13 -0
  134. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/session_response3.py +13 -0
  135. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/site.py +13 -0
  136. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/sites.py +11 -0
  137. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/spec_version.py +14 -0
  138. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/stage.py +12 -0
  139. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/status.py +13 -0
  140. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/status1.py +9 -0
  141. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/status2.py +10 -0
  142. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/status3.py +10 -0
  143. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/tag.py +11 -0
  144. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/tagged_union.py +20 -0
  145. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/tuple.py +18 -0
  146. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type1.py +15 -0
  147. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type10.py +14 -0
  148. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type11.py +14 -0
  149. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type12.py +14 -0
  150. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type13.py +14 -0
  151. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type14.py +14 -0
  152. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type15.py +14 -0
  153. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type16.py +14 -0
  154. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type17.py +14 -0
  155. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type2.py +14 -0
  156. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type3.py +14 -0
  157. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type4.py +14 -0
  158. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type6.py +14 -0
  159. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type7.py +14 -0
  160. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type8.py +10 -0
  161. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type9.py +14 -0
  162. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type_.py +26 -0
  163. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type_decl.py +31 -0
  164. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/type_entry.py +20 -0
  165. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/untagged_union.py +18 -0
  166. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/variant.py +15 -0
  167. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/version_marker.py +13 -0
  168. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/warning.py +22 -0
  169. tsurara_plugin-0.1.0/src/tsurara_plugin/protocol/warning_kind.py +8 -0
  170. tsurara_plugin-0.1.0/src/tsurara_plugin/testing.py +26 -0
  171. tsurara_plugin-0.1.0/src/tsurara_plugin/write.py +26 -0
  172. tsurara_plugin-0.1.0/tests/test_write.py +11 -0
  173. tsurara_plugin-0.1.0/uv.lock +98 -0
@@ -0,0 +1,3 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 nazo
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.
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.5
2
+ Name: tsurara-plugin
3
+ Version: 0.1.0
4
+ Summary: Write tsurara plugins in Python
5
+ Project-URL: Repository, https://github.com/tsurara-openapi/tsurara
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.11
9
+ Requires-Dist: tsurara-client
10
+ Description-Content-Type: text/markdown
11
+
12
+ # tsurara-plugin
13
+
14
+ Write tsurara plugins in Python (docs/guide/plugins.md). A plugin module defines `plugin = define_plugin(...)` with any of the stages; tsurara runs it once per run with `python -m tsurara_plugin <module>`:
15
+
16
+ ```yaml
17
+ plugins:
18
+ - { module: ./plugin.py, runtime: [python, -m, tsurara_plugin] }
19
+ ```
20
+
21
+ ```python
22
+ from tsurara_plugin import ExtendInput, OutputFile, define_plugin
23
+
24
+
25
+ def extend(input: ExtendInput) -> list[OutputFile]:
26
+ if input.manifest is None:
27
+ return []
28
+ return [
29
+ OutputFile(path=f"functions/{op.operation_id}.txt", contents=f"{input.marker}\n{op.function.identifier}\n")
30
+ for op in input.manifest.operations
31
+ if op.function is not None
32
+ ]
33
+
34
+
35
+ plugin = define_plugin(name="functions", extend=extend)
36
+ ```
37
+
38
+ The types of the model, the manifest and the inputs (`tsurara_plugin.protocol`) are generated by tsurara from `spec/plugin-protocol.schema.json`. `PyFile` writes Python files with their imports, and `tsurara_plugin.testing.run_plugin` runs tsurara with a plugin for tests.
@@ -0,0 +1,27 @@
1
+ # tsurara-plugin
2
+
3
+ Write tsurara plugins in Python (docs/guide/plugins.md). A plugin module defines `plugin = define_plugin(...)` with any of the stages; tsurara runs it once per run with `python -m tsurara_plugin <module>`:
4
+
5
+ ```yaml
6
+ plugins:
7
+ - { module: ./plugin.py, runtime: [python, -m, tsurara_plugin] }
8
+ ```
9
+
10
+ ```python
11
+ from tsurara_plugin import ExtendInput, OutputFile, define_plugin
12
+
13
+
14
+ def extend(input: ExtendInput) -> list[OutputFile]:
15
+ if input.manifest is None:
16
+ return []
17
+ return [
18
+ OutputFile(path=f"functions/{op.operation_id}.txt", contents=f"{input.marker}\n{op.function.identifier}\n")
19
+ for op in input.manifest.operations
20
+ if op.function is not None
21
+ ]
22
+
23
+
24
+ plugin = define_plugin(name="functions", extend=extend)
25
+ ```
26
+
27
+ The types of the model, the manifest and the inputs (`tsurara_plugin.protocol`) are generated by tsurara from `spec/plugin-protocol.schema.json`. `PyFile` writes Python files with their imports, and `tsurara_plugin.testing.run_plugin` runs tsurara with a plugin for tests.
@@ -0,0 +1,27 @@
1
+ [project]
2
+ name = "tsurara-plugin"
3
+ version = "0.1.0"
4
+ description = "Write tsurara plugins in Python"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ requires-python = ">=3.11"
8
+ dependencies = ["tsurara-client"]
9
+
10
+ [tool.uv.sources]
11
+ tsurara-client = { path = "../../runtimes/python", editable = true }
12
+
13
+ [dependency-groups]
14
+ dev = ["pytest>=8"]
15
+
16
+ [project.urls]
17
+ Repository = "https://github.com/tsurara-openapi/tsurara"
18
+
19
+ [build-system]
20
+ requires = ["hatchling==1.33.0"]
21
+ build-backend = "hatchling.build"
22
+
23
+ [tool.hatch.build.targets.wheel]
24
+ packages = ["src/tsurara_plugin"]
25
+
26
+ [tool.pytest.ini_options]
27
+ testpaths = ["tests"]
@@ -0,0 +1,12 @@
1
+ {
2
+ "include": ["src", "tests"],
3
+ "exclude": ["src/tsurara_plugin/protocol"],
4
+ "pythonVersion": "3.11",
5
+ "venvPath": ".",
6
+ "venv": ".venv",
7
+ "strict": [
8
+ "src/tsurara_plugin/__init__.py",
9
+ "src/tsurara_plugin/write.py",
10
+ "src/tsurara_plugin/testing.py"
11
+ ]
12
+ }
@@ -0,0 +1,60 @@
1
+ """Write tsurara plugins in Python.
2
+
3
+ A plugin module defines ``plugin = define_plugin(...)`` with any of the stages. tsurara runs it once per
4
+ run (``python -m tsurara_plugin <module>``) and calls the stages it declares over the session protocol
5
+ (design.md 11.2). ``extend`` and ``transform_files`` receive and return the generated dataclasses of
6
+ ``tsurara_plugin.protocol``; ``transform_document`` and ``transform_model`` work on JSON values, so that
7
+ nothing a newer tsurara adds is lost.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from collections.abc import Callable
13
+ from dataclasses import dataclass
14
+ from typing import Any
15
+
16
+ from .protocol import ExtendInput, Manifest, Model, OutputFile
17
+ from .write import PyFile
18
+
19
+ __all__ = [
20
+ "SESSION_PROTOCOL",
21
+ "ExtendInput",
22
+ "Manifest",
23
+ "Model",
24
+ "OutputFile",
25
+ "Plugin",
26
+ "PyFile",
27
+ "define_plugin",
28
+ ]
29
+
30
+ SESSION_PROTOCOL = 1
31
+ """The session protocol this SDK speaks (``tsurara_backend::session::SESSION_PROTOCOL``)."""
32
+
33
+
34
+ @dataclass(frozen=True, kw_only=True)
35
+ class Plugin:
36
+ """A plugin: a name, and any of the stages."""
37
+
38
+ name: str
39
+ transform_document: Callable[[Any], Any] | None = None
40
+ transform_model: Callable[[dict[str, Any]], dict[str, Any]] | None = None
41
+ extend: Callable[[ExtendInput], list[OutputFile]] | None = None
42
+ transform_files: Callable[[list[OutputFile]], list[OutputFile]] | None = None
43
+
44
+
45
+ def define_plugin(
46
+ *,
47
+ name: str,
48
+ transform_document: Callable[[Any], Any] | None = None,
49
+ transform_model: Callable[[dict[str, Any]], dict[str, Any]] | None = None,
50
+ extend: Callable[[ExtendInput], list[OutputFile]] | None = None,
51
+ transform_files: Callable[[list[OutputFile]], list[OutputFile]] | None = None,
52
+ ) -> Plugin:
53
+ """Declares a plugin; the module assigns it to ``plugin``."""
54
+ return Plugin(
55
+ name=name,
56
+ transform_document=transform_document,
57
+ transform_model=transform_model,
58
+ extend=extend,
59
+ transform_files=transform_files,
60
+ )
@@ -0,0 +1,71 @@
1
+ """``python -m tsurara_plugin <module>``: serves the plugin the module defines as ``plugin`` over the
2
+ session protocol (one JSON message per line on stdin and stdout)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import importlib.util
7
+ import json
8
+ import sys
9
+ from typing import Any
10
+
11
+ from . import SESSION_PROTOCOL, Plugin
12
+ from .protocol._typedefs import CODEC
13
+
14
+ STAGES = {
15
+ "transformDocument": "transform_document",
16
+ "transformModel": "transform_model",
17
+ "extend": "extend",
18
+ "transformFiles": "transform_files",
19
+ }
20
+
21
+ FILES = {"list": {"ref": "OutputFile"}}
22
+
23
+
24
+ def load(path: str) -> Plugin:
25
+ spec = importlib.util.spec_from_file_location("tsurara_plugin_module", path)
26
+ if spec is None or spec.loader is None:
27
+ raise SystemExit(f"cannot load {path}")
28
+ module = importlib.util.module_from_spec(spec)
29
+ spec.loader.exec_module(module)
30
+ plugin = getattr(module, "plugin", None)
31
+ if not isinstance(plugin, Plugin):
32
+ raise SystemExit(f"{path} does not define `plugin = define_plugin(...)`")
33
+ return plugin
34
+
35
+
36
+ def call(plugin: Plugin, stage: str, value: Any) -> Any:
37
+ function = getattr(plugin, STAGES[stage])
38
+ if function is None:
39
+ raise ValueError(f"the plugin has no {stage} stage")
40
+ if stage == "extend":
41
+ return CODEC.encode(FILES, function(CODEC.decode({"ref": "ExtendInput"}, value)))
42
+ if stage == "transformFiles":
43
+ return CODEC.encode(FILES, function(CODEC.decode(FILES, value)))
44
+ return function(value)
45
+
46
+
47
+ def main() -> None:
48
+ plugin = load(sys.argv[1])
49
+ for line in sys.stdin:
50
+ if not line.strip():
51
+ continue
52
+ request = json.loads(line)
53
+ if request["type"] == "hello":
54
+ stages = [s for s, attr in STAGES.items() if getattr(plugin, attr) is not None]
55
+ answer: dict[str, Any] = {
56
+ "type": "hello",
57
+ "protocol": SESSION_PROTOCOL,
58
+ "name": plugin.name,
59
+ "stages": stages,
60
+ }
61
+ else:
62
+ try:
63
+ answer = {"type": "result", "output": call(plugin, request["stage"], request["input"])}
64
+ except Exception as e: # noqa: BLE001 - every failure is reported to tsurara
65
+ answer = {"type": "error", "message": str(e)}
66
+ sys.stdout.write(json.dumps(answer) + "\n")
67
+ sys.stdout.flush()
68
+
69
+
70
+ if __name__ == "__main__":
71
+ main()
@@ -0,0 +1,321 @@
1
+ # Generated by tsurara. Do not edit.
2
+
3
+ from .allocated_names import AllocatedNames
4
+ from .body import Body
5
+ from .body_kind import BodyKind
6
+ from .body_kind1 import BodyKind1
7
+ from .callback import Callback
8
+ from .capabilities import Capabilities
9
+ from .case_ import Case
10
+ from .channel import Channel
11
+ from .channel_param import ChannelParam
12
+ from .choice import Choice
13
+ from .context_rules import ContextRules
14
+ from .data_policy import DataPolicy
15
+ from .decl import Decl
16
+ from .decl_id import DeclId
17
+ from .decl_kind import DeclKind
18
+ from .decl_kind1 import DeclKind1
19
+ from .decl_kind2 import DeclKind2
20
+ from .decl_kind3 import DeclKind3
21
+ from .decl_kind4 import DeclKind4
22
+ from .decl_kind5 import DeclKind5
23
+ from .decl_names import DeclNames
24
+ from .describe import Describe
25
+ from .discriminator import Discriminator
26
+ from .doc import Doc
27
+ from .encoding import Encoding
28
+ from .enum_decl import EnumDecl
29
+ from .enum_model import EnumModel
30
+ from .enum_repr import EnumRepr
31
+ from .enums import Enums
32
+ from .enums1 import Enums1
33
+ from .events import Events
34
+ from .export import Export
35
+ from .expr import Expr
36
+ from .expr1 import Expr1
37
+ from .expr10 import Expr10
38
+ from .expr11 import Expr11
39
+ from .expr12 import Expr12
40
+ from .expr2 import Expr2
41
+ from .expr3 import Expr3
42
+ from .expr4 import Expr4
43
+ from .expr5 import Expr5
44
+ from .expr5tuple import Expr5Tuple
45
+ from .expr6 import Expr6
46
+ from .expr6named import Expr6Named
47
+ from .expr7 import Expr7
48
+ from .expr7external import Expr7External
49
+ from .expr8 import Expr8
50
+ from .expr9 import Expr9
51
+ from .extend_input import ExtendInput
52
+ from .external import External
53
+ from .field import Field
54
+ from .files import Files
55
+ from .filter import Filter
56
+ from .framing import Framing
57
+ from .generate_request import GenerateRequest
58
+ from .generate_response import GenerateResponse
59
+ from .import_ import Import
60
+ from .inheritance import Inheritance
61
+ from .inline import Inline
62
+ from .items import Items
63
+ from .json_events import JsonEvents
64
+ from .json_events2 import JsonEvents2
65
+ from .literal1 import Literal1
66
+ from .literal2 import Literal2
67
+ from .literal3 import Literal3
68
+ from .literal_model import LiteralModel
69
+ from .loc import Loc
70
+ from .lowering import Lowering
71
+ from .manifest import Manifest
72
+ from .mapped import Mapped
73
+ from .markers import Markers
74
+ from .media_content import MediaContent
75
+ from .model import Model
76
+ from .module import Module
77
+ from .name_id import NameId
78
+ from .name_kind import NameKind
79
+ from .name_kind1 import NameKind1
80
+ from .name_kind1schema import NameKind1Schema
81
+ from .name_kind2 import NameKind2
82
+ from .name_kind2writable import NameKind2Writable
83
+ from .name_kind3 import NameKind3
84
+ from .name_kind3operation import NameKind3Operation
85
+ from .name_kind4 import NameKind4
86
+ from .name_kind4webhook import NameKind4Webhook
87
+ from .name_kind5 import NameKind5
88
+ from .name_kind5channel import NameKind5Channel
89
+ from .name_kind6 import NameKind6
90
+ from .name_kind6callback import NameKind6Callback
91
+ from .name_ref import NameRef
92
+ from .name_request import NameRequest
93
+ from .object import Object
94
+ from .operation import Operation
95
+ from .operation_entry import OperationEntry
96
+ from .operation_kind import OperationKind
97
+ from .operation_names import OperationNames
98
+ from .operation_types import OperationTypes
99
+ from .options import Options
100
+ from .origin import Origin
101
+ from .origin1 import Origin1
102
+ from .output_file import OutputFile
103
+ from .pagination import Pagination
104
+ from .param import Param
105
+ from .param_in import ParamIn
106
+ from .param_in1 import ParamIn1
107
+ from .presence import Presence
108
+ from .presence1 import Presence1
109
+ from .property import Property
110
+ from .record import Record
111
+ from .response import Response
112
+ from .runtime_source import RuntimeSource
113
+ from .scalar import Scalar
114
+ from .scalar_kind import ScalarKind
115
+ from .security_use import SecurityUse
116
+ from .sequence import Sequence
117
+ from .server import Server
118
+ from .server_variable import ServerVariable
119
+ from .session_request import SessionRequest
120
+ from .session_request1 import SessionRequest1
121
+ from .session_request2 import SessionRequest2
122
+ from .session_response import SessionResponse
123
+ from .session_response1 import SessionResponse1
124
+ from .session_response2 import SessionResponse2
125
+ from .session_response3 import SessionResponse3
126
+ from .site import Site
127
+ from .sites import Sites
128
+ from .spec_version import SpecVersion
129
+ from .stage import Stage
130
+ from .status import Status
131
+ from .status1 import Status1
132
+ from .status2 import Status2
133
+ from .status3 import Status3
134
+ from .tag import Tag
135
+ from .tagged_union import TaggedUnion
136
+ from .tuple import Tuple
137
+ from .type1 import Type1
138
+ from .type10 import Type10
139
+ from .type11 import Type11
140
+ from .type12 import Type12
141
+ from .type13 import Type13
142
+ from .type14 import Type14
143
+ from .type15 import Type15
144
+ from .type16 import Type16
145
+ from .type17 import Type17
146
+ from .type2 import Type2
147
+ from .type3 import Type3
148
+ from .type4 import Type4
149
+ from .type6 import Type6
150
+ from .type7 import Type7
151
+ from .type8 import Type8
152
+ from .type9 import Type9
153
+ from .type_ import Type
154
+ from .type_decl import TypeDecl
155
+ from .type_entry import TypeEntry
156
+ from .untagged_union import UntaggedUnion
157
+ from .variant import Variant
158
+ from .version_marker import VersionMarker
159
+ from .warning import Warning
160
+ from .warning_kind import WarningKind
161
+
162
+ __all__ = [
163
+ "AllocatedNames",
164
+ "Body",
165
+ "BodyKind",
166
+ "BodyKind1",
167
+ "Callback",
168
+ "Capabilities",
169
+ "Case",
170
+ "Channel",
171
+ "ChannelParam",
172
+ "Choice",
173
+ "ContextRules",
174
+ "DataPolicy",
175
+ "Decl",
176
+ "DeclId",
177
+ "DeclKind",
178
+ "DeclKind1",
179
+ "DeclKind2",
180
+ "DeclKind3",
181
+ "DeclKind4",
182
+ "DeclKind5",
183
+ "DeclNames",
184
+ "Describe",
185
+ "Discriminator",
186
+ "Doc",
187
+ "Encoding",
188
+ "EnumDecl",
189
+ "EnumModel",
190
+ "EnumRepr",
191
+ "Enums",
192
+ "Enums1",
193
+ "Events",
194
+ "Export",
195
+ "Expr",
196
+ "Expr1",
197
+ "Expr10",
198
+ "Expr11",
199
+ "Expr12",
200
+ "Expr2",
201
+ "Expr3",
202
+ "Expr4",
203
+ "Expr5",
204
+ "Expr5Tuple",
205
+ "Expr6",
206
+ "Expr6Named",
207
+ "Expr7",
208
+ "Expr7External",
209
+ "Expr8",
210
+ "Expr9",
211
+ "ExtendInput",
212
+ "External",
213
+ "Field",
214
+ "Files",
215
+ "Filter",
216
+ "Framing",
217
+ "GenerateRequest",
218
+ "GenerateResponse",
219
+ "Import",
220
+ "Inheritance",
221
+ "Inline",
222
+ "Items",
223
+ "JsonEvents",
224
+ "JsonEvents2",
225
+ "Literal1",
226
+ "Literal2",
227
+ "Literal3",
228
+ "LiteralModel",
229
+ "Loc",
230
+ "Lowering",
231
+ "Manifest",
232
+ "Mapped",
233
+ "Markers",
234
+ "MediaContent",
235
+ "Model",
236
+ "Module",
237
+ "NameId",
238
+ "NameKind",
239
+ "NameKind1",
240
+ "NameKind1Schema",
241
+ "NameKind2",
242
+ "NameKind2Writable",
243
+ "NameKind3",
244
+ "NameKind3Operation",
245
+ "NameKind4",
246
+ "NameKind4Webhook",
247
+ "NameKind5",
248
+ "NameKind5Channel",
249
+ "NameKind6",
250
+ "NameKind6Callback",
251
+ "NameRef",
252
+ "NameRequest",
253
+ "Object",
254
+ "Operation",
255
+ "OperationEntry",
256
+ "OperationKind",
257
+ "OperationNames",
258
+ "OperationTypes",
259
+ "Options",
260
+ "Origin",
261
+ "Origin1",
262
+ "OutputFile",
263
+ "Pagination",
264
+ "Param",
265
+ "ParamIn",
266
+ "ParamIn1",
267
+ "Presence",
268
+ "Presence1",
269
+ "Property",
270
+ "Record",
271
+ "Response",
272
+ "RuntimeSource",
273
+ "Scalar",
274
+ "ScalarKind",
275
+ "SecurityUse",
276
+ "Sequence",
277
+ "Server",
278
+ "ServerVariable",
279
+ "SessionRequest",
280
+ "SessionRequest1",
281
+ "SessionRequest2",
282
+ "SessionResponse",
283
+ "SessionResponse1",
284
+ "SessionResponse2",
285
+ "SessionResponse3",
286
+ "Site",
287
+ "Sites",
288
+ "SpecVersion",
289
+ "Stage",
290
+ "Status",
291
+ "Status1",
292
+ "Status2",
293
+ "Status3",
294
+ "Tag",
295
+ "TaggedUnion",
296
+ "Tuple",
297
+ "Type",
298
+ "Type1",
299
+ "Type10",
300
+ "Type11",
301
+ "Type12",
302
+ "Type13",
303
+ "Type14",
304
+ "Type15",
305
+ "Type16",
306
+ "Type17",
307
+ "Type2",
308
+ "Type3",
309
+ "Type4",
310
+ "Type6",
311
+ "Type7",
312
+ "Type8",
313
+ "Type9",
314
+ "TypeDecl",
315
+ "TypeEntry",
316
+ "UntaggedUnion",
317
+ "Variant",
318
+ "VersionMarker",
319
+ "Warning",
320
+ "WarningKind",
321
+ ]
@@ -0,0 +1,5 @@
1
+ # Generated by tsurara. Do not edit.
2
+
3
+ from tsurara_client import MISSING, Missing
4
+
5
+ __all__ = ["MISSING", "Missing"]