Pyrophone 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.
- pyrophone-0.1.0/.gitignore +15 -0
- pyrophone-0.1.0/PKG-INFO +38 -0
- pyrophone-0.1.0/README.md +6 -0
- pyrophone-0.1.0/doc/LICENSE +202 -0
- pyrophone-0.1.0/pyproject.toml +85 -0
- pyrophone-0.1.0/src/pyrophone/__init__.py +62 -0
- pyrophone-0.1.0/src/pyrophone/_channels.py +125 -0
- pyrophone-0.1.0/src/pyrophone/_compile.py +118 -0
- pyrophone-0.1.0/src/pyrophone/_control.py +229 -0
- pyrophone-0.1.0/src/pyrophone/_driver.py +91 -0
- pyrophone-0.1.0/src/pyrophone/_entry.py +53 -0
- pyrophone-0.1.0/src/pyrophone/_exceptions.py +42 -0
- pyrophone-0.1.0/src/pyrophone/_graph.py +283 -0
- pyrophone-0.1.0/src/pyrophone/_graph_display.py +117 -0
- pyrophone-0.1.0/src/pyrophone/_inspection.py +50 -0
- pyrophone-0.1.0/src/pyrophone/_node.py +216 -0
- pyrophone-0.1.0/src/pyrophone/_ports.py +105 -0
- pyrophone-0.1.0/src/pyrophone/_properties.py +64 -0
- pyrophone-0.1.0/src/pyrophone/_runner.py +83 -0
- pyrophone-0.1.0/src/pyrophone/_runtime.py +140 -0
- pyrophone-0.1.0/src/pyrophone/_schema.py +197 -0
- pyrophone-0.1.0/src/pyrophone/_shell.py +130 -0
- pyrophone-0.1.0/src/pyrophone/_terminal.py +73 -0
- pyrophone-0.1.0/src/pyrophone/_trace.py +93 -0
- pyrophone-0.1.0/src/pyrophone/cabe.py +222 -0
- pyrophone-0.1.0/src/pyrophone/jq.py +65 -0
- pyrophone-0.1.0/src/pyrophone/mqtt.py +122 -0
- pyrophone-0.1.0/src/pyrophone/nodes.py +110 -0
- pyrophone-0.1.0/src/pyrophone/py.typed +0 -0
- pyrophone-0.1.0/src/pyrophone/script.py +74 -0
- pyrophone-0.1.0/tests/__init__.py +0 -0
- pyrophone-0.1.0/tests/test_cabe.py +481 -0
- pyrophone-0.1.0/tests/test_channels.py +176 -0
- pyrophone-0.1.0/tests/test_entry.py +244 -0
- pyrophone-0.1.0/tests/test_graph.py +436 -0
- pyrophone-0.1.0/tests/test_graph_display.py +311 -0
- pyrophone-0.1.0/tests/test_inspection.py +112 -0
- pyrophone-0.1.0/tests/test_jq.py +175 -0
- pyrophone-0.1.0/tests/test_json_transform.py +118 -0
- pyrophone-0.1.0/tests/test_mqtt.py +290 -0
- pyrophone-0.1.0/tests/test_mqtt_example.py +204 -0
- pyrophone-0.1.0/tests/test_nodes.py +364 -0
- pyrophone-0.1.0/tests/test_package.py +17 -0
- pyrophone-0.1.0/tests/test_properties.py +200 -0
- pyrophone-0.1.0/tests/test_runtime.py +290 -0
- pyrophone-0.1.0/tests/test_runtime_configuration.py +260 -0
- pyrophone-0.1.0/tests/test_schema.py +299 -0
- pyrophone-0.1.0/tests/test_shell.py +299 -0
- pyrophone-0.1.0/tests/test_shell_terminal.py +122 -0
- pyrophone-0.1.0/tests/test_tracing.py +205 -0
- pyrophone-0.1.0/tests/test_typing.py +274 -0
pyrophone-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: Pyrophone
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python message routing DSL environment
|
|
5
|
+
Project-URL: Repository, https://github.com/messier-42/pyrophone
|
|
6
|
+
Project-URL: Issues, https://github.com/messier-42/pyrophone/issues
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: doc/LICENSE
|
|
9
|
+
Classifier: Development Status :: 1 - Planning
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Requires-Dist: aioconsole<1,>=0.9
|
|
19
|
+
Requires-Dist: prompt-toolkit<4,>=3.0.52
|
|
20
|
+
Requires-Dist: pyyaml<7,>=6
|
|
21
|
+
Provides-Extra: amqp
|
|
22
|
+
Provides-Extra: cabe
|
|
23
|
+
Requires-Dist: pycabe>=0.1.0.dev0; extra == 'cabe'
|
|
24
|
+
Provides-Extra: irc
|
|
25
|
+
Provides-Extra: jq
|
|
26
|
+
Requires-Dist: jq<2,>=1.13; extra == 'jq'
|
|
27
|
+
Provides-Extra: mqtt
|
|
28
|
+
Requires-Dist: aiomqtt<3,>=2.4; extra == 'mqtt'
|
|
29
|
+
Provides-Extra: redis
|
|
30
|
+
Provides-Extra: xmpp
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# Pyrophone
|
|
34
|
+
|
|
35
|
+
Pyrophone is a Python-based message router programming environment. It
|
|
36
|
+
functions as a DSL constructed within the Python programming language to enable
|
|
37
|
+
people to readily construct message routing services using a minimal number of
|
|
38
|
+
lines of code.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27", "hatch-vcs>=0.5"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "Pyrophone"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Python message routing DSL environment"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"PyYAML>=6,<7",
|
|
13
|
+
"aioconsole>=0.9,<1",
|
|
14
|
+
"prompt-toolkit>=3.0.52,<4",
|
|
15
|
+
]
|
|
16
|
+
license = "Apache-2.0"
|
|
17
|
+
license-files = ["doc/LICENSE"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 1 - Planning",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Programming Language :: Python :: 3.14",
|
|
25
|
+
"Programming Language :: Python :: 3.15",
|
|
26
|
+
"Typing :: Typed",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Repository = "https://github.com/messier-42/pyrophone"
|
|
31
|
+
Issues = "https://github.com/messier-42/pyrophone/issues"
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
cabe = ["PyCABE>=0.1.0.dev0"]
|
|
35
|
+
mqtt = ["aiomqtt>=2.4,<3"]
|
|
36
|
+
jq = ["jq>=1.13,<2"]
|
|
37
|
+
amqp = []
|
|
38
|
+
redis = []
|
|
39
|
+
xmpp = []
|
|
40
|
+
irc = []
|
|
41
|
+
|
|
42
|
+
[dependency-groups]
|
|
43
|
+
dev = [
|
|
44
|
+
"mypy>=1.15",
|
|
45
|
+
"types-PyYAML>=6,<7",
|
|
46
|
+
"pytest>=8",
|
|
47
|
+
"pyte>=0.8,<1",
|
|
48
|
+
"pytest-asyncio>=1",
|
|
49
|
+
"ruff>=0.11",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[tool.hatch.version]
|
|
53
|
+
source = "vcs"
|
|
54
|
+
fallback-version = "0.1.0.dev0"
|
|
55
|
+
raw-options = { dist_name = "Pyrophone" }
|
|
56
|
+
|
|
57
|
+
[tool.hatch.build.targets.wheel]
|
|
58
|
+
packages = ["src/pyrophone"]
|
|
59
|
+
|
|
60
|
+
[tool.hatch.build.targets.sdist]
|
|
61
|
+
include = ["/src", "/tests", "/examples", "/pyproject.toml", "/README.md", "/doc/LICENSE"]
|
|
62
|
+
|
|
63
|
+
[tool.pytest.ini_options]
|
|
64
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
65
|
+
addopts = ["--import-mode=importlib", "--strict-config", "--strict-markers"]
|
|
66
|
+
filterwarnings = ["error"]
|
|
67
|
+
testpaths = ["tests"]
|
|
68
|
+
|
|
69
|
+
[tool.ruff]
|
|
70
|
+
target-version = "py312"
|
|
71
|
+
line-length = 88
|
|
72
|
+
|
|
73
|
+
[tool.ruff.lint]
|
|
74
|
+
select = ["E4", "E7", "E9", "F", "I", "UP", "B", "RUF"]
|
|
75
|
+
|
|
76
|
+
# The walkthrough uses the curated script vocabulary and enables stages live.
|
|
77
|
+
[tool.ruff.lint.per-file-ignores]
|
|
78
|
+
"doc/examples/01-basic-mqtt/script.py" = ["F403", "F405"]
|
|
79
|
+
"doc/examples/01-basic-mqtt/.support/script-all.py" = ["F401", "F403", "F405"]
|
|
80
|
+
"doc/examples/01-basic-mqtt/.support/script-stage0.py" = ["F403", "F405"]
|
|
81
|
+
|
|
82
|
+
[tool.mypy]
|
|
83
|
+
python_version = "3.12"
|
|
84
|
+
strict = true
|
|
85
|
+
files = ["src", "tests"]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Typed declarations for asynchronous message-processing nodes."""
|
|
2
|
+
|
|
3
|
+
from ._compile import CompiledEdge, CompiledGraph, CompiledNode, compile_graph
|
|
4
|
+
from ._control import NodeHandle, PortHandle, Runtime
|
|
5
|
+
from ._entry import main
|
|
6
|
+
from ._exceptions import (
|
|
7
|
+
ChannelClosedError,
|
|
8
|
+
ConfigurationError,
|
|
9
|
+
EndOfStream,
|
|
10
|
+
GraphError,
|
|
11
|
+
NodeExecutionError,
|
|
12
|
+
PyrophoneError,
|
|
13
|
+
SchemaError,
|
|
14
|
+
)
|
|
15
|
+
from ._graph import Edge, Graph, NodeDeclaration, PortReference
|
|
16
|
+
from ._node import Node, node_type, node_type_schema
|
|
17
|
+
from ._ports import Input, InputPort, Output, OutputPort
|
|
18
|
+
from ._properties import Property
|
|
19
|
+
from ._runner import run_sync
|
|
20
|
+
from ._runtime import run_async
|
|
21
|
+
from ._schema import NodeTypeSchema, PortSchema, PropertySchema
|
|
22
|
+
from ._trace import Trace
|
|
23
|
+
|
|
24
|
+
# Compatibility with the original asynchronous entry point.
|
|
25
|
+
run = run_async
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"ChannelClosedError",
|
|
29
|
+
"CompiledEdge",
|
|
30
|
+
"CompiledGraph",
|
|
31
|
+
"CompiledNode",
|
|
32
|
+
"ConfigurationError",
|
|
33
|
+
"Edge",
|
|
34
|
+
"EndOfStream",
|
|
35
|
+
"Graph",
|
|
36
|
+
"GraphError",
|
|
37
|
+
"Input",
|
|
38
|
+
"InputPort",
|
|
39
|
+
"Node",
|
|
40
|
+
"NodeDeclaration",
|
|
41
|
+
"NodeExecutionError",
|
|
42
|
+
"NodeHandle",
|
|
43
|
+
"NodeTypeSchema",
|
|
44
|
+
"Output",
|
|
45
|
+
"OutputPort",
|
|
46
|
+
"PortHandle",
|
|
47
|
+
"PortReference",
|
|
48
|
+
"PortSchema",
|
|
49
|
+
"Property",
|
|
50
|
+
"PropertySchema",
|
|
51
|
+
"PyrophoneError",
|
|
52
|
+
"Runtime",
|
|
53
|
+
"SchemaError",
|
|
54
|
+
"Trace",
|
|
55
|
+
"compile_graph",
|
|
56
|
+
"main",
|
|
57
|
+
"node_type",
|
|
58
|
+
"node_type_schema",
|
|
59
|
+
"run",
|
|
60
|
+
"run_async",
|
|
61
|
+
"run_sync",
|
|
62
|
+
]
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""Unbuffered, FIFO handoff between asynchronous producer and consumer ports."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from collections import deque
|
|
5
|
+
from collections.abc import AsyncIterator
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
|
|
8
|
+
from ._exceptions import ChannelClosedError, EndOfStream
|
|
9
|
+
from ._trace import _notify, _TraceCallbacks
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(eq=False)
|
|
13
|
+
class _PendingSend[T]:
|
|
14
|
+
value: T
|
|
15
|
+
accepted: asyncio.Future[None]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Channel[T]:
|
|
19
|
+
"""One edge's rendezvous state, confined to one asyncio event loop.
|
|
20
|
+
|
|
21
|
+
Waiters are matched in arrival order. A handoff accepts the value immediately;
|
|
22
|
+
cancellation after acceptance does not undo delivery. Pending sends retain
|
|
23
|
+
their values only while the sender is waiting, never as buffered arrivals.
|
|
24
|
+
Closing either end rejects unaccepted sends and ends outstanding receives.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self) -> None:
|
|
28
|
+
self._closed = False
|
|
29
|
+
self._senders: deque[_PendingSend[T]] = deque()
|
|
30
|
+
self._receivers: deque[asyncio.Future[T]] = deque()
|
|
31
|
+
self.input = ReceiveEndpoint(self)
|
|
32
|
+
self.output = SendEndpoint(self)
|
|
33
|
+
|
|
34
|
+
async def _send(self, value: T) -> None:
|
|
35
|
+
if self._closed:
|
|
36
|
+
raise ChannelClosedError("channel is closed")
|
|
37
|
+
while self._receivers:
|
|
38
|
+
receiver = self._receivers.popleft()
|
|
39
|
+
if not receiver.done():
|
|
40
|
+
receiver.set_result(value)
|
|
41
|
+
self._trace(value)
|
|
42
|
+
return
|
|
43
|
+
accepted: asyncio.Future[None] = asyncio.get_running_loop().create_future()
|
|
44
|
+
pending = _PendingSend(value, accepted)
|
|
45
|
+
self._senders.append(pending)
|
|
46
|
+
try:
|
|
47
|
+
await accepted
|
|
48
|
+
finally:
|
|
49
|
+
# A matched or closed waiter has already been removed.
|
|
50
|
+
if pending in self._senders:
|
|
51
|
+
self._senders.remove(pending)
|
|
52
|
+
|
|
53
|
+
async def _recv(self) -> T:
|
|
54
|
+
while self._senders:
|
|
55
|
+
pending = self._senders.popleft()
|
|
56
|
+
if not pending.accepted.done():
|
|
57
|
+
pending.accepted.set_result(None)
|
|
58
|
+
self._trace(pending.value)
|
|
59
|
+
return pending.value
|
|
60
|
+
if self._closed:
|
|
61
|
+
raise EndOfStream("channel is closed")
|
|
62
|
+
receiver: asyncio.Future[T] = asyncio.get_running_loop().create_future()
|
|
63
|
+
self._receivers.append(receiver)
|
|
64
|
+
try:
|
|
65
|
+
return await receiver
|
|
66
|
+
finally:
|
|
67
|
+
if receiver in self._receivers:
|
|
68
|
+
self._receivers.remove(receiver)
|
|
69
|
+
|
|
70
|
+
def _trace(self, value: T) -> None:
|
|
71
|
+
# Snapshot both ends before callbacks can change registrations. Delivery
|
|
72
|
+
# has already been accepted; no await separates either side's observers.
|
|
73
|
+
outgoing = self.output._traces.snapshot()
|
|
74
|
+
incoming = self.input._traces.snapshot()
|
|
75
|
+
_notify(outgoing, value)
|
|
76
|
+
_notify(incoming, value)
|
|
77
|
+
|
|
78
|
+
def _close(self) -> None:
|
|
79
|
+
self._closed = True
|
|
80
|
+
self.output._traces.close()
|
|
81
|
+
self.input._traces.close()
|
|
82
|
+
while self._senders:
|
|
83
|
+
pending = self._senders.popleft()
|
|
84
|
+
if not pending.accepted.done():
|
|
85
|
+
pending.accepted.set_exception(ChannelClosedError("channel is closed"))
|
|
86
|
+
while self._receivers:
|
|
87
|
+
receiver = self._receivers.popleft()
|
|
88
|
+
if not receiver.done():
|
|
89
|
+
receiver.set_exception(EndOfStream("channel is closed"))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class ReceiveEndpoint[T]:
|
|
93
|
+
"""Consumer view of a channel; closing withdraws consumer interest."""
|
|
94
|
+
|
|
95
|
+
def __init__(self, channel: Channel[T]) -> None:
|
|
96
|
+
self._channel = channel
|
|
97
|
+
self._traces = _TraceCallbacks[T]()
|
|
98
|
+
|
|
99
|
+
async def recv(self) -> T:
|
|
100
|
+
return await self._channel._recv()
|
|
101
|
+
|
|
102
|
+
async def close(self) -> None:
|
|
103
|
+
self._channel._close()
|
|
104
|
+
|
|
105
|
+
async def __aiter__(self) -> AsyncIterator[T]:
|
|
106
|
+
while True:
|
|
107
|
+
try:
|
|
108
|
+
value = await self.recv()
|
|
109
|
+
except EndOfStream:
|
|
110
|
+
return
|
|
111
|
+
yield value
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class SendEndpoint[T]:
|
|
115
|
+
"""Producer view of a channel; closing announces end of stream."""
|
|
116
|
+
|
|
117
|
+
def __init__(self, channel: Channel[T]) -> None:
|
|
118
|
+
self._channel = channel
|
|
119
|
+
self._traces = _TraceCallbacks[T]()
|
|
120
|
+
|
|
121
|
+
async def send(self, value: T) -> None:
|
|
122
|
+
await self._channel._send(value)
|
|
123
|
+
|
|
124
|
+
async def close(self) -> None:
|
|
125
|
+
self._channel._close()
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""Validate fundamental graphs and detach execution snapshots."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from types import MappingProxyType
|
|
6
|
+
|
|
7
|
+
from ._exceptions import GraphError
|
|
8
|
+
from ._graph import Graph, PortReference, _resolved_schema, _validate_connection
|
|
9
|
+
from ._inspection import Printable, node_details
|
|
10
|
+
from ._node import Node, _resolve_configuration
|
|
11
|
+
from ._schema import NodeTypeSchema
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(frozen=True)
|
|
15
|
+
class CompiledNode(Printable):
|
|
16
|
+
"""Configured occurrence retaining its original declaration ID.
|
|
17
|
+
|
|
18
|
+
Configuration is shallowly read-only, with nested values detached from the
|
|
19
|
+
authoring declaration so subsequent graph edits cannot change execution.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
id: str
|
|
23
|
+
node_type: type[Node]
|
|
24
|
+
configuration: Mapping[str, object]
|
|
25
|
+
schema: NodeTypeSchema
|
|
26
|
+
|
|
27
|
+
def __repr__(self) -> str:
|
|
28
|
+
return f"<CompiledNode {self.node_type.__name__}#{self.id[:8]}>"
|
|
29
|
+
|
|
30
|
+
def _describe(self) -> str:
|
|
31
|
+
return node_details(
|
|
32
|
+
self.node_type,
|
|
33
|
+
self.configuration,
|
|
34
|
+
self.schema,
|
|
35
|
+
kind="CompiledNode",
|
|
36
|
+
node_id=self.id,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass(frozen=True)
|
|
41
|
+
class CompiledEdge(Printable):
|
|
42
|
+
source_id: str
|
|
43
|
+
source_port: str
|
|
44
|
+
destination_id: str
|
|
45
|
+
destination_port: str
|
|
46
|
+
|
|
47
|
+
def __repr__(self) -> str:
|
|
48
|
+
return (
|
|
49
|
+
f"<CompiledEdge {self.source_id[:8]}.{self.source_port} -> "
|
|
50
|
+
f"{self.destination_id[:8]}.{self.destination_port}>"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
def _describe(self) -> str:
|
|
54
|
+
return (
|
|
55
|
+
"CompiledEdge:\n"
|
|
56
|
+
f" From: {self.source_id}.{self.source_port}\n"
|
|
57
|
+
f" To: {self.destination_id}.{self.destination_port}"
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass(frozen=True)
|
|
62
|
+
class CompiledGraph(Printable):
|
|
63
|
+
nodes: tuple[CompiledNode, ...]
|
|
64
|
+
edges: tuple[CompiledEdge, ...]
|
|
65
|
+
|
|
66
|
+
def __repr__(self) -> str:
|
|
67
|
+
return f"CompiledGraph(nodes={len(self.nodes)}, edges={len(self.edges)})"
|
|
68
|
+
|
|
69
|
+
def _describe(self) -> str:
|
|
70
|
+
from ._graph_display import format_graph
|
|
71
|
+
|
|
72
|
+
return format_graph(self, title="CompiledGraph")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def compile_graph(graph: Graph) -> CompiledGraph:
|
|
76
|
+
"""Validate every connection and configuration without allocating live nodes.
|
|
77
|
+
|
|
78
|
+
Every declared input and output must have exactly one channel. Empty graphs
|
|
79
|
+
and portless nodes are valid. The returned tuples and copied configuration
|
|
80
|
+
are independent of later authoring graph changes.
|
|
81
|
+
"""
|
|
82
|
+
nodes, edges = graph.nodes, graph.edges
|
|
83
|
+
members = set(nodes)
|
|
84
|
+
connected: set[PortReference] = set()
|
|
85
|
+
incoming = {edge.destination: edge.source for edge in edges}
|
|
86
|
+
for edge in edges:
|
|
87
|
+
_validate_connection(
|
|
88
|
+
edge.source, edge.destination, connected, incoming=incoming
|
|
89
|
+
)
|
|
90
|
+
if edge.source.node not in members or edge.destination.node not in members:
|
|
91
|
+
raise GraphError("connection references a node outside the graph")
|
|
92
|
+
connected.update((edge.source, edge.destination))
|
|
93
|
+
for node in nodes:
|
|
94
|
+
for name in (*node.schema.inputs, *node.schema.outputs):
|
|
95
|
+
if node.port(name) not in connected:
|
|
96
|
+
raise GraphError(f"{node.schema.name}: unconnected port {name!r}")
|
|
97
|
+
return CompiledGraph(
|
|
98
|
+
tuple(
|
|
99
|
+
CompiledNode(
|
|
100
|
+
node.id,
|
|
101
|
+
node.node_type,
|
|
102
|
+
MappingProxyType(
|
|
103
|
+
_resolve_configuration(node.schema, node.configuration)
|
|
104
|
+
),
|
|
105
|
+
_resolved_schema(node, incoming),
|
|
106
|
+
)
|
|
107
|
+
for node in nodes
|
|
108
|
+
),
|
|
109
|
+
tuple(
|
|
110
|
+
CompiledEdge(
|
|
111
|
+
edge.source.node.id,
|
|
112
|
+
edge.source.name,
|
|
113
|
+
edge.destination.node.id,
|
|
114
|
+
edge.destination.name,
|
|
115
|
+
)
|
|
116
|
+
for edge in edges
|
|
117
|
+
),
|
|
118
|
+
)
|