nkparser 0.1.0__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nkparser
3
- Version: 0.1.0
3
+ Version: 0.3.0
4
4
  Summary: Parse, query, and serialize Foundry Nuke .nk script files
5
5
  Author-email: Virgil Sisoe <28490646+sisoe24@users.noreply.github.com>
6
6
  Requires-Python: >=3.10
@@ -0,0 +1,437 @@
1
+ Root {
2
+ inputs 0
3
+ project_directory "\[python \{nuke.script_directory()\}]"
4
+ lock_range true
5
+ format "2048 1556 0 0 2048 1556 1 2K_Super_35(full-ap)"
6
+ proxy_type scale
7
+ proxy_format "1024 778 0 0 1024 778 1 1K_Super_35(full-ap)"
8
+ }
9
+ Camera2 {
10
+ inputs 0
11
+ translate {0 1.184703231 5.879937649}
12
+ rotate {-0.7585932526 0 0}
13
+ name Camera1
14
+ xpos -87
15
+ ypos 201
16
+ }
17
+ Constant {
18
+ inputs 0
19
+ channels rgb
20
+ color {0.1411000043 0.3187749982 0.8299999833 1}
21
+ format "640 480 0 0 640 480 1 PC_Video"
22
+ name Constant2
23
+ xpos 270
24
+ ypos -137
25
+ }
26
+ Ramp {
27
+ output alpha
28
+ p0 {98 4}
29
+ p1 {102 480}
30
+ name Ramp1
31
+ xpos 270
32
+ ypos -41
33
+ }
34
+ Premult {
35
+ name Premult3
36
+ xpos 270
37
+ ypos 18
38
+ }
39
+ BasicMaterial {
40
+ name BasicMaterial1
41
+ xpos 270
42
+ ypos 88
43
+ }
44
+ Card2 {
45
+ translate {0 0 -1.169999957}
46
+ scaling {4 30 1}
47
+ type bicubic
48
+ uv_position {0.3576921821 0.01217948645}
49
+ control_points {3 3 3 6
50
+
51
+ 1 {-0.5059999824 -0.375 1.659999967} 0 {0.004000008106 0 -1.029999971} 0 {0 0 0} 0 {0 0.1250000149 -0.009999990463} 0 {0 0 0} 0 {0 0 0}
52
+ 1 {0 -0.375 0} 0 {0.1666666716 0 0} 0 {-0.1666666716 0 0} 0 {0 0.1250000149 0} 0 {0 0 0} 0 {0.5 0 0}
53
+ 1 {0.4939999878 -0.375 1.659999967} 0 {0 0 0} 0 {-0.005999982357 0 -1.039999962} 0 {0 0.1250000149 0} 0 {0 0 0} 0 {1 0 0}
54
+ 1 {-0.5059999824 0 1.659999967} 0 {0.004000008106 0 -1.029999971} 0 {0 0 0} 0 {0 0.125 0} 0 {0 -0.125 0} 0 {0 0.5 0}
55
+ 1 {0 0 0} 0 {0.1666666716 0 0} 0 {-0.1666666716 0 0} 0 {0 0.125 0} 0 {0 -0.125 0} 0 {0.5 0.5 0}
56
+ 1 {0.4939999878 0 1.659999967} 0 {0 0 0} 0 {-0.005999982357 0 -1.039999962} 0 {0 0.125 0} 0 {0 -0.125 0} 0 {1 0.5 0}
57
+ 1 {-0.5059999824 0.375 1.659999967} 0 {0.004000008106 0 -1.029999971} 0 {0 0 0} 0 {0 0 0} 0 {0 -0.1250000149 -0.009999990463} 0 {0 1 0}
58
+ 1 {0 0.375 0} 0 {0.1666666716 0 0} 0 {-0.1666666716 0 0} 0 {0 0 0} 0 {0 -0.1250000149 0} 0 {0.5 1 0}
59
+ 1 {0.4939999878 0.375 1.659999967} 0 {0 0 0} 0 {-0.005999982357 0 -1.039999962} 0 {0 0 0} 0 {0 -0.1250000149 -0.009999990463} 0 {1 1 0} }
60
+ drawPosition {-0.1717690974 -0.3658653796 0.1476006806}
61
+ name Card2
62
+ xpos 270
63
+ ypos 143
64
+ }
65
+ Constant {
66
+ inputs 0
67
+ channels rgb
68
+ format "256 256 0 0 256 256 1 square_256"
69
+ name Constant5
70
+ xpos -248
71
+ ypos -487
72
+ }
73
+ set N1b169e50 [stack 0]
74
+ Noise {
75
+ zoffset {{frame/50}}
76
+ center {128 128}
77
+ name Noise1
78
+ xpos -248
79
+ ypos -352
80
+ postage_stamp true
81
+ }
82
+ push $N1b169e50
83
+ Dot {
84
+ name Dot3
85
+ xpos -96
86
+ ypos -460
87
+ }
88
+ Radial {
89
+ area {2 2.5 254 253.5}
90
+ name Radial1
91
+ xpos -130
92
+ ypos -428
93
+ postage_stamp true
94
+ }
95
+ Merge2 {
96
+ inputs 2
97
+ operation multiply
98
+ name Merge1
99
+ xpos -130
100
+ ypos -328
101
+ }
102
+ Transform {
103
+ rotate {{frame*2 i}}
104
+ center {128 128}
105
+ name Transform1
106
+ xpos -130
107
+ ypos -294
108
+ }
109
+ Crop {
110
+ box {0 0 256 256}
111
+ reformat true
112
+ crop false
113
+ name Crop1
114
+ xpos -130
115
+ ypos -255
116
+ }
117
+ Constant {
118
+ inputs 0
119
+ channels rgb
120
+ format "256 256 0 0 256 256 1 square_256"
121
+ last 20
122
+ name Constant4
123
+ xpos -8
124
+ ypos -381
125
+ }
126
+ Noise {
127
+ size 205
128
+ zoffset 2.894736835
129
+ lacunarity 2.06
130
+ gain 0.55
131
+ gamma 0.355
132
+ center {1024 778}
133
+ name Noise2
134
+ xpos -8
135
+ ypos -294
136
+ postage_stamp true
137
+ }
138
+ Grade {
139
+ gamma 0.41
140
+ name Grade1
141
+ xpos -8
142
+ ypos -205
143
+ }
144
+ Copy {
145
+ inputs 2
146
+ from0 rgba.alpha
147
+ to0 rgba.alpha
148
+ name Copy1
149
+ xpos -130
150
+ ypos -210
151
+ }
152
+ Premult {
153
+ name Premult1
154
+ xpos -130
155
+ ypos -157
156
+ }
157
+ BlendMat {
158
+ surfaceblend modulate
159
+ name BlendMat1
160
+ xpos -130
161
+ ypos -108
162
+ }
163
+ Constant {
164
+ inputs 0
165
+ channels rgb
166
+ format "256 256 0 0 256 256 1 square_256"
167
+ name Constant3
168
+ xpos 155
169
+ ypos -254
170
+ }
171
+ Roto {
172
+ output alpha
173
+ curves {{{v x3f99999a}
174
+ {f 0}
175
+ {n
176
+ {layer Root
177
+ {f 512}
178
+ {t x43000000 x43000000}
179
+ {a}
180
+ {curvegroup Bezier4 512 bezier
181
+ {{cc
182
+ {f 8192}
183
+ {px x42a00000
184
+ {xc1480000 x3fc00000}
185
+ {x42d45581 x4235554d}
186
+ {x41480000 xbfc00000}
187
+ {xc0e00000 xc1dc0000}
188
+ {x43038000 x428a0000}
189
+ {x40e00000 x41dc0000}
190
+ {xc1151279 xc06b0d30}
191
+ {x430c8000 x42dc0000}
192
+ {x41151279 x406b0d30}
193
+ {xc0d00000 x41c00000}
194
+ {x432baac1 x42a9aaa6}
195
+ {x40d00000 xc1c00000}
196
+ {xc0a1cf03 x40487896}
197
+ {x4349aac1 x427d554d}
198
+ {x40a1cf03 xc0487896}
199
+ {x40400000 x41900000}
200
+ {x43642ac1 x4247554d}
201
+ {xc0400000 xc1900000}
202
+ {x41980000 x40200000}
203
+ {x43392ac1 x41a6aa99}
204
+ {xc1980000 xc0200000}
205
+ {xc0200000 xc1400000}
206
+ {x4295555a x41d6aa99}
207
+ {x40200000 x41400000}}} idem}
208
+ {t
209
+ {{x42a00000 x43118000}}
210
+ {{x42a00000 x424c8000}} 0
211
+ {{x42a00000 0}}
212
+ {{x42a00000 0}} 0 0 0
213
+ {{x42a00000 0}}
214
+ {{x42a00000 1}}
215
+ {{x42a00000 1}} 1
216
+ {{x42a00000 0}}}
217
+ {a spx x43000000 spy x43000000 sb 1 ltn x42a00000 ltm x42a00000 tt x40800000}}
218
+ {curvegroup Bezier3 512 bezier
219
+ {{cc
220
+ {f 8192}
221
+ {px x42a00000
222
+ {x41300000 xc0a00000}
223
+ {x41f55567 x4342553f}
224
+ {xc1300000 x40a00000}
225
+ {xc1e40000 x40e00000}
226
+ {x4299555a x4362d53f}
227
+ {x41e40000 xc0e00000}
228
+ {x41980000 x41c40000}
229
+ {x42e45581 x4347553f}
230
+ {xc1980000 xc1c40000}
231
+ {x41d40000 x41200000}
232
+ {x42b5555a x431a553f}
233
+ {xc1d40000 xc1200000}
234
+ {0 xc1840000}
235
+ {x4218aab3 x4323553f}
236
+ {0 x41840000}}} idem}
237
+ {t
238
+ {{x42a00000 x4292cccd}}
239
+ {{x42a00000 x43334ccd}} 0
240
+ {{x42a00000 0}}
241
+ {{x42a00000 0}} 0 0 0
242
+ {{x42a00000 0}}
243
+ {{x42a00000 1}}
244
+ {{x42a00000 1}} 1
245
+ {{x42a00000 0}}}
246
+ {a spx x43000000 spy x43000000 sb 1 ltn x42a00000 ltm x42a00000 tt x40800000}}
247
+ {curvegroup Bezier2 512 bezier
248
+ {{cc
249
+ {f 8192}
250
+ {px x42a00000
251
+ {x40d5b131 x41767c85}
252
+ {x42f85581 x4336d53f}
253
+ {xc0d5b11c xc1767c85}
254
+ {xc13e7bb3 x4107a5b9}
255
+ {x43322ac1 x431b553f}
256
+ {x413e7bb3 xc107a5b9}
257
+ {xc0ba028a xc1568e22}
258
+ {x43592ac1 x42bfaaa6}
259
+ {x40ba028a x41568e22}
260
+ {x415ad4fe xc11bd59b}
261
+ {x434e2ac1 x4348d53f}
262
+ {xc15ad4fe x411bd59b}}} idem}
263
+ {t
264
+ {{x42a00000 x430c0000}}
265
+ {{x42a00000 x42318000}} 0
266
+ {{x42a00000 0}}
267
+ {{x42a00000 0}} 0 0 0
268
+ {{x42a00000 0}}
269
+ {{x42a00000 1}}
270
+ {{x42a00000 1}} 1
271
+ {{x42a00000 0}}}
272
+ {a spx x43000000 spy x43000000 sb 1 ltn x42a00000 ltm x42a00000 tt x40800000}}
273
+ {curvegroup Bezier1 512 bezier
274
+ {{cc
275
+ {f 8192}
276
+ {px x42a00000
277
+ {xc0c00000 x41c80000}
278
+ {x41fd5567 x42dcaa7f}
279
+ {x40c00000 xc1c80000}
280
+ {xc1b80000 xc1000000}
281
+ {x4266aab3 x428caaa6}
282
+ {x41b80000 x41000000}
283
+ {xc0a00000 x40400000}
284
+ {x42bb555a x4296aaa6}
285
+ {x40a00000 xc0400000}
286
+ {x41980000 xc0400000}
287
+ {x429b555a x4304553f}
288
+ {xc1980000 x40400000}}} idem}
289
+ {t
290
+ {{x42a00000 x42890000}}
291
+ {{x42a00000 x42b18000}} 0
292
+ {{x42a00000 0}}
293
+ {{x42a00000 0}} 0 0 0
294
+ {{x42a00000 0}}
295
+ {{x42a00000 1}}
296
+ {{x42a00000 1}} 1
297
+ {{x42a00000 0}}}
298
+ {a spx x43000000 spy x43000000 sb 1 ltn x42a00000 ltm x42a00000 tt x40800000}}}}}}
299
+ toolbox {selectAll {
300
+ { selectAll str 1 ssx 1 ssy 1 sf 1 }
301
+ { createBezier str 1 ssx 1 ssy 1 sf 1 sb 1 tt 4 }
302
+ { createOpenSpline str 1 ssx 1 ssy 1 sf 1 sb 1 }
303
+ { createBezierCusped str 1 ssx 1 ssy 1 sf 1 sb 1 }
304
+ { createBSpline str 1 ssx 1 ssy 1 sf 1 sb 1 }
305
+ { createEllipse str 1 ssx 1 ssy 1 sf 1 sb 1 }
306
+ { createRectangle str 1 ssx 1 ssy 1 sf 1 sb 1 }
307
+ { createRectangleCusped str 1 ssx 1 ssy 1 sf 1 sb 1 }
308
+ { brush str 1 ssx 1 ssy 1 sf 1 sb 1 }
309
+ { eraser src 2 str 1 ssx 1 ssy 1 sf 1 sb 1 }
310
+ { clone src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
311
+ { reveal src 3 str 1 ssx 1 ssy 1 sf 1 sb 1 }
312
+ { dodge src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
313
+ { burn src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
314
+ { blur src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
315
+ { sharpen src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
316
+ { smear src 1 str 1 ssx 1 ssy 1 sf 1 sb 1 }
317
+ } }
318
+ toolbar_brush_hardness 0.200000003
319
+ toolbar_source_transform_scale {1 1}
320
+ toolbar_source_transform_center {320 240}
321
+ colorOverlay 0
322
+ lifetime_type "all frames"
323
+ lifetime_start 80
324
+ lifetime_end 80
325
+ view {}
326
+ motionblur_on true
327
+ motionblur_shutter_offset_type centred
328
+ source_black_outside true
329
+ createNewTrack {{-1} "-1\t(none)\t-1" "1000\tNew Track Layer\t1000"}
330
+ name Roto1
331
+ xpos 155
332
+ ypos -164
333
+ }
334
+ Card2 {
335
+ lens_in_focal 2.9
336
+ translate {-0.00400000019 0 0}
337
+ rotate {-90 0 0}
338
+ uniform_scale 0.28
339
+ control_points {3 3 3 6
340
+
341
+ 1 {-0.5 -0.5 0} 0 {0.1666666865 0 0} 0 {0 0 0} 0 {0 0.1666666865 0} 0 {0 0 0} 0 {0 0 0}
342
+ 1 {0 -0.5 0} 0 {0.1666666716 0 0} 0 {-0.1666666716 0 0} 0 {0 0.1666666865 0} 0 {0 0 0} 0 {0.5 0 0}
343
+ 1 {0.5 -0.5 0} 0 {0 0 0} 0 {-0.1666666865 0 0} 0 {0 0.1666666865 0} 0 {0 0 0} 0 {1 0 0}
344
+ 1 {-0.5 0 0} 0 {0.1666666865 0 0} 0 {0 0 0} 0 {0 0.1666666716 0} 0 {0 -0.1666666716 0} 0 {0 0.5 0}
345
+ 1 {0 0 0} 0 {0.1666666716 0 0} 0 {-0.1666666716 0 0} 0 {0 0.1666666716 0} 0 {0 -0.1666666716 0} 0 {0.5 0.5 0}
346
+ 1 {0.5 0 0} 0 {0 0 0} 0 {-0.1666666865 0 0} 0 {0 0.1666666716 0} 0 {0 -0.1666666716 0} 0 {1 0.5 0}
347
+ 1 {-0.5 0.5 0} 0 {0.1666666865 0 0} 0 {0 0 0} 0 {0 0 0} 0 {0 -0.1666666865 0} 0 {0 1 0}
348
+ 1 {0 0.5 0} 0 {0.1666666716 0 0} 0 {-0.1666666716 0 0} 0 {0 0 0} 0 {0 -0.1666666865 0} 0 {0.5 1 0}
349
+ 1 {0.5 0.5 0} 0 {0 0 0} 0 {-0.1666666865 0 0} 0 {0 0 0} 0 {0 -0.1666666865 0} 0 {1 1 0} }
350
+ name Card1
351
+ xpos 155
352
+ ypos -108
353
+ }
354
+ push 0
355
+ ParticleEmitter {
356
+ inputs 3
357
+ emit_from faces
358
+ rate 200
359
+ rate_variation 1
360
+ rate_channel rgba.alpha
361
+ lifetime 200
362
+ lifetime_variation 1
363
+ halflife 10
364
+ velocity 0.11
365
+ velocity_variation 1
366
+ size 0.36
367
+ start_frame_animation random
368
+ frame_advance constant
369
+ name ParticleEmitter1
370
+ xpos 23
371
+ ypos -108
372
+ }
373
+ ParticleDrag {
374
+ drag 0.47
375
+ name ParticleDrag1
376
+ xpos 23
377
+ ypos -62
378
+ }
379
+ ParticleTurbulence {
380
+ strength {0.005 0.005 0.005}
381
+ name ParticleTurbulence1
382
+ xpos 23
383
+ ypos -7
384
+ }
385
+ ParticleCurve {
386
+ curves {r {}
387
+ g {}
388
+ b {}
389
+ a {}
390
+ size {curve 0.5377450585 s0 t-0.3000000119 0.01470589638}
391
+ mass {}}
392
+ affect_size true
393
+ name ParticleCurve1
394
+ xpos 23
395
+ ypos 44
396
+ }
397
+ Scene {
398
+ inputs 2
399
+ name Scene1
400
+ xpos 33
401
+ ypos 122
402
+ }
403
+ Constant {
404
+ inputs 0
405
+ channels rgb
406
+ format "1920 1080 0 0 1920 1080 1 HD"
407
+ name Constant1
408
+ xpos 147
409
+ ypos 198
410
+ }
411
+ ScanlineRender {
412
+ inputs 3
413
+ motion_vectors_type velocity
414
+ name ScanlineRender1
415
+ xpos 23
416
+ ypos 222
417
+ }
418
+ Viewer {
419
+ frame_range 1-100
420
+ frame_range_lock true
421
+ downrez 2
422
+ roi {-0.2419999987 -0.5559999943 0.1930000037 0.3950000107}
423
+ input_process false
424
+ grid_display false
425
+ name Viewer1
426
+ xpos 23
427
+ ypos 285
428
+ }
429
+ StickyNote {
430
+ inputs 0
431
+ name StickyNote1
432
+ tile_color 0x9b9b9bff
433
+ label "Disable Premult in when in 3D View to see\na better representation of the textures."
434
+ note_font_size 18
435
+ xpos -478
436
+ ypos -170
437
+ }
@@ -0,0 +1,24 @@
1
+ import nkparser
2
+
3
+ script = nkparser.Script.from_file("examples/comp.nk")
4
+
5
+ print(script.nuke_version)
6
+ print(len(list(script.all_nodes())))
7
+
8
+ # Example: Find nodes by class
9
+ reads = script.query().of_class("Read").all()
10
+
11
+ # Example: Find nodes by attribute
12
+ grade = script.find(attr="label", value=".+comp")
13
+ if grade:
14
+ grade.set("disable", "true")
15
+
16
+ script.write("out/comp_modified.nk")
17
+
18
+ # Example: Filter nodes by predicate
19
+ nodes_by_name = script.query().filter(lambda n: "comp" in n.name).all()
20
+ print(f"Found {len(nodes_by_name)} nodes with 'comp' in name")
21
+
22
+ # Example: Get node connections
23
+ for node in script.all_nodes():
24
+ print(f"Node: {node.name}, Class: {node.class_name}")
@@ -203,7 +203,7 @@ class ScriptBuilder:
203
203
  children = group_children
204
204
  self._execution_stack = saved_stack
205
205
  node: Node = GroupNode(
206
- node_class=raw.node_class,
206
+ class_name=raw.node_class,
207
207
  knobs=knobs,
208
208
  children=children,
209
209
  is_unclosed=raw.is_unclosed,
@@ -212,7 +212,7 @@ class ScriptBuilder:
212
212
  )
213
213
  else:
214
214
  node = Node(
215
- node_class=raw.node_class,
215
+ class_name=raw.node_class,
216
216
  knobs=knobs,
217
217
  source_line=raw.source_line,
218
218
  source_end_line=raw.source_end_line,
@@ -23,6 +23,8 @@ Usage examples
23
23
  from __future__ import annotations
24
24
 
25
25
  import sys
26
+ import csv
27
+ import io
26
28
  import json
27
29
  import argparse
28
30
  from typing import Any
@@ -66,7 +68,7 @@ def cmd_info(args: argparse.Namespace) -> int:
66
68
  nodes = list(script.all_nodes())
67
69
 
68
70
  from collections import Counter
69
- class_counts = Counter(n.node_class for n in nodes)
71
+ class_counts = Counter(n.class_name for n in nodes)
70
72
  top = class_counts.most_common(5)
71
73
 
72
74
  errors = script.errors()
@@ -130,6 +132,21 @@ def cmd_validate(args: argparse.Namespace) -> int:
130
132
  print(json.dumps(out, indent=2))
131
133
  return _exit_code(script)
132
134
 
135
+ if getattr(args, "format", "text") == "csv":
136
+ buf = io.StringIO()
137
+ writer = csv.DictWriter(buf, fieldnames=["severity", "code", "message", "line", "col"])
138
+ writer.writeheader()
139
+ for d in script.diagnostics:
140
+ writer.writerow({
141
+ "severity": d.severity.value,
142
+ "code": d.code,
143
+ "message": d.message,
144
+ "line": d.line,
145
+ "col": d.col,
146
+ })
147
+ print(buf.getvalue(), end="")
148
+ return _exit_code(script)
149
+
133
150
  if not script.diagnostics:
134
151
  print(f"No issues found in {args.file}")
135
152
  return 0
@@ -223,27 +240,21 @@ def cmd_nodes(args: argparse.Namespace) -> int:
223
240
  )
224
241
  col_w[col] = min(_MAX_W, max(len(col), max_val))
225
242
 
226
- if getattr(args, "format", "text") == "json":
227
- def _node_dict(node: Node) -> dict[str, Any]:
228
- d: dict[str, Any] = {
229
- "class": node.node_class,
230
- "name": node.name,
231
- "xpos": int(node.xpos) if node.xpos is not None else None,
232
- "ypos": int(node.ypos) if node.ypos is not None else None,
233
- }
234
- if extra_cols:
235
- d["knobs"] = {c: node.get(c)
236
- for c in extra_cols if node.knob(c)}
237
- return d
243
+ knobs_arg = extra_cols if extra_cols else None
238
244
 
245
+ if getattr(args, "format", "text") == "json":
239
246
  out: dict[str, Any] = {
240
247
  "file": args.file,
241
- "nodes": [_node_dict(n) for n in nodes],
248
+ "nodes": [n.to_dict(knobs=knobs_arg) for n in nodes],
242
249
  "count": len(nodes),
243
250
  }
244
251
  print(json.dumps(out, indent=2))
245
252
  return _exit_code(script)
246
253
 
254
+ if getattr(args, "format", "text") == "csv":
255
+ print(script.to_csv(nodes=nodes, knobs=knobs_arg), end="")
256
+ return _exit_code(script)
257
+
247
258
  parts = [
248
259
  f"{{:<{col_w['#']}}}",
249
260
  f"{{:<{col_w['Class']}}}",
@@ -262,7 +273,7 @@ def cmd_nodes(args: argparse.Namespace) -> int:
262
273
  xp = str(int(node.xpos)) if node.xpos is not None else ""
263
274
  yp = str(int(node.ypos)) if node.ypos is not None else ""
264
275
  extra_vals = [node.get(c)[:col_w[c]] for c in extra_cols]
265
- row = [str(i), node.node_class[:col_w["Class"]],
276
+ row = [str(i), node.class_name[:col_w["Class"]],
266
277
  node.name[:col_w["Name"]], xp, yp]
267
278
  print(fmt.format(*(row + extra_vals)))
268
279
 
@@ -298,6 +309,8 @@ examples:
298
309
  nkparse nodes comp.nk --name "^Merge"
299
310
  nkparse nodes comp.nk --class Grade --attrs
300
311
  nkparse nodes comp.nk --class Grade --attrs white,multiply --format json
312
+ nkparse nodes comp.nk --format csv
313
+ nkparse validate comp.nk --format csv
301
314
  nkparse show comp.nk
302
315
  """,
303
316
  )
@@ -318,7 +331,7 @@ examples:
318
331
  "validate", help="List all diagnostics (errors and warnings)")
319
332
  p_val.add_argument("file", metavar="FILE", help=".nk file to validate")
320
333
  p_val.add_argument(
321
- "--format", choices=["text", "json"], default="text", help="Output format (default: text)"
334
+ "--format", choices=["text", "json", "csv"], default="text", help="Output format (default: text)"
322
335
  )
323
336
 
324
337
  # tree
@@ -378,7 +391,7 @@ examples:
378
391
  ),
379
392
  )
380
393
  p_nodes.add_argument(
381
- "--format", choices=["text", "json"], default="text", help="Output format (default: text)"
394
+ "--format", choices=["text", "json", "csv"], default="text", help="Output format (default: text)"
382
395
  )
383
396
 
384
397
  # show
@@ -131,8 +131,8 @@ class Knob:
131
131
 
132
132
  @dataclass
133
133
  class Node:
134
- node_class: str
135
- knobs: list[Knob] = field(default_factory=list)
134
+ class_name: str
135
+ knobs: list[Knob] = field(default_factory=list[Knob])
136
136
  source_line: int = 0
137
137
  source_end_line: int = 0
138
138
 
@@ -216,8 +216,31 @@ class Node:
216
216
 
217
217
  return Serializer._serialize_node(self)
218
218
 
219
+ def to_dict(self, knobs: Optional[list[str]] = None) -> dict:
220
+ """Return a dict representation of this node.
221
+
222
+ Parameters
223
+ ----------
224
+ knobs:
225
+ ``None`` — omit extra knobs (default).
226
+ ``["*"]`` — include all knobs as a nested dict.
227
+ ``[...]`` — include only the named knobs.
228
+ """
229
+ d: dict = {
230
+ "class": self.class_name,
231
+ "name": self.name,
232
+ "xpos": int(self.xpos) if self.xpos is not None else None,
233
+ "ypos": int(self.ypos) if self.ypos is not None else None,
234
+ }
235
+ if knobs is not None:
236
+ cols = (
237
+ [k.name for k in self.knobs] if knobs == ["*"] else knobs
238
+ )
239
+ d["knobs"] = {c: self.get(c) for c in cols if self.knob(c)}
240
+ return d
241
+
219
242
  def __repr__(self) -> str:
220
- return f"<Node {self.node_class!r} name={self.name!r}>"
243
+ return f"<Node {self.class_name!r} name={self.name!r}>"
221
244
 
222
245
  def __hash__(self) -> int:
223
246
  return id(self)
@@ -248,7 +271,7 @@ class GroupNode(Node):
248
271
  yield from child.iter_nodes(recursive=True)
249
272
 
250
273
  def __repr__(self) -> str:
251
- return f"<GroupNode {self.node_class!r} name={self.name!r} children={len(self.children)}>"
274
+ return f"<GroupNode {self.class_name!r} name={self.name!r} children={len(self.children)}>"
252
275
 
253
276
 
254
277
  # ---------------------------------------------------------------------------
@@ -398,6 +421,77 @@ class Script:
398
421
  with open(path, "w", encoding="utf-8") as fh:
399
422
  fh.write(self.to_nk())
400
423
 
424
+ def to_json(
425
+ self,
426
+ nodes: Optional[list[Node]] = None,
427
+ knobs: Optional[list[str]] = None,
428
+ ) -> str:
429
+ """Return a JSON array string of nodes.
430
+
431
+ Parameters
432
+ ----------
433
+ nodes:
434
+ Subset of nodes to include; defaults to ``all_nodes()``.
435
+ knobs:
436
+ ``None`` — omit extra knobs (default).
437
+ ``["*"]`` — include all knobs per node as a nested dict.
438
+ ``[...]`` — include only the named knobs.
439
+ """
440
+ import json
441
+
442
+ target = nodes if nodes is not None else list(self.all_nodes())
443
+ return json.dumps([n.to_dict(knobs=knobs) for n in target], indent=2)
444
+
445
+ def to_csv(
446
+ self,
447
+ nodes: Optional[list[Node]] = None,
448
+ knobs: Optional[list[str]] = None,
449
+ ) -> str:
450
+ """Return a CSV string of nodes.
451
+
452
+ Parameters
453
+ ----------
454
+ nodes:
455
+ Subset of nodes to include; defaults to ``all_nodes()``.
456
+ knobs:
457
+ ``None`` — only class/name/xpos/ypos columns (default).
458
+ ``["*"]`` — add a column for every knob found across all nodes.
459
+ ``[...]`` — add columns for the named knobs only.
460
+ """
461
+ import csv
462
+ import io
463
+
464
+ _FIXED = {"name", "xpos", "ypos"}
465
+ target = nodes if nodes is not None else list(self.all_nodes())
466
+
467
+ extra_cols: list[str] = []
468
+ if knobs is not None:
469
+ if knobs == ["*"]:
470
+ seen: dict[str, None] = {}
471
+ for node in target:
472
+ for k in node.knobs:
473
+ if k.name not in _FIXED and k.name not in seen:
474
+ seen[k.name] = None
475
+ extra_cols = list(seen)
476
+ else:
477
+ extra_cols = knobs
478
+
479
+ buf = io.StringIO()
480
+ headers = ["class", "name", "xpos", "ypos"] + extra_cols
481
+ writer = csv.DictWriter(buf, fieldnames=headers)
482
+ writer.writeheader()
483
+ for node in target:
484
+ row: dict = {
485
+ "class": node.class_name,
486
+ "name": node.name,
487
+ "xpos": int(node.xpos) if node.xpos is not None else "",
488
+ "ypos": int(node.ypos) if node.ypos is not None else "",
489
+ }
490
+ for c in extra_cols:
491
+ row[c] = node.get(c)
492
+ writer.writerow(row)
493
+ return buf.getvalue()
494
+
401
495
  # ------------------------------------------------------------------
402
496
  # Navigation
403
497
  # ------------------------------------------------------------------
@@ -472,7 +566,7 @@ class Script:
472
566
  val_rx = re.compile(value) if value is not None else None
473
567
  results: list[Node] = []
474
568
  for node in self.all_nodes():
475
- if node_class is not None and node.node_class != node_class:
569
+ if node_class is not None and node.class_name != node_class:
476
570
  continue
477
571
  if name_rx is not None and not name_rx.search(node.name):
478
572
  continue
@@ -495,7 +589,7 @@ class Script:
495
589
  def root(self) -> Optional[Node]:
496
590
  """Return the Root node, or None."""
497
591
  for node in self.nodes:
498
- if node.node_class == "Root":
592
+ if node.class_name == "Root":
499
593
  return node
500
594
  return None
501
595
 
@@ -37,7 +37,7 @@ class NodeQuery:
37
37
  def of_class(self, *classes: str) -> "NodeQuery":
38
38
  """Keep only nodes whose node_class is in *classes*."""
39
39
  class_set = set(classes)
40
- return NodeQuery(n for n in self._nodes if n.node_class in class_set)
40
+ return NodeQuery(n for n in self._nodes if n.class_name in class_set)
41
41
 
42
42
  def named(self, pattern: str) -> "NodeQuery":
43
43
  """Keep nodes whose name knob matches the regex *pattern*."""
@@ -61,7 +61,7 @@ class NodeQuery:
61
61
  results.append(node)
62
62
  return NodeQuery(results)
63
63
 
64
- def where(self, predicate: Callable[[Node], bool]) -> "NodeQuery":
64
+ def filter(self, predicate: Callable[[Node], bool]) -> "NodeQuery":
65
65
  """Keep nodes that satisfy *predicate*."""
66
66
  return NodeQuery(n for n in self._nodes if predicate(n))
67
67
 
@@ -61,7 +61,7 @@ class Serializer:
61
61
 
62
62
  @staticmethod
63
63
  def _serialize_node(node: Node) -> str:
64
- lines: list[str] = [f"{node.node_class} {{"]
64
+ lines: list[str] = [f"{node.class_name} {{"]
65
65
  for knob in node.knobs:
66
66
  lines.append(knob.raw_line)
67
67
  if isinstance(node, GroupNode):
@@ -99,7 +99,7 @@ class Validator:
99
99
  if not node.name:
100
100
  self._emit(
101
101
  DiagnosticSeverity.WARNING,
102
- f"Node of class {node.node_class!r} has no name",
102
+ f"Node of class {node.class_name!r} has no name",
103
103
  "empty-name",
104
104
  node.source_line,
105
105
  )
@@ -82,12 +82,12 @@ class TextTree:
82
82
  lines: list[str],
83
83
  ) -> None:
84
84
  connector = self.LAST_BRANCH if is_last else self.BRANCH
85
- label = f"{node.node_class}"
85
+ label = f"{node.class_name}"
86
86
  if node.name:
87
87
  label += f" [{node.name}]"
88
88
  if node._inputs:
89
89
  input_names = [
90
- (n.name or n.node_class) if n else "?"
90
+ (n.name or n.class_name) if n else "?"
91
91
  for n in node._inputs
92
92
  ]
93
93
  label += f" ← {', '.join(input_names)}"
@@ -170,7 +170,7 @@ class DotExporter:
170
170
  for node in self._script.all_nodes():
171
171
  node_id = self._node_id(node)
172
172
  label = self._node_label(node)
173
- color = self._node_color(node.node_class)
173
+ color = self._node_color(node.class_name)
174
174
  lines.append(f' {node_id} [label="{label}" fillcolor="{color}"];')
175
175
 
176
176
  # Edges
@@ -201,7 +201,7 @@ class DotExporter:
201
201
 
202
202
  @staticmethod
203
203
  def _node_label(node: Node) -> str:
204
- lines = [node.node_class]
204
+ lines = [node.class_name]
205
205
  if node.name:
206
206
  lines.append(node.name)
207
207
  return "\\n".join(lines)
@@ -1,17 +1,13 @@
1
1
  [project]
2
2
  name = "nkparser"
3
- version = "0.1.0"
3
+ version = "0.3.0"
4
4
  description = "Parse, query, and serialize Foundry Nuke .nk script files"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
7
- dependencies = []
8
7
  authors = [
9
8
  {name = "Virgil Sisoe", email = "28490646+sisoe24@users.noreply.github.com"}
10
9
  ]
11
10
 
12
- [tool.uv]
13
- default-groups = ["dev"]
14
-
15
11
  [tool.hatch.build.targets.sdist]
16
12
  exclude = ["sample", "tests", "out", ".uv-cache", "todo.md"]
17
13
 
@@ -301,7 +301,7 @@ wheels = [
301
301
 
302
302
  [[package]]
303
303
  name = "nkparser"
304
- version = "0.1.0"
304
+ version = "0.3.0"
305
305
  source = { editable = "." }
306
306
 
307
307
  [package.optional-dependencies]
@@ -309,38 +309,20 @@ dev = [
309
309
  { name = "mypy" },
310
310
  { name = "pytest" },
311
311
  { name = "pytest-cov" },
312
- { name = "ruff" },
313
312
  ]
314
313
  graphviz = [
315
314
  { name = "graphviz" },
316
315
  ]
317
316
 
318
- [package.dev-dependencies]
319
- dev = [
320
- { name = "mypy" },
321
- { name = "pytest" },
322
- { name = "pytest-cov" },
323
- { name = "ruff" },
324
- ]
325
-
326
317
  [package.metadata]
327
318
  requires-dist = [
328
319
  { name = "graphviz", marker = "extra == 'graphviz'", specifier = ">=0.20" },
329
320
  { name = "mypy", marker = "extra == 'dev'" },
330
321
  { name = "pytest", marker = "extra == 'dev'", specifier = ">=7" },
331
322
  { name = "pytest-cov", marker = "extra == 'dev'" },
332
- { name = "ruff", marker = "extra == 'dev'" },
333
323
  ]
334
324
  provides-extras = ["graphviz", "dev"]
335
325
 
336
- [package.metadata.requires-dev]
337
- dev = [
338
- { name = "mypy" },
339
- { name = "pytest", specifier = ">=7" },
340
- { name = "pytest-cov" },
341
- { name = "ruff" },
342
- ]
343
-
344
326
  [[package]]
345
327
  name = "packaging"
346
328
  version = "26.0"
@@ -409,31 +391,6 @@ wheels = [
409
391
  { url = "https://files.pythonhosted.org/packages/9d/7a/d968e294073affff457b041c2be9868a40c1c71f4a35fcc1e45e5493067b/pytest_cov-7.1.0-py3-none-any.whl", hash = "sha256:a0461110b7865f9a271aa1b51e516c9a95de9d696734a2f71e3e78f46e1d4678", size = 22876, upload-time = "2026-03-21T20:11:14.438Z" },
410
392
  ]
411
393
 
412
- [[package]]
413
- name = "ruff"
414
- version = "0.15.8"
415
- source = { registry = "https://pypi.org/simple" }
416
- sdist = { url = "https://files.pythonhosted.org/packages/14/b0/73cf7550861e2b4824950b8b52eebdcc5adc792a00c514406556c5b80817/ruff-0.15.8.tar.gz", hash = "sha256:995f11f63597ee362130d1d5a327a87cb6f3f5eae3094c620bcc632329a4d26e", size = 4610921, upload-time = "2026-03-26T18:39:38.675Z" }
417
- wheels = [
418
- { url = "https://files.pythonhosted.org/packages/4a/92/c445b0cd6da6e7ae51e954939cb69f97e008dbe750cfca89b8cedc081be7/ruff-0.15.8-py3-none-linux_armv6l.whl", hash = "sha256:cbe05adeba76d58162762d6b239c9056f1a15a55bd4b346cfd21e26cd6ad7bc7", size = 10527394, upload-time = "2026-03-26T18:39:41.566Z" },
419
- { url = "https://files.pythonhosted.org/packages/eb/92/f1c662784d149ad1414cae450b082cf736430c12ca78367f20f5ed569d65/ruff-0.15.8-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:d3e3d0b6ba8dca1b7ef9ab80a28e840a20070c4b62e56d675c24f366ef330570", size = 10905693, upload-time = "2026-03-26T18:39:30.364Z" },
420
- { url = "https://files.pythonhosted.org/packages/ca/f2/7a631a8af6d88bcef997eb1bf87cc3da158294c57044aafd3e17030613de/ruff-0.15.8-py3-none-macosx_11_0_arm64.whl", hash = "sha256:6ee3ae5c65a42f273f126686353f2e08ff29927b7b7e203b711514370d500de3", size = 10323044, upload-time = "2026-03-26T18:39:33.37Z" },
421
- { url = "https://files.pythonhosted.org/packages/67/18/1bf38e20914a05e72ef3b9569b1d5c70a7ef26cd188d69e9ca8ef588d5bf/ruff-0.15.8-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fdce027ada77baa448077ccc6ebb2fa9c3c62fd110d8659d601cf2f475858d94", size = 10629135, upload-time = "2026-03-26T18:39:44.142Z" },
422
- { url = "https://files.pythonhosted.org/packages/d2/e9/138c150ff9af60556121623d41aba18b7b57d95ac032e177b6a53789d279/ruff-0.15.8-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:12e617fc01a95e5821648a6df341d80456bd627bfab8a829f7cfc26a14a4b4a3", size = 10348041, upload-time = "2026-03-26T18:39:52.178Z" },
423
- { url = "https://files.pythonhosted.org/packages/02/f1/5bfb9298d9c323f842c5ddeb85f1f10ef51516ac7a34ba446c9347d898df/ruff-0.15.8-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:432701303b26416d22ba696c39f2c6f12499b89093b61360abc34bcc9bf07762", size = 11121987, upload-time = "2026-03-26T18:39:55.195Z" },
424
- { url = "https://files.pythonhosted.org/packages/10/11/6da2e538704e753c04e8d86b1fc55712fdbdcc266af1a1ece7a51fff0d10/ruff-0.15.8-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d910ae974b7a06a33a057cb87d2a10792a3b2b3b35e33d2699fdf63ec8f6b17a", size = 11951057, upload-time = "2026-03-26T18:39:19.18Z" },
425
- { url = "https://files.pythonhosted.org/packages/83/f0/c9208c5fd5101bf87002fed774ff25a96eea313d305f1e5d5744698dc314/ruff-0.15.8-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2033f963c43949d51e6fdccd3946633c6b37c484f5f98c3035f49c27395a8ab8", size = 11464613, upload-time = "2026-03-26T18:40:06.301Z" },
426
- { url = "https://files.pythonhosted.org/packages/f8/22/d7f2fabdba4fae9f3b570e5605d5eb4500dcb7b770d3217dca4428484b17/ruff-0.15.8-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0f29b989a55572fb885b77464cf24af05500806ab4edf9a0fd8977f9759d85b1", size = 11257557, upload-time = "2026-03-26T18:39:57.972Z" },
427
- { url = "https://files.pythonhosted.org/packages/71/8c/382a9620038cf6906446b23ce8632ab8c0811b8f9d3e764f58bedd0c9a6f/ruff-0.15.8-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:ac51d486bf457cdc985a412fb1801b2dfd1bd8838372fc55de64b1510eff4bec", size = 11169440, upload-time = "2026-03-26T18:39:22.205Z" },
428
- { url = "https://files.pythonhosted.org/packages/4d/0d/0994c802a7eaaf99380085e4e40c845f8e32a562e20a38ec06174b52ef24/ruff-0.15.8-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:c9861eb959edab053c10ad62c278835ee69ca527b6dcd72b47d5c1e5648964f6", size = 10605963, upload-time = "2026-03-26T18:39:46.682Z" },
429
- { url = "https://files.pythonhosted.org/packages/19/aa/d624b86f5b0aad7cef6bbf9cd47a6a02dfdc4f72c92a337d724e39c9d14b/ruff-0.15.8-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:8d9a5b8ea13f26ae90838afc33f91b547e61b794865374f114f349e9036835fb", size = 10357484, upload-time = "2026-03-26T18:39:49.176Z" },
430
- { url = "https://files.pythonhosted.org/packages/35/c3/e0b7835d23001f7d999f3895c6b569927c4d39912286897f625736e1fd04/ruff-0.15.8-py3-none-musllinux_1_2_i686.whl", hash = "sha256:c2a33a529fb3cbc23a7124b5c6ff121e4d6228029cba374777bd7649cc8598b8", size = 10830426, upload-time = "2026-03-26T18:40:03.702Z" },
431
- { url = "https://files.pythonhosted.org/packages/f0/51/ab20b322f637b369383adc341d761eaaa0f0203d6b9a7421cd6e783d81b9/ruff-0.15.8-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:75e5cd06b1cf3f47a3996cfc999226b19aa92e7cce682dcd62f80d7035f98f49", size = 11345125, upload-time = "2026-03-26T18:39:27.799Z" },
432
- { url = "https://files.pythonhosted.org/packages/37/e6/90b2b33419f59d0f2c4c8a48a4b74b460709a557e8e0064cf33ad894f983/ruff-0.15.8-py3-none-win32.whl", hash = "sha256:bc1f0a51254ba21767bfa9a8b5013ca8149dcf38092e6a9eb704d876de94dc34", size = 10571959, upload-time = "2026-03-26T18:39:36.117Z" },
433
- { url = "https://files.pythonhosted.org/packages/1f/a2/ef467cb77099062317154c63f234b8a7baf7cb690b99af760c5b68b9ee7f/ruff-0.15.8-py3-none-win_amd64.whl", hash = "sha256:04f79eff02a72db209d47d665ba7ebcad609d8918a134f86cb13dd132159fc89", size = 11743893, upload-time = "2026-03-26T18:39:25.01Z" },
434
- { url = "https://files.pythonhosted.org/packages/15/e2/77be4fff062fa78d9b2a4dea85d14785dac5f1d0c1fb58ed52331f0ebe28/ruff-0.15.8-py3-none-win_arm64.whl", hash = "sha256:cf891fa8e3bb430c0e7fac93851a5978fc99c8fa2c053b57b118972866f8e5f2", size = 11048175, upload-time = "2026-03-26T18:40:01.06Z" },
435
- ]
436
-
437
394
  [[package]]
438
395
  name = "tomli"
439
396
  version = "2.4.1"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes