baghban 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. baghban-0.1.0/CHANGELOG.md +20 -0
  2. baghban-0.1.0/LICENSE +202 -0
  3. baghban-0.1.0/MANIFEST.in +4 -0
  4. baghban-0.1.0/NOTICE +11 -0
  5. baghban-0.1.0/PKG-INFO +342 -0
  6. baghban-0.1.0/README.md +318 -0
  7. baghban-0.1.0/ROADMAP.md +33 -0
  8. baghban-0.1.0/TESTING.md +65 -0
  9. baghban-0.1.0/examples/demo.py +43 -0
  10. baghban-0.1.0/examples/rig_v1/foraging.bonsai +100 -0
  11. baghban-0.1.0/examples/rig_v1/modules/CameraRecorder.bonsai +31 -0
  12. baghban-0.1.0/examples/rig_v2/foraging.bonsai +102 -0
  13. baghban-0.1.0/examples/rig_v2/modules/CameraRecorder.bonsai +35 -0
  14. baghban-0.1.0/pyproject.toml +40 -0
  15. baghban-0.1.0/setup.cfg +4 -0
  16. baghban-0.1.0/src/baghban/__init__.py +23 -0
  17. baghban-0.1.0/src/baghban/__main__.py +5 -0
  18. baghban-0.1.0/src/baghban/checks.py +384 -0
  19. baghban-0.1.0/src/baghban/cli.py +211 -0
  20. baghban-0.1.0/src/baghban/diff.py +169 -0
  21. baghban-0.1.0/src/baghban/info.py +156 -0
  22. baghban-0.1.0/src/baghban/model.py +600 -0
  23. baghban-0.1.0/src/baghban/render.py +207 -0
  24. baghban-0.1.0/src/baghban.egg-info/PKG-INFO +342 -0
  25. baghban-0.1.0/src/baghban.egg-info/SOURCES.txt +64 -0
  26. baghban-0.1.0/src/baghban.egg-info/dependency_links.txt +1 -0
  27. baghban-0.1.0/src/baghban.egg-info/entry_points.txt +2 -0
  28. baghban-0.1.0/src/baghban.egg-info/requires.txt +6 -0
  29. baghban-0.1.0/src/baghban.egg-info/top_level.txt +1 -0
  30. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflow/ArgumentRange/TwoInputs.bonsai +25 -0
  31. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflow/SharedProperties/Mixed.bonsai +22 -0
  32. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflow/SharedProperties/MixedNestedGroup.bonsai +37 -0
  33. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflow/SharedProperties/NestedOperator.bonsai +32 -0
  34. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflow/SharedProperties/NonEqualProperty.bonsai +11 -0
  35. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflow/SharedProperties/NonEqualPropertyNestedGroup.bonsai +29 -0
  36. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflow/SharedProperties/Pure.bonsai +22 -0
  37. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflow/SharedProperties/PureNestedGroup.bonsai +35 -0
  38. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflow.bonsai +13 -0
  39. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflowInner.bonsai +27 -0
  40. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflowMissing.bonsai +20 -0
  41. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflowMissingOuter.bonsai +32 -0
  42. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflowOuter.bonsai +28 -0
  43. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflowPolymorphic.bonsai +27 -0
  44. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflowPolymorphicInner.bonsai +32 -0
  45. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflowPolymorphicOuter.bonsai +28 -0
  46. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflowSelfInner.bonsai +12 -0
  47. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Core.Tests/IncludeWorkflowSelfOuter.bonsai +12 -0
  48. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Editor.Tests/ConnectComponentWithHigherIndexIntoLowerIndex.bonsai +44 -0
  49. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Editor.Tests/IncludeEmbeddedWorkflowBuildException.bonsai +12 -0
  50. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Editor.Tests/IncludeEmbeddedWorkflowRuntimeException.bonsai +12 -0
  51. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Editor.Tests/IncludeWorkflowBuildException.bonsai +12 -0
  52. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Editor.Tests/IncludeWorkflowRuntimeException.bonsai +12 -0
  53. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Editor.Tests/MissingSubject.bonsai +22 -0
  54. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Editor.Tests/MissingTypes.bonsai +14 -0
  55. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Editor.Tests/NestedSubscribeSubjectWithClosestRedefinition.bonsai +71 -0
  56. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Editor.Tests/NestedWorkflowBuildException.bonsai +35 -0
  57. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Editor.Tests/NestedWorkflowRuntimeException.bonsai +38 -0
  58. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Editor.Tests/ReorderComponentWithHigherIndexIntoLowerIndex.bonsai +44 -0
  59. baghban-0.1.0/tests/data/bonsai_upstream/Bonsai.Editor.Tests/ReorderDanglingBranchWithPredecessors.bonsai +85 -0
  60. baghban-0.1.0/tests/data/bonsai_upstream/LICENSE +19 -0
  61. baghban-0.1.0/tests/data/bonsai_upstream/README.md +12 -0
  62. baghban-0.1.0/tests/test_checks.py +324 -0
  63. baghban-0.1.0/tests/test_diff_render_cli.py +158 -0
  64. baghban-0.1.0/tests/test_ground_truth.py +80 -0
  65. baghban-0.1.0/tests/test_model.py +109 -0
  66. baghban-0.1.0/tests/xmlkit.py +115 -0
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (unreleased)
4
+
5
+ First version.
6
+
7
+ - Reader for `.bonsai` files: types resolved through xmlns, `Combinator`,
8
+ `Source` and `Disable` unwrapped, nested workflows, Bonsai's scoping rules
9
+ (groups and includes transparent, other nested workflows real scopes),
10
+ includes resolved from the top-level folder or, with `--resource-root`,
11
+ from embedded resources; include property overrides applied, through
12
+ nested includes too.
13
+ - Findings: `SILENT_OVERWRITE`, `FAILS_ON_REPEAT`, `DUPLICATE_OUTPUT`,
14
+ `DANGLING_SUBJECT`, `DUPLICATE_SUBJECT`, `MISSING_INCLUDE`,
15
+ `RECURSIVE_INCLUDE`, `INVALID_INCLUDE`, `DISABLED_WRITER`,
16
+ `APPENDS_ACROSS_RUNS`, `UNUSED_SUBJECT`; what could not be checked is
17
+ reported, not guessed.
18
+ - Commands: `check`, `show`, `render` (HTML, Mermaid, DOT), `diff`, `deps`,
19
+ `params`, `fingerprint` (with `--fields` for daftar).
20
+ - Tests: 113, including agreement with Bonsai's own test workflows.
baghban-0.1.0/LICENSE ADDED
@@ -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,4 @@
1
+ include README.md TESTING.md ROADMAP.md CHANGELOG.md LICENSE NOTICE
2
+ recursive-include tests *.py *.bonsai *.md LICENSE
3
+ recursive-include examples *.py *.bonsai
4
+ global-exclude __pycache__ *.pyc *.html
baghban-0.1.0/NOTICE ADDED
@@ -0,0 +1,11 @@
1
+ baghban
2
+ Copyright 2026 Aslan Satary Dizaji
3
+
4
+ Licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ tests/data/bonsai_upstream/ contains test workflows copied unchanged from
7
+ Bonsai (https://github.com/bonsai-rx/bonsai), Copyright (c) 2011-2025 Bonsai
8
+ Foundation CIC and Contributors, under the MIT licence
9
+ (tests/data/bonsai_upstream/LICENSE). They are used only as test data.
10
+
11
+ baghban reads the .bonsai file format; it contains no Bonsai code.
baghban-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,342 @@
1
+ Metadata-Version: 2.4
2
+ Name: baghban
3
+ Version: 0.1.0
4
+ Summary: Check, draw and compare Bonsai workflows on any machine, before the rig runs.
5
+ Author: Aslan Satary Dizaji
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/aslansd/baghban
8
+ Project-URL: Issues, https://github.com/aslansd/baghban/issues
9
+ Keywords: bonsai,bonsai-rx,neuroscience,experiments,lint,reproducibility
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Scientific/Engineering
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ License-File: NOTICE
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest>=7; extra == "dev"
21
+ Provides-Extra: provenance
22
+ Requires-Dist: daftar; extra == "provenance"
23
+ Dynamic: license-file
24
+
25
+ # baghban
26
+
27
+ **باغبان** — *bağban, gardener.* The same word in Persian and Azerbaijani.
28
+ Someone has to tend the bonsai.
29
+
30
+ **Know what will go wrong with a Bonsai rig before the session runs.**
31
+ baghban reads [Bonsai](https://bonsai-rx.org) workflow files and reports the
32
+ faults that lose data without an error: a writer that overwrites every trial,
33
+ two cameras recording into one file, a logger left disabled after debugging,
34
+ a subject name with a typo. It also draws, compares and fingerprints
35
+ workflows, so you can review a rig from a Mac or Linux laptop.
36
+
37
+ ```
38
+ pip install baghban
39
+ ```
40
+
41
+ Python 3.10+. Apache 2.0. **No dependencies. No Windows, no .NET, no Bonsai
42
+ installation.** baghban reads the `.bonsai` XML; it never runs a workflow.
43
+
44
+ ---
45
+
46
+ ## The failure that matters
47
+
48
+ Bonsai's costliest bugs do not crash anything. The workflow builds, the
49
+ cameras light up, the session runs for an hour, and the problem surfaces weeks
50
+ later in analysis:
51
+
52
+ - A `CsvWriter` inside a per-trial `SelectMany` with `Overwrite=True` and
53
+ `Suffix=None` is opened again for every trial and replaces the file each
54
+ time. After 200 trials, the file holds trial 200.
55
+ - A camera-recording module included twice, without giving each copy its own
56
+ file name, sends both cameras to `camera.avi`.
57
+ - A writer disabled while debugging a sensor stays disabled. Nothing is
58
+ recorded, and nothing says so.
59
+
60
+ Each of these is fully determined by the workflow file. None of them is
61
+ reported by Bonsai before the data is gone.
62
+
63
+ ---
64
+
65
+ ## The thirty-second version
66
+
67
+ ```
68
+ $ baghban check rig/foraging.bonsai
69
+
70
+ [error] DUPLICATE_OUTPUT Include 'modules/CameraRecorder.bonsai' #3 > VideoWriter 'camera.avi' #1
71
+ Another writer also writes 'camera.avi' (Include 'modules/CameraRecorder.bonsai' #1 >
72
+ VideoWriter 'camera.avi' #1). Two writers cannot hold the same file: one of them fails,
73
+ or they overwrite each other. This is common when a module containing a writer is
74
+ included twice without giving each copy its own file name.
75
+ fix: Give each writer its own file name; for included modules, externalize FileName and
76
+ set it on each IncludeWorkflow.
77
+
78
+ [error] SILENT_OVERWRITE SelectMany 'Trial' #6 > CsvWriter 'trial.csv' #2
79
+ Overwrite=True with Suffix=None inside SelectMany 'Trial': the writer is opened again
80
+ for every element (e.g. every trial), and each time it replaces 'trial.csv'. Only the
81
+ last element's data survives the session.
82
+ fix: Use Suffix=Timestamp or FileCount to keep one file per element, or move the writer
83
+ after the SelectMany to collect all elements in one file.
84
+
85
+ [error] DANGLING_SUBJECT SubscribeSubject 'TrialEnds' #8
86
+ No subject named 'TrialEnds' is declared in this scope or any enclosing one, so Bonsai
87
+ will fail to build the workflow.
88
+ fix: Did you mean 'TrialEnd'?
89
+
90
+ [warning] DISABLED_WRITER CsvWriter 'licks.csv' #11
91
+ This CsvWriter is disabled, so nothing will be written to 'licks.csv'. Disabling a
92
+ writer while debugging and forgetting to re-enable it loses whole sessions without an
93
+ error.
94
+ fix: Re-enable it, or delete it if the data is not needed.
95
+
96
+ 3 errors, 1 warning, 1 info in 22 nodes.
97
+ ```
98
+
99
+ That is `examples/rig_v1`, a foraging rig with two cameras, a lick sensor
100
+ and 10 s trials. `examples/rig_v2` is the same rig fixed, and checks clean.
101
+ `check` exits 1 when there are errors, so it can gate a commit or a CI run.
102
+
103
+ `#n` is a node's position in its own workflow, as in the XML, which is how
104
+ the two copies of the included module are told apart.
105
+
106
+ ---
107
+
108
+ ## Findings
109
+
110
+ | Finding | Severity | Question it answers |
111
+ | --- | --- | --- |
112
+ | `SILENT_OVERWRITE` | error | Will a writer replace data from an earlier run, or from an earlier trial in the same run, without an error? |
113
+ | `FAILS_ON_REPEAT` | error | Will a writer inside a per-trial loop raise "file already exists" on trial 2 and end the session? |
114
+ | `DUPLICATE_OUTPUT` | error | Do two writers write to the same file? |
115
+ | `DANGLING_SUBJECT` | error | Does a `SubscribeSubject` or `MulticastSubject` name a subject that is not declared where it can see it? |
116
+ | `DUPLICATE_SUBJECT` | error | Are two subjects with one name declared in the same scope? |
117
+ | `MISSING_INCLUDE` | error | Does an `IncludeWorkflow` point at a file that does not exist? |
118
+ | `RECURSIVE_INCLUDE` | error | Do workflows include each other in a cycle? |
119
+ | `INVALID_INCLUDE` | error | Is an included file not a readable workflow? |
120
+ | `DISABLED_WRITER` | warning | Is a writer (or a group holding one) disabled, so nothing is recorded? |
121
+ | `APPENDS_ACROSS_RUNS` | info | Does every run append to the same file, and repeat the CSV header mid-file? |
122
+ | `UNUSED_SUBJECT` | info | Is a subject declared but never subscribed to? |
123
+
124
+ `SILENT_OVERWRITE` drops to a warning when the file name is externalized:
125
+ then it is only safe if the launcher sets a new name each run, which baghban
126
+ cannot see.
127
+
128
+ ### How it decides
129
+
130
+ baghban models the parts of Bonsai's build process the checks depend on, as
131
+ the Bonsai source implements them (Bonsai.Core, Bonsai.System):
132
+
133
+ - **Scopes.** `GroupWorkflow` and `IncludeWorkflow` build in a `GroupContext`
134
+ that forwards every declaration to its parent, so a subject declared inside
135
+ a group is visible beside it. Every other nested workflow (`SelectMany`,
136
+ `Defer`, `CreateObservable`, ...) builds in a new `BuildContext`: lookups
137
+ fall back outwards, declarations stay inside. Declaring a name twice in one
138
+ build context is a build error.
139
+ - **Loops.** `SelectMany`, `CreateObservable` and `WindowWorkflow` subscribe
140
+ their nested workflow once per input element, so a writer inside one is
141
+ opened once per element, typically once per trial.
142
+ - **Writers.** `CsvWriter` and the `FileSink`/`StreamSink` families
143
+ (`VideoWriter`, `TextWriter`, `AudioWriter`, `MatrixWriter`, `ImageWriter`)
144
+ open their file on subscription, check `File.Exists(path) && !Overwrite`,
145
+ then create it. Any operator with `Suffix` plus `FileName` or `Path` is
146
+ treated as a writer, which also covers third-party writers that follow the
147
+ convention.
148
+ - **Includes.** Paths are opened relative to the working directory, which
149
+ the editor sets to the top-level workflow's folder. baghban resolves nested
150
+ includes the same way: relative to the top-level file, not to the file
151
+ containing the include. Values written on an `IncludeWorkflow` set the
152
+ included file's externalized properties, and baghban applies them, through
153
+ nested includes too, so checks see the effective file names.
154
+ - **Disabled nodes** are not built: a disabled subject declares nothing, and
155
+ a disabled include is not opened.
156
+
157
+ ### Staying quiet when it cannot know
158
+
159
+ A checker that cries wolf on good rigs gets switched off. When the XML is not
160
+ enough to be sure, baghban says what it did not check instead of guessing:
161
+
162
+ - an include it cannot open (an embedded resource of a NuGet package, or an
163
+ absolute Windows path on a Mac) suspends subject checks in that scope,
164
+ because the include may declare the subject;
165
+ - a file name assigned from data at run time (`PropertyMapping`,
166
+ `InputMapping`) is not judged;
167
+ - types are not checked, because baghban has no catalogue of what each
168
+ package contains.
169
+
170
+ These appear as `not checked:` lines under the report.
171
+
172
+ ---
173
+
174
+ ## Checked against something that does not depend on it
175
+
176
+ Bonsai's own test suite ships 30 small workflows and asserts which of them
177
+ fail to build (`WorkflowRunnerTests`, `IncludeWorkflowTests`). They are
178
+ included unchanged in `tests/data/bonsai_upstream` (MIT licence), and baghban
179
+ must agree with Bonsai on every one:
180
+
181
+ | Bonsai's expectation | baghban |
182
+ | --- | --- |
183
+ | `*BuildException` workflows fail to build (undeclared `MulticastSubject`, directly and through file and embedded includes) | `DANGLING_SUBJECT` |
184
+ | `IncludeWorkflowSelfOuter` fails to build (self-inclusion) | `RECURSIVE_INCLUDE` |
185
+ | `IncludeWorkflowMissing` fails to build (missing nested include) | `MISSING_INCLUDE` |
186
+ | `*RuntimeException` workflows build, then fail while running (division by zero) | no findings: not a static problem |
187
+ | `NestedSubscribeSubjectWithClosestRedefinition` builds | no findings |
188
+ | `MissingTypes` names a type that does not exist | no findings: baghban does not guess about types |
189
+ | Nested include property: the outer include's `OuterCount = 2` reaches the inner `Take.Count` | `Take.Count == "2"` |
190
+
191
+ On the file-writer findings, where Bonsai has no test fixtures, each finding
192
+ is tested in both directions on paired workflows: it must fire where the fault
193
+ exists and stay quiet on the nearest workflow without it (see `TESTING.md`).
194
+
195
+ ---
196
+
197
+ ## Commands
198
+
199
+ ```
200
+ baghban check WORKFLOW|DIR ... findings; exit 1 on errors (--strict: on warnings too)
201
+ baghban show WORKFLOW the workflow as a tree
202
+ baghban render WORKFLOW [-f html] draw it: html (default), mermaid, dot
203
+ baghban diff A B what changed, by meaning; exit 0 if equivalent
204
+ baghban deps WORKFLOW assemblies (= packages) and includes it needs
205
+ baghban params WORKFLOW externalized properties and their values
206
+ baghban fingerprint WORKFLOW content hash, stable across re-saves (--fields for daftar)
207
+ ```
208
+
209
+ `check` accepts folders. A file that another checked file includes is checked
210
+ through its includer, where the subjects and file names it relies on are
211
+ defined, rather than on its own. Every command takes `--resource-root
212
+ ASSEMBLY=DIR` to follow embedded-resource includes (`Path="MyPackage:Module.bonsai"`)
213
+ into a package's source folder.
214
+
215
+ ### See a workflow without the editor
216
+
217
+ ```
218
+ baghban render rig/foraging.bonsai && open foraging.html
219
+ ```
220
+
221
+ writes one HTML page with the graph (nested workflows as boxes, disabled nodes
222
+ dashed, nodes with findings outlined in red or orange), the findings table and
223
+ a text outline. It loads the Mermaid script from a CDN, so it needs a network
224
+ connection to draw. `-f mermaid` output also renders directly in GitHub
225
+ markdown and pull requests.
226
+
227
+ ### Diff by meaning
228
+
229
+ Nodes are addressed by position in the XML, so inserting one node renumbers
230
+ every edge after it, and `git diff` becomes noise. `baghban diff` matches
231
+ nodes by what they are: named nodes by type and name, others by type and
232
+ occurrence ("the second CsvWriter in the Trial SelectMany"):
233
+
234
+ ```
235
+ $ baghban diff rig_v1/foraging.bonsai rig_v2/foraging.bonsai
236
+
237
+ ~ CsvWriter#1 ('licks.csv') enabled
238
+ + CsvWriter#2 ('trials.csv')
239
+ ~ Include(modules/CameraRecorder.bonsai) FileName: (unset) -> left.avi
240
+ ~ Include(modules/CameraRecorder.bonsai)/VideoWriter ('left.avi') Suffix: None -> Timestamp
241
+ - SelectMany:Trial/CsvWriter ('trial.csv')
242
+ + SubscribeSubject:TrialEnd
243
+ - SubscribeSubject:TrialEnds
244
+ ~ Timer Period: PT10S -> PT12S
245
+ ...
246
+ ```
247
+
248
+ Included files are expanded, so a change inside a module shows up under each
249
+ include that uses it. Inserting an unrelated node does not disturb other keys;
250
+ it does shift the keys of later unnamed nodes of the same type in the same
251
+ workflow, which naming them avoids.
252
+
253
+ ---
254
+
255
+ ## Python
256
+
257
+ ```
258
+ import baghban
259
+
260
+ doc = baghban.load("rig/foraging.bonsai")
261
+ report = baghban.check(doc)
262
+ print(report.summary())
263
+ report.errors # [Finding(code, severity, message, location, file, node, hint)]
264
+
265
+ for node in doc.walk(): # every node, includes expanded
266
+ if node.is_writer:
267
+ print(node.location(), node.properties)
268
+
269
+ baghban.diff(baghban.load("v1.bonsai"), baghban.load("v2.bonsai")).summary()
270
+ baghban.fingerprint(doc)
271
+ baghban.mermaid(doc)
272
+ ```
273
+
274
+ ---
275
+
276
+ ## Provenance, with daftar
277
+
278
+ A session's data is only as interpretable as the record of the protocol that
279
+ produced it, and that protocol is a `.bonsai` file plus its includes plus the
280
+ parameter values it ran with. `baghban.manifest_fields` turns that into flat
281
+ fields for [daftar](https://pypi.org/project/daftar/):
282
+
283
+ ```
284
+ with daftar.track("session-0412", params=baghban.manifest_fields(doc)) as run:
285
+ ...
286
+ ```
287
+
288
+ ```
289
+ $ baghban fingerprint rig_v2/foraging.bonsai --fields
290
+ {
291
+ "bonsai.workflow": "examples/rig_v2/foraging.bonsai",
292
+ "bonsai.version": "2.9.0",
293
+ "bonsai.fingerprint": "fc07dd88c5331b2dfeb53671f5e05cd80b03f49e96060cb58a745b1682b600fd",
294
+ "bonsai.param.TrialInterval": "PT12S",
295
+ "bonsai.include.modules/CameraRecorder.bonsai": "ok"
296
+ }
297
+ ```
298
+
299
+ The fingerprint ignores whitespace, attribute order, namespace prefixes and
300
+ the `Version` stamp the editor writes on every save, and changes with every
301
+ operator, property value, edge, disabled flag and included file's content.
302
+ Two sessions that ran the same protocol then diff as identical in daftar,
303
+ even when someone re-saved the file in between.
304
+
305
+ ---
306
+
307
+ ## Try it
308
+
309
+ ```
310
+ python examples/demo.py
311
+ ```
312
+
313
+ Shows, checks, fixes, diffs and fingerprints the example rig, and writes
314
+ `examples/rig_v1.html`.
315
+
316
+ ## Status
317
+
318
+ Research prototype, honestly labelled.
319
+
320
+ - The findings are grounded in the Bonsai source and agree with Bonsai's own
321
+ test suite, but have not yet been run across a broad set of real rigs. How
322
+ often they fire on published workflows, and how often wrongly, is the next
323
+ thing to measure (see `ROADMAP.md`).
324
+ - No finding has yet been confirmed by running a workflow. `Bonsai.Player`
325
+ runs on macOS under .NET 8, so the writer findings can be confirmed on a Mac
326
+ by running the fixtures and watching the files; that is on the roadmap.
327
+ - Embedded-resource includes from installed NuGet packages are not followed
328
+ yet unless you point `--resource-root` at the package source.
329
+ - Timing problems (unbounded `Zip` queues, timestamps taken after heavy
330
+ processing) need stream rates the XML rarely states, and are not checked.
331
+
332
+ ## Development
333
+
334
+ ```
335
+ pip install -e ".[dev]"
336
+ pytest -q
337
+ ```
338
+
339
+ ## Licence
340
+
341
+ Apache 2.0. `tests/data/bonsai_upstream` contains test workflows from Bonsai
342
+ (MIT); see `NOTICE`. baghban contains no Bonsai code.