ryucad 0.9.2rc4__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.
- ryucad-0.9.2rc4/.gitignore +6 -0
- ryucad-0.9.2rc4/LICENSE +201 -0
- ryucad-0.9.2rc4/NOTICE +25 -0
- ryucad-0.9.2rc4/PKG-INFO +121 -0
- ryucad-0.9.2rc4/README.md +103 -0
- ryucad-0.9.2rc4/pyproject.toml +46 -0
- ryucad-0.9.2rc4/src/ryucad/__init__.py +76 -0
- ryucad-0.9.2rc4/src/ryucad/_codes.py +756 -0
- ryucad-0.9.2rc4/src/ryucad/_errors.py +165 -0
- ryucad-0.9.2rc4/src/ryucad/_find.py +66 -0
- ryucad-0.9.2rc4/src/ryucad/_meta.py +9 -0
- ryucad-0.9.2rc4/src/ryucad/_session.py +391 -0
- ryucad-0.9.2rc4/src/ryucad/py.typed +0 -0
- ryucad-0.9.2rc4/tests/fake_session.py +124 -0
- ryucad-0.9.2rc4/tests/support.py +16 -0
- ryucad-0.9.2rc4/tests/test_client.py +242 -0
- ryucad-0.9.2rc4/tests/test_errors.py +117 -0
- ryucad-0.9.2rc4/tests/test_fake.py +30 -0
- ryucad-0.9.2rc4/tests/test_find.py +72 -0
- ryucad-0.9.2rc4/tests/test_package.py +22 -0
- ryucad-0.9.2rc4/tests/test_session.py +215 -0
ryucad-0.9.2rc4/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
ryucad-0.9.2rc4/NOTICE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
ryucad
|
|
2
|
+
Copyright 2026 Seiraiyu
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see
|
|
5
|
+
LICENSE). It covers the ryucad, ryukei, ryupdm, ryueda and ryudfm crates
|
|
6
|
+
and everything else in this repository unless a file or its folder says
|
|
7
|
+
otherwise.
|
|
8
|
+
|
|
9
|
+
Third-party material kept under its own licence:
|
|
10
|
+
|
|
11
|
+
- Fonts embedded in ryucad-app, ryueda and the shared shell (ryu-app):
|
|
12
|
+
Inter (SIL Open Font License 1.1), JetBrains Mono (SIL Open Font
|
|
13
|
+
License 1.1) and Phosphor icons (MIT). See
|
|
14
|
+
crates/ryu-app/fonts/LICENSES.md and crates/ryueda/fonts/LICENSES.md.
|
|
15
|
+
- Test corpora: NIST's MBE PMI test models (public domain) in
|
|
16
|
+
crates/ryustep/tests/corpus, and cuts of them in
|
|
17
|
+
crates/ryukei/tests/data/nist_*.body; boards in crates/ryudfm/tests/corpus and
|
|
18
|
+
schematic references in crates/ryueda/tests/schematic_corpus, each
|
|
19
|
+
under the licence its manifest and LICENSE file name.
|
|
20
|
+
- Code adapted from other projects says so where it appears, with its
|
|
21
|
+
licence and copyright (for example egui_tiles, MIT OR Apache-2.0, in
|
|
22
|
+
crates/ryucad-app/src/ui/shell.rs).
|
|
23
|
+
|
|
24
|
+
Algorithms ported from NVIDIA's SMLib (USD BRep, Apache License 2.0)
|
|
25
|
+
keep SMLib's NOTICE and credit it in the files that hold them.
|
ryucad-0.9.2rc4/PKG-INFO
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ryucad
|
|
3
|
+
Version: 0.9.2rc4
|
|
4
|
+
Summary: The official Python client for ryucad, CAD built for AI agents to drive
|
|
5
|
+
Project-URL: Homepage, https://github.com/Seiraiyu/ryucad
|
|
6
|
+
Project-URL: Issues, https://github.com/Seiraiyu/ryucad/issues
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
License-File: NOTICE
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# ryucad for Python
|
|
20
|
+
|
|
21
|
+
The official Python client for [ryucad](https://github.com/Seiraiyu/ryucad),
|
|
22
|
+
CAD built for AI agents to drive. It runs an installed `ryucad` as
|
|
23
|
+
`ryucad session --stdio`, one process per connection, and sends ryucad's
|
|
24
|
+
requests by name: the framing, binary answers, progress and typed errors
|
|
25
|
+
are handled for you. Standard library only, Python 3.10 or newer,
|
|
26
|
+
Apache-2.0.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
The package finds an installed ryucad; it ships none. Install ryucad first:
|
|
31
|
+
|
|
32
|
+
curl -fsSL https://github.com/Seiraiyu/ryucad/releases/latest/download/install.sh | sh
|
|
33
|
+
|
|
34
|
+
or on Windows (PowerShell):
|
|
35
|
+
|
|
36
|
+
irm https://github.com/Seiraiyu/ryucad/releases/latest/download/install.ps1 | iex
|
|
37
|
+
|
|
38
|
+
then the package:
|
|
39
|
+
|
|
40
|
+
pip install ryucad
|
|
41
|
+
|
|
42
|
+
It looks for ryucad in `connect(exe=...)`, then `RYUCAD_EXE`, then `ryucad`
|
|
43
|
+
on `PATH`, then the installers' `~/.ryucad/bin` (`RYUCAD_HOME`'s `bin`
|
|
44
|
+
when that is set), and raises `ryucad.NotInstalled` with the two commands
|
|
45
|
+
above when there is none. It needs ryucad's protocol 3 or newer (the one
|
|
46
|
+
with `batch`) and warns when ryucad is older than the package.
|
|
47
|
+
|
|
48
|
+
## A build script
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
import ryucad
|
|
52
|
+
|
|
53
|
+
def plate(name, width):
|
|
54
|
+
return ryucad.op(
|
|
55
|
+
"part.ensure",
|
|
56
|
+
part=name,
|
|
57
|
+
params={"w": f"{width} mm"},
|
|
58
|
+
features=[{"id": "base", "type": "box", "params": {"x": "w", "y": 30, "z": 6}}],
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
with ryucad.connect("~/work/fixture") as cad:
|
|
62
|
+
answer = cad.batch([plate("left", 40), plate("right", 60)], prune=True)
|
|
63
|
+
print(answer["parts"]) # {"left": {"status": "created", ...}, ...}
|
|
64
|
+
|
|
65
|
+
again = cad.batch([plate("left", 40), plate("right", 60)], prune=True)
|
|
66
|
+
assert again["written"] == 0 # nothing changed, nothing written
|
|
67
|
+
|
|
68
|
+
cad.call("export", part="left", out="left.step") # relative to the project
|
|
69
|
+
stl = cad.call("export", part="left", format="stl")
|
|
70
|
+
print(len(stl.data), "bytes of STL")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
- `cad.call(method, params=None, **params)` sends any request by name and
|
|
74
|
+
returns its `result` as a dict; an answer that carries bytes has them in
|
|
75
|
+
`.data`. A param named like a Python keyword (`from`) goes in the dict.
|
|
76
|
+
- `cad.batch(ops, expect=None, dry_run=False, rebuild=None, prune=False)`
|
|
77
|
+
runs many edits as one checked, logged, undoable change; `ryucad.op`
|
|
78
|
+
builds each op. `cad.ensure(part, features, ...)` is `part.ensure` alone,
|
|
79
|
+
and `cad.undo()` takes back this participant's latest change.
|
|
80
|
+
- `connect(folder, as_=..., no_daemon=..., exe=..., env=..., on_progress=...)`:
|
|
81
|
+
`as_` names the participant in the activity log; `on_progress` receives
|
|
82
|
+
each `progress` line of a request sent with `progress=True`; after the
|
|
83
|
+
script's own `subscribe`, notifications collect in `cad.notifications`.
|
|
84
|
+
- One request at a time per session (threads take turns); open two
|
|
85
|
+
sessions for two at once. Ctrl+C cancels a long request and waits for its
|
|
86
|
+
`cancelled` answer before `KeyboardInterrupt` reaches the script.
|
|
87
|
+
|
|
88
|
+
## Errors
|
|
89
|
+
|
|
90
|
+
A refusal raises `ryucad.RyucadError` with ryucad's stable `code`, a
|
|
91
|
+
`message`, its `details`, and `pointer`, `path`, `op` and `method` when it
|
|
92
|
+
names them (a batch's failing op). It is one of `FixableError` (the agent
|
|
93
|
+
can fix it), `UsageError`, `ProjectError` (no usable project) or
|
|
94
|
+
`ExternalError` (not the agent's fault), with named classes for the codes
|
|
95
|
+
scripts branch on: `Conflict`, `NotFound`, `RebuildFailed`,
|
|
96
|
+
`HasDependents`, `AssemblyOverconstrained`, `Cancelled`, `DaemonError`.
|
|
97
|
+
Every other code is matched by `e.code == ryucad.Code.SOME_CODE`. The
|
|
98
|
+
client's own errors are `NotInstalled`, `Incompatible`, `SessionClosed` and
|
|
99
|
+
`ProtocolError`; all derive from `ryucad.Error`.
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
try:
|
|
103
|
+
cad.batch(ops)
|
|
104
|
+
except ryucad.FixableError as e:
|
|
105
|
+
print(e.code, e.op, e.pointer, e.message)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## The protocol
|
|
109
|
+
|
|
110
|
+
Methods, params and answers are ryucad's own: `ryucad <command> --help`
|
|
111
|
+
and `--json` name them, and the repository's
|
|
112
|
+
[scripting notes](https://github.com/Seiraiyu/ryucad/blob/main/docs/claude/ryucad-scripting.md)
|
|
113
|
+
describe `session --stdio`, `batch` and `part.ensure`. The package adds no
|
|
114
|
+
second API.
|
|
115
|
+
|
|
116
|
+
## Versions
|
|
117
|
+
|
|
118
|
+
The package is released with ryucad, from the same tag: ryucad `vX.Y.Z`
|
|
119
|
+
publishes `ryucad` `X.Y.Z` here, and a pre-release `vX.Y.Z-pre.N`
|
|
120
|
+
publishes `X.Y.ZrcN` (install it with `pip install --pre`). Keep the
|
|
121
|
+
package and ryucad at the same version.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# ryucad for Python
|
|
2
|
+
|
|
3
|
+
The official Python client for [ryucad](https://github.com/Seiraiyu/ryucad),
|
|
4
|
+
CAD built for AI agents to drive. It runs an installed `ryucad` as
|
|
5
|
+
`ryucad session --stdio`, one process per connection, and sends ryucad's
|
|
6
|
+
requests by name: the framing, binary answers, progress and typed errors
|
|
7
|
+
are handled for you. Standard library only, Python 3.10 or newer,
|
|
8
|
+
Apache-2.0.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
The package finds an installed ryucad; it ships none. Install ryucad first:
|
|
13
|
+
|
|
14
|
+
curl -fsSL https://github.com/Seiraiyu/ryucad/releases/latest/download/install.sh | sh
|
|
15
|
+
|
|
16
|
+
or on Windows (PowerShell):
|
|
17
|
+
|
|
18
|
+
irm https://github.com/Seiraiyu/ryucad/releases/latest/download/install.ps1 | iex
|
|
19
|
+
|
|
20
|
+
then the package:
|
|
21
|
+
|
|
22
|
+
pip install ryucad
|
|
23
|
+
|
|
24
|
+
It looks for ryucad in `connect(exe=...)`, then `RYUCAD_EXE`, then `ryucad`
|
|
25
|
+
on `PATH`, then the installers' `~/.ryucad/bin` (`RYUCAD_HOME`'s `bin`
|
|
26
|
+
when that is set), and raises `ryucad.NotInstalled` with the two commands
|
|
27
|
+
above when there is none. It needs ryucad's protocol 3 or newer (the one
|
|
28
|
+
with `batch`) and warns when ryucad is older than the package.
|
|
29
|
+
|
|
30
|
+
## A build script
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import ryucad
|
|
34
|
+
|
|
35
|
+
def plate(name, width):
|
|
36
|
+
return ryucad.op(
|
|
37
|
+
"part.ensure",
|
|
38
|
+
part=name,
|
|
39
|
+
params={"w": f"{width} mm"},
|
|
40
|
+
features=[{"id": "base", "type": "box", "params": {"x": "w", "y": 30, "z": 6}}],
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
with ryucad.connect("~/work/fixture") as cad:
|
|
44
|
+
answer = cad.batch([plate("left", 40), plate("right", 60)], prune=True)
|
|
45
|
+
print(answer["parts"]) # {"left": {"status": "created", ...}, ...}
|
|
46
|
+
|
|
47
|
+
again = cad.batch([plate("left", 40), plate("right", 60)], prune=True)
|
|
48
|
+
assert again["written"] == 0 # nothing changed, nothing written
|
|
49
|
+
|
|
50
|
+
cad.call("export", part="left", out="left.step") # relative to the project
|
|
51
|
+
stl = cad.call("export", part="left", format="stl")
|
|
52
|
+
print(len(stl.data), "bytes of STL")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- `cad.call(method, params=None, **params)` sends any request by name and
|
|
56
|
+
returns its `result` as a dict; an answer that carries bytes has them in
|
|
57
|
+
`.data`. A param named like a Python keyword (`from`) goes in the dict.
|
|
58
|
+
- `cad.batch(ops, expect=None, dry_run=False, rebuild=None, prune=False)`
|
|
59
|
+
runs many edits as one checked, logged, undoable change; `ryucad.op`
|
|
60
|
+
builds each op. `cad.ensure(part, features, ...)` is `part.ensure` alone,
|
|
61
|
+
and `cad.undo()` takes back this participant's latest change.
|
|
62
|
+
- `connect(folder, as_=..., no_daemon=..., exe=..., env=..., on_progress=...)`:
|
|
63
|
+
`as_` names the participant in the activity log; `on_progress` receives
|
|
64
|
+
each `progress` line of a request sent with `progress=True`; after the
|
|
65
|
+
script's own `subscribe`, notifications collect in `cad.notifications`.
|
|
66
|
+
- One request at a time per session (threads take turns); open two
|
|
67
|
+
sessions for two at once. Ctrl+C cancels a long request and waits for its
|
|
68
|
+
`cancelled` answer before `KeyboardInterrupt` reaches the script.
|
|
69
|
+
|
|
70
|
+
## Errors
|
|
71
|
+
|
|
72
|
+
A refusal raises `ryucad.RyucadError` with ryucad's stable `code`, a
|
|
73
|
+
`message`, its `details`, and `pointer`, `path`, `op` and `method` when it
|
|
74
|
+
names them (a batch's failing op). It is one of `FixableError` (the agent
|
|
75
|
+
can fix it), `UsageError`, `ProjectError` (no usable project) or
|
|
76
|
+
`ExternalError` (not the agent's fault), with named classes for the codes
|
|
77
|
+
scripts branch on: `Conflict`, `NotFound`, `RebuildFailed`,
|
|
78
|
+
`HasDependents`, `AssemblyOverconstrained`, `Cancelled`, `DaemonError`.
|
|
79
|
+
Every other code is matched by `e.code == ryucad.Code.SOME_CODE`. The
|
|
80
|
+
client's own errors are `NotInstalled`, `Incompatible`, `SessionClosed` and
|
|
81
|
+
`ProtocolError`; all derive from `ryucad.Error`.
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
try:
|
|
85
|
+
cad.batch(ops)
|
|
86
|
+
except ryucad.FixableError as e:
|
|
87
|
+
print(e.code, e.op, e.pointer, e.message)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## The protocol
|
|
91
|
+
|
|
92
|
+
Methods, params and answers are ryucad's own: `ryucad <command> --help`
|
|
93
|
+
and `--json` name them, and the repository's
|
|
94
|
+
[scripting notes](https://github.com/Seiraiyu/ryucad/blob/main/docs/claude/ryucad-scripting.md)
|
|
95
|
+
describe `session --stdio`, `batch` and `part.ensure`. The package adds no
|
|
96
|
+
second API.
|
|
97
|
+
|
|
98
|
+
## Versions
|
|
99
|
+
|
|
100
|
+
The package is released with ryucad, from the same tag: ryucad `vX.Y.Z`
|
|
101
|
+
publishes `ryucad` `X.Y.Z` here, and a pre-release `vX.Y.Z-pre.N`
|
|
102
|
+
publishes `X.Y.ZrcN` (install it with `pip install --pre`). Keep the
|
|
103
|
+
package and ryucad at the same version.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ryucad"
|
|
7
|
+
# The version comes from ryucad's release tag, never from this file: the
|
|
8
|
+
# repository holds 0.0.0, as the workspace does, and the release stamps it
|
|
9
|
+
# (scripts/stamp-version.sh, ryucad plan 32.B).
|
|
10
|
+
version = "0.9.2rc4"
|
|
11
|
+
description = "The official Python client for ryucad, CAD built for AI agents to drive"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
license = "Apache-2.0"
|
|
15
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
16
|
+
dependencies = []
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Topic :: Scientific/Engineering",
|
|
22
|
+
"Topic :: Multimedia :: Graphics :: 3D Modeling",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/Seiraiyu/ryucad"
|
|
28
|
+
Issues = "https://github.com/Seiraiyu/ryucad/issues"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.wheel]
|
|
31
|
+
packages = ["src/ryucad"]
|
|
32
|
+
|
|
33
|
+
[tool.hatch.build.targets.sdist]
|
|
34
|
+
include = ["src/ryucad", "tests", "README.md", "LICENSE", "NOTICE"]
|
|
35
|
+
|
|
36
|
+
[tool.ruff]
|
|
37
|
+
target-version = "py310"
|
|
38
|
+
line-length = 100
|
|
39
|
+
|
|
40
|
+
[tool.ruff.lint]
|
|
41
|
+
# Named, not ruff's default set, which grows between releases.
|
|
42
|
+
select = ["E", "F", "W", "B", "UP", "I"]
|
|
43
|
+
|
|
44
|
+
[tool.mypy]
|
|
45
|
+
python_version = "3.10"
|
|
46
|
+
strict = true
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""The official Python client for ryucad: one ``ryucad session --stdio``
|
|
2
|
+
per :func:`connect`, ryucad's requests by name, typed errors.
|
|
3
|
+
|
|
4
|
+
import ryucad
|
|
5
|
+
|
|
6
|
+
with ryucad.connect("~/work/gearbox") as cad:
|
|
7
|
+
cad.batch([ryucad.op("part.ensure", part="shaft", features=[...])], prune=True)
|
|
8
|
+
|
|
9
|
+
Methods, params and answers are the protocol's, as ``ryucad <command>
|
|
10
|
+
--help`` and docs/claude/ryucad-scripting.md name them.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from ._codes import EXIT, Code
|
|
14
|
+
from ._errors import (
|
|
15
|
+
AssemblyOverconstrained,
|
|
16
|
+
Cancelled,
|
|
17
|
+
Conflict,
|
|
18
|
+
DaemonError,
|
|
19
|
+
Error,
|
|
20
|
+
ExternalError,
|
|
21
|
+
FixableError,
|
|
22
|
+
HasDependents,
|
|
23
|
+
Incompatible,
|
|
24
|
+
NotFound,
|
|
25
|
+
NotInstalled,
|
|
26
|
+
ProjectError,
|
|
27
|
+
ProtocolError,
|
|
28
|
+
RebuildFailed,
|
|
29
|
+
RyucadError,
|
|
30
|
+
SessionClosed,
|
|
31
|
+
UsageError,
|
|
32
|
+
)
|
|
33
|
+
from ._find import find
|
|
34
|
+
from ._meta import VERSION as __version__
|
|
35
|
+
from ._session import (
|
|
36
|
+
Answer,
|
|
37
|
+
BatchAnswer,
|
|
38
|
+
EnsureAnswer,
|
|
39
|
+
PartStatus,
|
|
40
|
+
Session,
|
|
41
|
+
Status,
|
|
42
|
+
connect,
|
|
43
|
+
op,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
__all__ = [
|
|
47
|
+
"Answer",
|
|
48
|
+
"BatchAnswer",
|
|
49
|
+
"EnsureAnswer",
|
|
50
|
+
"PartStatus",
|
|
51
|
+
"Status",
|
|
52
|
+
"op",
|
|
53
|
+
"Session",
|
|
54
|
+
"connect",
|
|
55
|
+
"Code",
|
|
56
|
+
"EXIT",
|
|
57
|
+
"AssemblyOverconstrained",
|
|
58
|
+
"Cancelled",
|
|
59
|
+
"Conflict",
|
|
60
|
+
"DaemonError",
|
|
61
|
+
"Error",
|
|
62
|
+
"ExternalError",
|
|
63
|
+
"FixableError",
|
|
64
|
+
"HasDependents",
|
|
65
|
+
"Incompatible",
|
|
66
|
+
"NotFound",
|
|
67
|
+
"NotInstalled",
|
|
68
|
+
"ProjectError",
|
|
69
|
+
"ProtocolError",
|
|
70
|
+
"RebuildFailed",
|
|
71
|
+
"RyucadError",
|
|
72
|
+
"SessionClosed",
|
|
73
|
+
"UsageError",
|
|
74
|
+
"__version__",
|
|
75
|
+
"find",
|
|
76
|
+
]
|