Commit 0fd0332
feat(cli, python): programmatic interface to cli with python bindings (#2677)
Closes #2671
## Goals
1. Have `hugr` cli available in environment when installed via uv (`uvx
hugr --help`)
2. Allow use of cli functionality from python package without spawning
subprocess
## Implications
- Either ship binary with wheel or bind the function directly - chose
the latter as it is more flexible and avoids a bunch of build faff
- CLI uses argc + stdin for input and stdout for output (by default), we
need a way to do this via binding i/o to avoid subprocess
## Primary outcomes
- Cli invocation bound via pyo3 to python "package script" with same
name as binary, meeting goal 1
- hugr-cli refactored to read inputs from a reader and write outputs to
a writer when appropriate, satisfying goal 2. Uses an "override" pattern
- when i/o is specified it overrides the corresponding cli-arg
## Secondary outcomes
- CLI main.rs contents moved to lib.rs, allowing use by library
dependants
- Make tracing a default feature for hugr-cli (not used by hugr-py)
- `cli` module in python to wrap core sub-commands and parameters, with
simply typed interfaces
- Python test cli use replaced with bound function calls - meaning no
need to build cli before running python tests
- Model loading in python via conversion to json uses cli convert
function rather than dedicated binding
- Dedicated cargo profile for python wheel for smaller wheels (very open
to critique on this)
- Pydantic models to parse `describe` json output
- Remove parallel pytest since it is now faster without it
## Possible issues
- Versioning: the cli version is pinned to the rust crates, the python
package is not. Meaning `uvx hugr --version` will report a different
value to `uv --with hugr run python -c "import hugr;
print(hugr.__version__)"`. Are we ok with this?
---------
Co-authored-by: Alec Edgington <[email protected]>1 parent c722823 commit 0fd0332
File tree
24 files changed
+1032
-292
lines changed- .github/workflows
- hugr-cli
- src
- tests
- hugr-py
- rust
- src/hugr
- _hugr
- tests
24 files changed
+1032
-292
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
| |||
68 | 66 | | |
69 | 67 | | |
70 | 68 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | 69 | | |
94 | | - | |
| 70 | + | |
95 | 71 | | |
96 | 72 | | |
97 | 73 | | |
| |||
110 | 86 | | |
111 | 87 | | |
112 | 88 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | 89 | | |
120 | 90 | | |
121 | 91 | | |
| |||
125 | 95 | | |
126 | 96 | | |
127 | 97 | | |
128 | | - | |
129 | 98 | | |
130 | 99 | | |
131 | 100 | | |
132 | 101 | | |
133 | 102 | | |
134 | | - | |
135 | 103 | | |
136 | 104 | | |
137 | 105 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
25 | 29 | | |
26 | 30 | | |
27 | 31 | | |
28 | | - | |
29 | | - | |
| 32 | + | |
| 33 | + | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | | - | |
51 | | - | |
52 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
53 | 65 | | |
54 | 66 | | |
55 | 67 | | |
| |||
78 | 90 | | |
79 | 91 | | |
80 | 92 | | |
81 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
82 | 98 | | |
83 | 99 | | |
84 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
85 | 106 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
77 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
78 | 87 | | |
79 | 88 | | |
80 | 89 | | |
81 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
82 | 95 | | |
83 | 96 | | |
84 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
85 | 102 | | |
86 | 103 | | |
87 | 104 | | |
88 | 105 | | |
89 | | - | |
| 106 | + | |
90 | 107 | | |
91 | 108 | | |
92 | 109 | | |
| |||
96 | 113 | | |
97 | 114 | | |
98 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
99 | 123 | | |
100 | 124 | | |
101 | 125 | | |
102 | 126 | | |
103 | | - | |
| 127 | + | |
104 | 128 | | |
105 | | - | |
| 129 | + | |
106 | 130 | | |
107 | 131 | | |
108 | 132 | | |
109 | 133 | | |
110 | 134 | | |
111 | 135 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
133 | 141 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
150 | 175 | | |
151 | | - | |
152 | 176 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
162 | 187 | | |
| 188 | + | |
| 189 | + | |
163 | 190 | | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
170 | 205 | | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
175 | 213 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
181 | 218 | | |
182 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
183 | 223 | | |
| 224 | + | |
| 225 | + | |
184 | 226 | | |
185 | 227 | | |
186 | 228 | | |
| |||
0 commit comments