lockwire 0.2.6__tar.gz → 0.2.7__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.
- {lockwire-0.2.6 → lockwire-0.2.7}/PKG-INFO +17 -15
- {lockwire-0.2.6 → lockwire-0.2.7}/README.md +10 -5
- {lockwire-0.2.6 → lockwire-0.2.7}/pyproject.toml +18 -53
- lockwire-0.2.7/src/lockwire/__init__.py +46 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/__main__.py +2 -2
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/agent_setup.py +30 -10
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/api.py +23 -4
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/api_payload.py +52 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/catalog.py +107 -4
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/catalog_seed.yaml +206 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/checks.py +1072 -170
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/cli.py +329 -61
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/edit.py +25 -6
- lockwire-0.2.7/src/lockwire/examples/arm/contract.yaml +335 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/humanoid/contract.yaml +643 -643
- lockwire-0.2.7/src/lockwire/examples/quadruped/contract.yaml +490 -0
- lockwire-0.2.7/src/lockwire/examples/rover/contract.yaml +322 -0
- lockwire-0.2.7/src/lockwire/examples/servo-bench.yaml +156 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/hook_check.py +7 -3
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/mcp_server.py +134 -14
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/mesh_simple.py +3 -1
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/page.py +17 -5
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/parts_list.py +12 -2
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/plan_payload.py +2 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/plugins.py +11 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/report.py +20 -17
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/report_html.py +1 -1
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/report_json.py +12 -2
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/scene_urdf.py +6 -3
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/schema.py +192 -15
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/serve.py +89 -3
- lockwire-0.2.7/src/lockwire/servo_bus.py +240 -0
- lockwire-0.2.7/src/lockwire/servo_bus_dxl.py +135 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/start_operation.py +106 -10
- lockwire-0.2.7/src/lockwire/swap.py +382 -0
- lockwire-0.2.7/src/lockwire/thrust.py +77 -0
- lockwire-0.2.7/src/lockwire/thrust_tables.yaml +133 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/urdf.py +120 -33
- lockwire-0.2.6/src/lockwire/__init__.py +0 -21
- lockwire-0.2.6/src/lockwire/examples/arm/contract.yaml +0 -335
- lockwire-0.2.6/src/lockwire/examples/quadruped/contract.yaml +0 -490
- lockwire-0.2.6/src/lockwire/examples/rover/contract.yaml +0 -322
- lockwire-0.2.6/src/lockwire/examples/servo-bench.yaml +0 -113
- lockwire-0.2.6/src/lockwire_pro/__init__.py +0 -0
- lockwire-0.2.6/src/lockwire_pro/_ccx_owner.py +0 -72
- lockwire-0.2.6/src/lockwire_pro/actuator_case.py +0 -517
- lockwire-0.2.6/src/lockwire_pro/analysis.py +0 -4142
- lockwire-0.2.6/src/lockwire_pro/api_payload_pro.py +0 -576
- lockwire-0.2.6/src/lockwire_pro/api_pro.py +0 -747
- lockwire-0.2.6/src/lockwire_pro/baseline.py +0 -1496
- lockwire-0.2.6/src/lockwire_pro/cli_pro.py +0 -1243
- lockwire-0.2.6/src/lockwire_pro/command_record.py +0 -413
- lockwire-0.2.6/src/lockwire_pro/health.py +0 -1441
- lockwire-0.2.6/src/lockwire_pro/jobs.py +0 -1713
- lockwire-0.2.6/src/lockwire_pro/motion-admission.json +0 -5
- lockwire-0.2.6/src/lockwire_pro/observation_bridge.py +0 -284
- lockwire-0.2.6/src/lockwire_pro/page_pro.py +0 -166
- lockwire-0.2.6/src/lockwire_pro/paid_checks.py +0 -1536
- lockwire-0.2.6/src/lockwire_pro/plugin.py +0 -28
- lockwire-0.2.6/src/lockwire_pro/preflight/__init__.py +0 -33
- lockwire-0.2.6/src/lockwire_pro/preflight/envelopes.py +0 -62
- lockwire-0.2.6/src/lockwire_pro/preflight/report.py +0 -53
- lockwire-0.2.6/src/lockwire_pro/preflight/report_html.py +0 -280
- lockwire-0.2.6/src/lockwire_pro/preflight/runner.py +0 -503
- lockwire-0.2.6/src/lockwire_pro/preflight/source.py +0 -613
- lockwire-0.2.6/src/lockwire_pro/preflight/stages/__init__.py +0 -6
- lockwire-0.2.6/src/lockwire_pro/preflight/stages/command_motion.py +0 -126
- lockwire-0.2.6/src/lockwire_pro/preflight/stages/commands.py +0 -323
- lockwire-0.2.6/src/lockwire_pro/preflight/stages/coverage.py +0 -62
- lockwire-0.2.6/src/lockwire_pro/preflight/stages/cross_record.py +0 -348
- lockwire-0.2.6/src/lockwire_pro/preflight/stages/cross_signal.py +0 -321
- lockwire-0.2.6/src/lockwire_pro/preflight/stages/enumeration.py +0 -95
- lockwire-0.2.6/src/lockwire_pro/preflight/stages/flow.py +0 -759
- lockwire-0.2.6/src/lockwire_pro/preflight/stages/liveness.py +0 -132
- lockwire-0.2.6/src/lockwire_pro/preflight/stages/sanity.py +0 -484
- lockwire-0.2.6/src/lockwire_pro/recording.py +0 -541
- lockwire-0.2.6/src/lockwire_pro/ros2bag.py +0 -342
- lockwire-0.2.6/src/lockwire_pro/ros2bag_example.py +0 -146
- lockwire-0.2.6/src/lockwire_pro/ros2bag_example.yaml +0 -43
- lockwire-0.2.6/src/lockwire_pro/sample_local.py +0 -365
- lockwire-0.2.6/src/lockwire_pro/sample_remote.py +0 -385
- lockwire-0.2.6/src/lockwire_pro/serve_pro.py +0 -597
- lockwire-0.2.6/src/lockwire_pro/stats/__init__.py +0 -14
- lockwire-0.2.6/src/lockwire_pro/stats/clusters.py +0 -135
- lockwire-0.2.6/src/lockwire_pro/stats/cusum.py +0 -218
- lockwire-0.2.6/src/lockwire_pro/stats/neff.py +0 -94
- lockwire-0.2.6/src/lockwire_pro/stats/wilks.py +0 -215
- lockwire-0.2.6/src/lockwire_pro/ulog.py +0 -312
- {lockwire-0.2.6 → lockwire-0.2.7}/LICENSE +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/NOTICE +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/_filelock.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/advice.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/bench.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/blame.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/catalog_robots.yaml +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/check_sim.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/cli_line.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/confine.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/constraints.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/copy.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/describe.py +0 -0
- {lockwire-0.2.6/src/lockwire_pro/stats → lockwire-0.2.7/src/lockwire}/drift.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/emit_ts.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/arm/LICENSE +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/arm/NOTICE +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/arm/plan.yaml +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/arm/scene.glb +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/arm/starter.json +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/drone/contract.yaml +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/drone/plan.yaml +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/drone/scene.glb +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/drone/starter.json +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/humanoid/NOTICE +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/humanoid/plan.yaml +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/humanoid/scene.glb +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/humanoid/starter.json +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/quadruped/NOTICE +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/quadruped/plan.yaml +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/quadruped/scene.glb +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/quadruped/starter.json +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/rover/NOTICE +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/rover/plan.yaml +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/rover/scene.glb +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/examples/rover/starter.json +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/export_mhs.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/factdiff.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/fieldpath.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/forces.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/gitref.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/hw.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/mechanism.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/mesh_dae.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/plan.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/review_draft.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/scan.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/scene.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/scene_import.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/scene_view.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/sdf.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/statics.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/units.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/vcs.py +0 -0
- {lockwire-0.2.6 → lockwire-0.2.7}/src/lockwire/whatif.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lockwire
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: The physical-assumption contract for robots: checks that a robot's declared parts (power, weight, bus, torque) add up
|
|
5
5
|
Keywords: robotics,urdf,ros,preflight,lockfile,ci,hardware,drone
|
|
6
6
|
Author: Shivansh
|
|
@@ -16,28 +16,25 @@ Classifier: Topic :: Scientific/Engineering
|
|
|
16
16
|
Classifier: Topic :: Software Development :: Quality Assurance
|
|
17
17
|
Classifier: Topic :: Software Development :: Testing
|
|
18
18
|
Requires-Dist: numpy>=2.5.1
|
|
19
|
-
Requires-Dist: pydantic>=2.13.4
|
|
19
|
+
Requires-Dist: pydantic>=2.13.4,<3
|
|
20
20
|
Requires-Dist: rich>=15.0.0
|
|
21
|
-
Requires-Dist: ruamel-yaml>=0.19.1
|
|
22
|
-
Requires-Dist: typer>=0.26.8
|
|
21
|
+
Requires-Dist: ruamel-yaml>=0.19.1,<0.20
|
|
22
|
+
Requires-Dist: typer>=0.26.8,<0.29
|
|
23
23
|
Requires-Dist: xacro>=2.1.1
|
|
24
|
-
Requires-Dist:
|
|
25
|
-
Requires-Dist: mcp>=2.2.0 ; extra == 'mcp'
|
|
24
|
+
Requires-Dist: pyserial>=3.5 ; extra == 'bus'
|
|
25
|
+
Requires-Dist: mcp>=2.2.0,<3 ; extra == 'mcp'
|
|
26
26
|
Requires-Dist: pyjwt>=2.15 ; extra == 'mcp'
|
|
27
27
|
Requires-Dist: robot-descriptions>=3.3.0,<4 ; extra == 'robots'
|
|
28
28
|
Requires-Dist: xacrodoc>=2.0.1 ; extra == 'robots'
|
|
29
|
-
Requires-Dist: mcap>=1.4.0 ; extra == 'ros2bag'
|
|
30
|
-
Requires-Dist: mcap-ros2-support>=0.5.7 ; extra == 'ros2bag'
|
|
31
29
|
Requires-Dist: fastapi>=0.141.1 ; extra == 'serve'
|
|
32
30
|
Requires-Dist: uvicorn>=0.52.4 ; extra == 'serve'
|
|
33
31
|
Requires-Python: >=3.12
|
|
34
32
|
Project-URL: Homepage, https://github.com/Shivansh2703/lockwire
|
|
35
33
|
Project-URL: Repository, https://github.com/Shivansh2703/lockwire
|
|
36
34
|
Project-URL: Issues, https://github.com/Shivansh2703/lockwire/issues
|
|
37
|
-
Provides-Extra:
|
|
35
|
+
Provides-Extra: bus
|
|
38
36
|
Provides-Extra: mcp
|
|
39
37
|
Provides-Extra: robots
|
|
40
|
-
Provides-Extra: ros2bag
|
|
41
38
|
Provides-Extra: serve
|
|
42
39
|
Description-Content-Type: text/markdown
|
|
43
40
|
|
|
@@ -120,15 +117,19 @@ Cursor, Claude Desktop and other agents: [docs/guides/agents.md](docs/guides/age
|
|
|
120
117
|
|
|
121
118
|
## No robot file? Try an example
|
|
122
119
|
|
|
123
|
-
servo-bench is built to fail: a 5 V rail overloaded on purpose, so you can see what a catch looks like.
|
|
120
|
+
servo-bench is built to fail: a 5 V rail overloaded and a wrist servo too weak, on purpose, so you can see what a catch looks like.
|
|
124
121
|
|
|
125
122
|
```console
|
|
126
123
|
$ uvx lockwire start --example servo-bench
|
|
127
|
-
wrote lockwire.yaml — example servo-bench (built to fail: a 5 V rail overloaded on purpose, so you can see what a catch looks like). Next: uvx lockwire check lockwire.yaml
|
|
124
|
+
wrote lockwire.yaml — example servo-bench (built to fail: a 5 V rail overloaded and a wrist servo too weak, on purpose, so you can see what a catch looks like). Next: uvx lockwire check lockwire.yaml
|
|
128
125
|
$ uvx lockwire check
|
|
126
|
+
VIOLATION model/joints/wrist/limits/effort — observed 0.40 N*m joint effort limit, expected <= 0.226 N*m, the feetech.scs0009
|
|
127
|
+
stall torque (Δ 1.8x the stall torque)
|
|
128
|
+
...
|
|
129
|
+
action: ... or find a stronger servo: lockwire swap lockwire.yaml wrist
|
|
129
130
|
VIOLATION budgets/bud.power.servo-5v — observed 32.10 W, expected <= 15.00 W (Δ +17.10 W (+114%))
|
|
130
131
|
...
|
|
131
|
-
NO-GO —
|
|
132
|
+
NO-GO — 2 violation(s), 0 warning(s)
|
|
132
133
|
```
|
|
133
134
|
|
|
134
135
|
The five robots (`--example drone`, `rover`, `arm`, `quadruped`, `humanoid`) are clean
|
|
@@ -141,8 +142,9 @@ starting points; try your own robot for the catch.
|
|
|
141
142
|
- **CI:** the same check on every push, with pull-request annotations and an HTML report.
|
|
142
143
|
- **Agents:** your AI coding agent runs the same check before it changes the robot.
|
|
143
144
|
|
|
144
|
-
Everything else (datasheet comparisons, power, torque and bus budgets,
|
|
145
|
-
|
|
145
|
+
Everything else (datasheet comparisons, power, torque and bus budgets, part swap, the servo
|
|
146
|
+
recorder, drift on a single robot, the Python library): [the guides](docs/guides/index.md). The powered-on
|
|
147
|
+
preflight gate, ROS 2 bags and the drift ledger across units are Lockwire Pro, waitlist only: https://lockwirerobotics.com.
|
|
146
148
|
|
|
147
149
|
## Download the app
|
|
148
150
|
|
|
@@ -77,15 +77,19 @@ Cursor, Claude Desktop and other agents: [docs/guides/agents.md](docs/guides/age
|
|
|
77
77
|
|
|
78
78
|
## No robot file? Try an example
|
|
79
79
|
|
|
80
|
-
servo-bench is built to fail: a 5 V rail overloaded on purpose, so you can see what a catch looks like.
|
|
80
|
+
servo-bench is built to fail: a 5 V rail overloaded and a wrist servo too weak, on purpose, so you can see what a catch looks like.
|
|
81
81
|
|
|
82
82
|
```console
|
|
83
83
|
$ uvx lockwire start --example servo-bench
|
|
84
|
-
wrote lockwire.yaml — example servo-bench (built to fail: a 5 V rail overloaded on purpose, so you can see what a catch looks like). Next: uvx lockwire check lockwire.yaml
|
|
84
|
+
wrote lockwire.yaml — example servo-bench (built to fail: a 5 V rail overloaded and a wrist servo too weak, on purpose, so you can see what a catch looks like). Next: uvx lockwire check lockwire.yaml
|
|
85
85
|
$ uvx lockwire check
|
|
86
|
+
VIOLATION model/joints/wrist/limits/effort — observed 0.40 N*m joint effort limit, expected <= 0.226 N*m, the feetech.scs0009
|
|
87
|
+
stall torque (Δ 1.8x the stall torque)
|
|
88
|
+
...
|
|
89
|
+
action: ... or find a stronger servo: lockwire swap lockwire.yaml wrist
|
|
86
90
|
VIOLATION budgets/bud.power.servo-5v — observed 32.10 W, expected <= 15.00 W (Δ +17.10 W (+114%))
|
|
87
91
|
...
|
|
88
|
-
NO-GO —
|
|
92
|
+
NO-GO — 2 violation(s), 0 warning(s)
|
|
89
93
|
```
|
|
90
94
|
|
|
91
95
|
The five robots (`--example drone`, `rover`, `arm`, `quadruped`, `humanoid`) are clean
|
|
@@ -98,8 +102,9 @@ starting points; try your own robot for the catch.
|
|
|
98
102
|
- **CI:** the same check on every push, with pull-request annotations and an HTML report.
|
|
99
103
|
- **Agents:** your AI coding agent runs the same check before it changes the robot.
|
|
100
104
|
|
|
101
|
-
Everything else (datasheet comparisons, power, torque and bus budgets,
|
|
102
|
-
|
|
105
|
+
Everything else (datasheet comparisons, power, torque and bus budgets, part swap, the servo
|
|
106
|
+
recorder, drift on a single robot, the Python library): [the guides](docs/guides/index.md). The powered-on
|
|
107
|
+
preflight gate, ROS 2 bags and the drift ledger across units are Lockwire Pro, waitlist only: https://lockwirerobotics.com.
|
|
103
108
|
|
|
104
109
|
## Download the app
|
|
105
110
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "lockwire"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.7"
|
|
4
4
|
description = "The physical-assumption contract for robots: checks that a robot's declared parts (power, weight, bus, torque) add up"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -23,40 +23,26 @@ classifiers = [
|
|
|
23
23
|
]
|
|
24
24
|
dependencies = [
|
|
25
25
|
"numpy>=2.5.1",
|
|
26
|
-
"pydantic>=2.13.4",
|
|
26
|
+
"pydantic>=2.13.4,<3",
|
|
27
27
|
"rich>=15.0.0",
|
|
28
|
-
"ruamel-yaml>=0.19.1",
|
|
29
|
-
|
|
28
|
+
"ruamel-yaml>=0.19.1,<0.20", # 0.x: a minor bump may break the round-trip API
|
|
29
|
+
# typer 0.29 breaks click Argument handling (AttributeError: TyperArgument has no attribute type); lift the cap once the code is fixed
|
|
30
|
+
"typer>=0.26.8,<0.29",
|
|
30
31
|
"xacro>=2.1.1",
|
|
31
32
|
]
|
|
32
33
|
|
|
33
34
|
[project.optional-dependencies]
|
|
34
|
-
# Reading
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
#
|
|
38
|
-
# The load-bearing property is that these need **no ROS installation**:
|
|
39
|
-
# `mcap-ros2-support` depends only on `mcap`, which depends only on lz4 and
|
|
40
|
-
# zstandard. So `preflight --from run.mcap` works in a bare venv on macOS, which
|
|
41
|
-
# is what lets someone try lockwire against a bag they already have without
|
|
42
|
-
# installing ROS first.
|
|
43
|
-
ros2bag = [
|
|
44
|
-
"mcap>=1.4.0",
|
|
45
|
-
"mcap-ros2-support>=0.5.7",
|
|
35
|
+
# Reading a Feetech STS/SCS servo bus (`lockwire record-servos`); read-only.
|
|
36
|
+
bus = [
|
|
37
|
+
"pyserial>=3.5",
|
|
46
38
|
]
|
|
47
|
-
#
|
|
48
|
-
# check/CLI path does not import it; field command mapping remains separate.
|
|
49
|
-
mavlink = [
|
|
50
|
-
"pymavlink==2.4.50",
|
|
51
|
-
]
|
|
52
|
-
# Serving lockwire over MCP to an agent. Optional for the same reason as `ros2bag`:
|
|
53
|
-
# a plain install must stay lean, and the SDK is only needed by `lockwire mcp`.
|
|
39
|
+
# Serving lockwire over MCP to an agent. Optional: a plain install must stay lean, and the SDK is only needed by `lockwire mcp`.
|
|
54
40
|
mcp = [
|
|
55
|
-
"mcp>=2.2.0",
|
|
41
|
+
"mcp>=2.2.0,<3",
|
|
56
42
|
"pyjwt>=2.15", # direct floor: a fresh lock must not resolve below the fixed release
|
|
57
43
|
]
|
|
58
44
|
# The Electron app's sidecar: `lockwire serve` over local HTTP. Optional for the
|
|
59
|
-
# same reason as `
|
|
45
|
+
# same reason as `mcp` — a plain CLI install stays lean; only the
|
|
60
46
|
# packaged app build and anyone running the sidecar by hand need these. Versions are
|
|
61
47
|
# today's PyPI current stable (measured, E1-a).
|
|
62
48
|
serve = [
|
|
@@ -81,31 +67,21 @@ Issues = "https://github.com/Shivansh2703/lockwire/issues"
|
|
|
81
67
|
[project.scripts]
|
|
82
68
|
lockwire = "lockwire:main"
|
|
83
69
|
|
|
84
|
-
[project.entry-points."lockwire.plugins"]
|
|
85
|
-
pro = "lockwire_pro.plugin:register"
|
|
86
|
-
|
|
87
70
|
[build-system]
|
|
88
71
|
requires = ["uv_build>=0.11.26,<0.12.0"]
|
|
89
72
|
build-backend = "uv_build"
|
|
90
73
|
|
|
91
|
-
# One distribution, two importable packages: the core `lockwire` and `lockwire_pro`, the
|
|
92
74
|
# plugin with the recording commands (preflight, baseline, health...), loaded via its entry point.
|
|
93
75
|
[tool.uv.build-backend]
|
|
94
|
-
module-name =
|
|
76
|
+
module-name = "lockwire"
|
|
95
77
|
|
|
96
78
|
[dependency-groups]
|
|
97
79
|
dev = [
|
|
98
|
-
"mcp>=2.2.0",
|
|
99
|
-
#
|
|
100
|
-
|
|
101
|
-
# without it here those tests silently never ran. Dev-only: the runtime
|
|
102
|
-
# `ros2bag` extra above stays optional so a plain install stays lean.
|
|
103
|
-
"mcap>=1.4.0",
|
|
104
|
-
"mcap-ros2-support>=0.5.7",
|
|
105
|
-
# Tests must exercise CRC/dialect admission instead of silently skipping it.
|
|
106
|
-
"pymavlink==2.4.50",
|
|
80
|
+
"mcp>=2.2.0,<3",
|
|
81
|
+
# The packaging gate claims `serial` (bus extra); dev env must import it.
|
|
82
|
+
"pyserial>=3.5",
|
|
107
83
|
# tests/test_serve.py needs the sidecar (`lockwire serve`) importable and
|
|
108
|
-
# runnable as a subprocess. Same reasoning as `mcp
|
|
84
|
+
# runnable as a subprocess. Same reasoning as `mcp` above: CI's
|
|
109
85
|
# `test` job runs a plain `uv sync --dev`, so without these here that
|
|
110
86
|
# whole test file would silently never run. Dev-only: the runtime `serve`
|
|
111
87
|
# extra above stays optional so a plain install stays lean.
|
|
@@ -140,19 +116,8 @@ line-length = 100
|
|
|
140
116
|
"scripts/measure_stacked_gate.py" = ["E402"]
|
|
141
117
|
|
|
142
118
|
[tool.pytest.ini_options]
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
# suite on any machine. Those two modules hold the fail-closed decision and the
|
|
146
|
-
# severity mapping — the parts with judgement in them — and leaving them
|
|
147
|
-
# testable only inside a container would mean they were usually untested.
|
|
148
|
-
pythonpath = [".", "ros/lockwire_ros"]
|
|
149
|
-
# The ROS package's tests live in the ROS package, not in `tests/`, and the
|
|
150
|
-
# reason is load-bearing rather than tidiness: they must also run inside a
|
|
151
|
-
# Humble container where `lockwire` is deliberately NOT installed, and
|
|
152
|
-
# `tests/conftest.py` imports it at collection time. Kept on testpaths so the
|
|
153
|
-
# ordinary suite still covers them here. Cases needing rclpy `importorskip` it,
|
|
154
|
-
# so they skip off-robot instead of erroring.
|
|
155
|
-
testpaths = ["tests", "ros/lockwire_ros/test"]
|
|
119
|
+
pythonpath = ["."]
|
|
120
|
+
testpaths = ["tests"]
|
|
156
121
|
# chrome: drives real headless Chrome (subprocess spawn). scripts/pytest_slot.sh
|
|
157
122
|
# excludes this marker from every non-exclusive (targeted) run so workers' test
|
|
158
123
|
# runs never spawn Chrome processes; the cadence Check (--exclusive) still runs
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Lockwire — the physical-assumption contract for robots, enforced in CI and at preflight."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.2.7"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def main() -> None:
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from lockwire.catalog import PrivatePartsError
|
|
10
|
+
from lockwire.cli import app
|
|
11
|
+
from lockwire.schema import ContractError
|
|
12
|
+
|
|
13
|
+
for stream in (sys.stdout, sys.stderr): # a cp1252 Windows console cannot print Δ, →, ✓
|
|
14
|
+
if hasattr(stream, "reconfigure"):
|
|
15
|
+
stream.reconfigure(errors="replace")
|
|
16
|
+
try:
|
|
17
|
+
app()
|
|
18
|
+
except PrivatePartsError as error: # one line, not a traceback
|
|
19
|
+
from rich.console import Console
|
|
20
|
+
from rich.markup import escape
|
|
21
|
+
|
|
22
|
+
Console(stderr=True).print(f"[red]private parts file broken:[/] {escape(str(error))}")
|
|
23
|
+
sys.exit(2)
|
|
24
|
+
except ContractError as error: # the user's lockfile, not a bug: plain lines, no traceback
|
|
25
|
+
from rich.console import Console
|
|
26
|
+
from rich.markup import escape
|
|
27
|
+
|
|
28
|
+
Console(stderr=True).print(escape(str(error)), soft_wrap=True, highlight=False)
|
|
29
|
+
sys.exit(2)
|
|
30
|
+
except OSError as error: # a file-system problem, not a lockwire bug: one plain line
|
|
31
|
+
from rich.console import Console
|
|
32
|
+
from rich.markup import escape
|
|
33
|
+
|
|
34
|
+
from lockwire.cli import plain_os_error
|
|
35
|
+
|
|
36
|
+
Console(stderr=True).print(escape(plain_os_error(error)), soft_wrap=True, highlight=False)
|
|
37
|
+
sys.exit(2)
|
|
38
|
+
except Exception as error: # a crash is a bug, never a verdict: REFUSED (2), not NO-GO (1)
|
|
39
|
+
from rich.console import Console
|
|
40
|
+
from rich.markup import escape
|
|
41
|
+
|
|
42
|
+
Console(stderr=True).print(
|
|
43
|
+
f"[red]lockwire stopped: {type(error).__name__}: {escape(str(error))} "
|
|
44
|
+
"— this is a bug in lockwire, not a verdict[/]"
|
|
45
|
+
)
|
|
46
|
+
sys.exit(2)
|
|
@@ -28,7 +28,7 @@ def rules() -> str:
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
PRE_COMMIT = r""" - repo: https://github.com/Shivansh2703/lockwire
|
|
31
|
-
rev: v0.2.
|
|
31
|
+
rev: v0.2.7
|
|
32
32
|
hooks:
|
|
33
33
|
- id: lockwire-check
|
|
34
34
|
files: (?i)(\.(urdf|xacro|sdf)|(^|/)lockwire\.ya?ml)$
|
|
@@ -45,15 +45,27 @@ jobs:
|
|
|
45
45
|
contract: lockwire.yaml
|
|
46
46
|
"""
|
|
47
47
|
# $0 is the interpreter. Same gate as plugin/hooks/hook-check.sh: model files only, any case.
|
|
48
|
-
|
|
48
|
+
_GATE = (
|
|
49
49
|
'p=$(cat); case $(printf %s "$p" | tr "[:upper:]" "[:lower:]") in'
|
|
50
50
|
' *.urdf\\"* | *.sdf\\"* | *.xacro\\"* | *lockwire.yaml\\"*) ;; *) exit 0 ;; esac;'
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
' printf %s "$p" | "$0" -m lockwire hook-check && exit 0;'
|
|
51
|
+
)
|
|
52
|
+
_CRASH = (
|
|
54
53
|
' [ $? = 2 ] || echo "lockwire hook-check crashed (see above); re-run lockwire agent-setup'
|
|
55
54
|
' --claude" >&2; exit 2'
|
|
56
55
|
)
|
|
56
|
+
GUARD = (
|
|
57
|
+
_GATE
|
|
58
|
+
+ ' [ -x "$0" ] || { echo "lockwire: hook interpreter is gone; re-run lockwire agent-setup'
|
|
59
|
+
' --claude" >&2; exit 2; };'
|
|
60
|
+
' printf %s "$p" | "$0" -m lockwire hook-check && exit 0;' + _CRASH
|
|
61
|
+
)
|
|
62
|
+
# An interpreter inside uv's cache (uvx) is gone after a cache clean or on a teammate's machine,
|
|
63
|
+
# so name the command instead: `lockwire` on PATH, else `uvx lockwire`.
|
|
64
|
+
GUARD_PORTABLE = (
|
|
65
|
+
_GATE + ' if command -v lockwire >/dev/null; then printf %s "$p" | lockwire hook-check;'
|
|
66
|
+
' elif command -v uvx >/dev/null; then printf %s "$p" | uvx lockwire hook-check;'
|
|
67
|
+
' else echo "lockwire: neither lockwire nor uvx is on PATH" >&2; exit 2; fi && exit 0;' + _CRASH
|
|
68
|
+
)
|
|
57
69
|
|
|
58
70
|
|
|
59
71
|
def agent_setup(root: Path, *, ci_only: bool = False) -> list[str]:
|
|
@@ -63,12 +75,14 @@ def agent_setup(root: Path, *, ci_only: bool = False) -> list[str]:
|
|
|
63
75
|
def put(name: str, text: str, *, append: bool = False, head: str = "") -> None:
|
|
64
76
|
# ponytail: fixed names under root, so no `confine` (it refuses .yaml targets by design).
|
|
65
77
|
path = root / name
|
|
66
|
-
old = path.read_text() if path.exists() else None
|
|
78
|
+
old = path.read_text(encoding="utf-8") if path.exists() else None
|
|
67
79
|
if old is not None and (not append or text.split("\n")[0] in old):
|
|
68
80
|
lines.append(f"kept {name}")
|
|
69
81
|
return
|
|
70
82
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
71
|
-
path.write_text(
|
|
83
|
+
path.write_text(
|
|
84
|
+
head + text if old is None else old.rstrip("\n") + "\n\n" + text, encoding="utf-8"
|
|
85
|
+
)
|
|
72
86
|
lines.append(f"wrote {name}")
|
|
73
87
|
|
|
74
88
|
for name in () if ci_only else ("CLAUDE.md", "AGENTS.md"):
|
|
@@ -87,9 +101,15 @@ def claude_hook(root: Path) -> str:
|
|
|
87
101
|
install there exits 1, and Claude Code lets an edit through on any exit but 2. GUARD passes
|
|
88
102
|
other files untouched and turns a gone interpreter (a cleaned uvx cache) or a crash into 2.
|
|
89
103
|
"""
|
|
90
|
-
|
|
104
|
+
uvx = any(
|
|
105
|
+
p.startswith(("archive-v", "environments-v", "builds-v"))
|
|
106
|
+
for p in Path(sys.executable).parts
|
|
107
|
+
)
|
|
108
|
+
command = (
|
|
109
|
+
cli_line("sh", "-c", GUARD_PORTABLE) if uvx else cli_line("sh", "-c", GUARD, sys.executable)
|
|
110
|
+
)
|
|
91
111
|
path = root / ".claude" / "settings.json"
|
|
92
|
-
settings = json.loads(path.read_text()) if path.exists() else {}
|
|
112
|
+
settings = json.loads(path.read_text(encoding="utf-8")) if path.exists() else {}
|
|
93
113
|
groups = settings.setdefault("hooks", {}).setdefault("PreToolUse", [])
|
|
94
114
|
ours = [
|
|
95
115
|
h
|
|
@@ -106,7 +126,7 @@ def claude_hook(root: Path) -> str:
|
|
|
106
126
|
{"matcher": "Edit|Write|MultiEdit", "hooks": [{"type": "command", "command": command}]}
|
|
107
127
|
)
|
|
108
128
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
109
|
-
path.write_text(json.dumps(settings, indent=2) + "\n")
|
|
129
|
+
path.write_text(json.dumps(settings, indent=2) + "\n", encoding="utf-8")
|
|
110
130
|
return (
|
|
111
131
|
f"wrote .claude/settings.json (edit hook: {command}; to remove it, delete the "
|
|
112
132
|
"PreToolUse entry whose command contains `lockwire hook-check`)"
|
|
@@ -76,6 +76,7 @@ from lockwire.report_json import (
|
|
|
76
76
|
from lockwire.schema import (
|
|
77
77
|
ArtifactRef,
|
|
78
78
|
Contract,
|
|
79
|
+
RobotInfo,
|
|
79
80
|
UnsupportedSchemaVersion,
|
|
80
81
|
load_contract,
|
|
81
82
|
load_contract_bytes,
|
|
@@ -563,6 +564,16 @@ def _actuator_check_context(
|
|
|
563
564
|
return actuator_evidence, Path(evidence_root), revision
|
|
564
565
|
|
|
565
566
|
|
|
567
|
+
def defect_document(model_file: Path, error: Exception) -> dict[str, Any]:
|
|
568
|
+
"""The check document for a model file with a dup/missing link or joint: NO-GO."""
|
|
569
|
+
from lockwire.start_operation import defect_report # noqa: PLC0415
|
|
570
|
+
from lockwire.urdf import robot_name # noqa: PLC0415
|
|
571
|
+
|
|
572
|
+
return check_document(
|
|
573
|
+
Contract(robot=RobotInfo(name=robot_name(model_file))), defect_report(error)
|
|
574
|
+
)
|
|
575
|
+
|
|
576
|
+
|
|
566
577
|
def check(
|
|
567
578
|
contract: Path | str | Contract,
|
|
568
579
|
*,
|
|
@@ -574,6 +585,7 @@ def check(
|
|
|
574
585
|
model: str | None = None,
|
|
575
586
|
model_file: Path | None = None,
|
|
576
587
|
mass: str | None = None,
|
|
588
|
+
warnings: Iterable[str] = (),
|
|
577
589
|
) -> dict[str, Any]:
|
|
578
590
|
"""Record-level checks: the document ``lockwire check --json`` writes.
|
|
579
591
|
|
|
@@ -609,10 +621,17 @@ def check(
|
|
|
609
621
|
|
|
610
622
|
rerun_command(findings, rerun)
|
|
611
623
|
if model_file is not None and path is not None:
|
|
612
|
-
from lockwire.start_operation import
|
|
624
|
+
from lockwire.start_operation import ( # noqa: PLC0415
|
|
625
|
+
drop_same_figure,
|
|
626
|
+
typed_paths,
|
|
627
|
+
warning_findings,
|
|
628
|
+
zero_if_nothing_compared,
|
|
629
|
+
)
|
|
613
630
|
|
|
631
|
+
findings += warning_findings(list(warnings))
|
|
614
632
|
typed_paths(findings, path, model_file)
|
|
615
633
|
drop_same_figure(findings, mass)
|
|
634
|
+
zero_if_nothing_compared(findings)
|
|
616
635
|
return check_document(
|
|
617
636
|
loaded,
|
|
618
637
|
findings,
|
|
@@ -1175,9 +1194,9 @@ def upgrade(
|
|
|
1175
1194
|
if hashlib.sha256(raw).hexdigest() != expected_revision:
|
|
1176
1195
|
raise ValueError("legacy contract changed since its revision was selected")
|
|
1177
1196
|
upgraded = upgrade_contract_text(raw.decode("utf-8")).encode("utf-8")
|
|
1178
|
-
legacy = load_contract_bytes(raw)
|
|
1179
|
-
if legacy.schema_version not in {"0.2", "0.3", "0.4"}:
|
|
1180
|
-
raise ValueError("upgrade requires an explicit legacy schema_version 0.2, 0.3 or 0.
|
|
1197
|
+
legacy = load_contract_bytes(raw, upgrading=True, name=contract_path.name)
|
|
1198
|
+
if legacy.schema_version not in {"0.2", "0.3", "0.4", "0.5"}:
|
|
1199
|
+
raise ValueError("upgrade requires an explicit legacy schema_version 0.2, 0.3, 0.4 or 0.5")
|
|
1181
1200
|
load_contract_bytes(upgraded)
|
|
1182
1201
|
if contract_path.read_bytes() != raw:
|
|
1183
1202
|
raise ValueError("legacy contract changed during upgrade")
|
|
@@ -242,6 +242,15 @@ NUMBER_KINDS: dict[str, dict[str, str]] = {
|
|
|
242
242
|
"Counts.not_scored": _build_kind_declaration("derived", "report.verdict"),
|
|
243
243
|
"MeshGap.missing": _build_kind_declaration("derived", "start_operation._find_meshes"),
|
|
244
244
|
"MeshGap.total": _build_kind_declaration("derived", "start_operation._find_meshes"),
|
|
245
|
+
# --- Part Swap (the app's swap-preview): catalog servo figures, gravity loads and ratios
|
|
246
|
+
"SwapCandidate.stall_nm": _build_kind_declaration("catalog", "swap.preview", mark="catalog"),
|
|
247
|
+
"SwapCandidate.mass_g": _build_kind_declaration("catalog", "swap.preview", mark="catalog"),
|
|
248
|
+
"SwapCandidate.ratio": _build_kind_declaration("derived", "swap.status"),
|
|
249
|
+
"SwapKnockOn.before_nm": _build_kind_declaration("derived", "checks.gravity_loads"),
|
|
250
|
+
"SwapKnockOn.after_nm": _build_kind_declaration("derived", "checks.gravity_loads"),
|
|
251
|
+
"SwapKnockOn.ratio": _build_kind_declaration("derived", "swap.status"),
|
|
252
|
+
"SwapPreviewPayload.load_nm": _build_kind_declaration("derived", "checks.gravity_loads"),
|
|
253
|
+
"SwapPreviewPayload.delta_g": _build_kind_declaration("derived", "swap.preview"),
|
|
245
254
|
# --- the Add part picker: a catalog number; its own `kind` field says datasheet or assumed
|
|
246
255
|
"AddPartNumber.value": _build_kind_declaration(
|
|
247
256
|
"catalog", "catalog.SourcedNumber", mark="catalog"
|
|
@@ -870,6 +879,48 @@ class StartersPayload(_Strict):
|
|
|
870
879
|
starters: list[Starter]
|
|
871
880
|
|
|
872
881
|
|
|
882
|
+
SwapStatus = Literal["fit", "tight", "too weak"]
|
|
883
|
+
|
|
884
|
+
|
|
885
|
+
class SwapCandidate(_Strict):
|
|
886
|
+
"""One catalog servo ranked for a joint; ``ratio`` is stall/load, capped at 100."""
|
|
887
|
+
|
|
888
|
+
id: str
|
|
889
|
+
name: str
|
|
890
|
+
label: Literal["cited", "unverified"]
|
|
891
|
+
status: SwapStatus
|
|
892
|
+
stall_nm: float
|
|
893
|
+
ratio: float
|
|
894
|
+
mass_g: float
|
|
895
|
+
flags: list[str]
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
class SwapKnockOn(_Strict):
|
|
899
|
+
"""One joint above the swapped one: load before -> after; no status when its servo
|
|
900
|
+
has no stall torque, no loads when the gravity walk did not score it."""
|
|
901
|
+
|
|
902
|
+
joint: str
|
|
903
|
+
before_nm: float | None
|
|
904
|
+
after_nm: float | None
|
|
905
|
+
status: SwapStatus | None
|
|
906
|
+
was: SwapStatus | None
|
|
907
|
+
ratio: float | None
|
|
908
|
+
dropped: bool
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
class SwapPreviewPayload(_Strict):
|
|
912
|
+
"""The sidecar's ``swap-preview``: ``swap.preview`` for one joint, the knock-on for ``chosen``."""
|
|
913
|
+
|
|
914
|
+
joint: str
|
|
915
|
+
current: str | None
|
|
916
|
+
load_nm: float
|
|
917
|
+
chosen: str | None
|
|
918
|
+
delta_g: float
|
|
919
|
+
candidates: list[SwapCandidate]
|
|
920
|
+
knock_on: list[SwapKnockOn]
|
|
921
|
+
notes: list[str]
|
|
922
|
+
|
|
923
|
+
|
|
873
924
|
class AcceptedRow(_Strict):
|
|
874
925
|
"""A finding the lockfile accepted on record: the Check panel's muted Accepted rows."""
|
|
875
926
|
|
|
@@ -1012,6 +1063,7 @@ ALL_MEMBERS: tuple[type[BaseModel], ...] = (
|
|
|
1012
1063
|
DeclareFormPayload,
|
|
1013
1064
|
StartPayload,
|
|
1014
1065
|
StartersPayload,
|
|
1066
|
+
SwapPreviewPayload,
|
|
1015
1067
|
)
|
|
1016
1068
|
|
|
1017
1069
|
|
|
@@ -18,12 +18,23 @@ number is a bug in the seed data, not a permitted state (see `_source_not_blank`
|
|
|
18
18
|
from __future__ import annotations
|
|
19
19
|
|
|
20
20
|
import datetime as dt
|
|
21
|
+
import re
|
|
21
22
|
from collections.abc import Iterable
|
|
22
23
|
from pathlib import Path
|
|
23
24
|
from typing import Literal
|
|
24
25
|
|
|
25
|
-
from pydantic import
|
|
26
|
+
from pydantic import (
|
|
27
|
+
BaseModel,
|
|
28
|
+
ConfigDict,
|
|
29
|
+
Field,
|
|
30
|
+
ValidationError,
|
|
31
|
+
field_validator,
|
|
32
|
+
model_validator,
|
|
33
|
+
)
|
|
26
34
|
from ruamel.yaml import YAML
|
|
35
|
+
from ruamel.yaml.error import YAMLError
|
|
36
|
+
|
|
37
|
+
from lockwire import units
|
|
27
38
|
|
|
28
39
|
_SEED_PATH = Path(__file__).parent / "catalog_seed.yaml"
|
|
29
40
|
_ROBOTS_PATH = Path(__file__).parent / "catalog_robots.yaml"
|
|
@@ -35,6 +46,15 @@ _ROBOTS_PATH = Path(__file__).parent / "catalog_robots.yaml"
|
|
|
35
46
|
NumberKind = Literal["datasheet", "source_file", "assumed"]
|
|
36
47
|
|
|
37
48
|
|
|
49
|
+
def is_cited(kind: str, source: str) -> bool:
|
|
50
|
+
"""The cited rule: a datasheet figure whose source names a URL that is not a retail listing."""
|
|
51
|
+
return (
|
|
52
|
+
kind == "datasheet"
|
|
53
|
+
and bool(re.search(r"https?://", source))
|
|
54
|
+
and "retail" not in source.lower()
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
38
58
|
class SourcedNumber(BaseModel):
|
|
39
59
|
"""One number on a catalog part, badged with where it came from."""
|
|
40
60
|
|
|
@@ -75,9 +95,17 @@ class CatalogPart(BaseModel):
|
|
|
75
95
|
id: str
|
|
76
96
|
family: str
|
|
77
97
|
name: str
|
|
98
|
+
bus: str | None = None # servo bus word, e.g. feetech-sts, dynamixel-p2
|
|
78
99
|
numbers: dict[str, SourcedNumber] = Field(default_factory=dict)
|
|
79
100
|
note: str | None = None
|
|
80
101
|
|
|
102
|
+
@property
|
|
103
|
+
def label(self) -> Literal["cited", "unverified"]:
|
|
104
|
+
"""Derived, never stored: cited = every number is a datasheet figure with a URL source
|
|
105
|
+
that is not a retail listing; anything else is unverified."""
|
|
106
|
+
ok = all(is_cited(n.kind, n.source) for n in self.numbers.values())
|
|
107
|
+
return "cited" if ok and self.numbers else "unverified"
|
|
108
|
+
|
|
81
109
|
|
|
82
110
|
class Catalog(BaseModel):
|
|
83
111
|
model_config = ConfigDict(extra="forbid")
|
|
@@ -95,11 +123,86 @@ class Catalog(BaseModel):
|
|
|
95
123
|
return v
|
|
96
124
|
|
|
97
125
|
|
|
126
|
+
# Units Part Swap and the servo check read without converting: a part must state them so.
|
|
127
|
+
_FIXED_UNITS = {
|
|
128
|
+
"stall_torque": "N*m",
|
|
129
|
+
"stall_torque_voltage": "V",
|
|
130
|
+
"input_voltage_min": "V",
|
|
131
|
+
"input_voltage_max": "V",
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class PrivatePartsError(ValueError):
|
|
136
|
+
"""A parts file is broken; the message starts with its path."""
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _refuse_bad_units(file: Path, part: dict) -> None:
|
|
140
|
+
numbers = part.get("numbers")
|
|
141
|
+
if not isinstance(numbers, dict):
|
|
142
|
+
return
|
|
143
|
+
for key, unit in _FIXED_UNITS.items(): # read as-is by Part Swap and the servo check
|
|
144
|
+
got = numbers.get(key)
|
|
145
|
+
if isinstance(got, dict) and got.get("unit") != unit:
|
|
146
|
+
raise PrivatePartsError(
|
|
147
|
+
f"{file}: part {part.get('id')!r} numbers.{key}.unit is "
|
|
148
|
+
f"{got.get('unit')!r}; write it in {unit}"
|
|
149
|
+
+ (" (1 kg*cm = 0.0980665 N*m)" if unit == "N*m" else "")
|
|
150
|
+
)
|
|
151
|
+
mass = numbers.get("mass") # Part Swap converts mass to kg
|
|
152
|
+
if isinstance(mass, dict) and not (
|
|
153
|
+
units.known(str(mass.get("unit"))) and units.dimension(mass["unit"]) == "mass"
|
|
154
|
+
):
|
|
155
|
+
raise PrivatePartsError(
|
|
156
|
+
f"{file}: part {part.get('id')!r} numbers.mass.unit is {mass.get('unit')!r}; "
|
|
157
|
+
"write it in kg or g"
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
98
161
|
def load_catalog(path: Path | str | None = None) -> Catalog:
|
|
99
|
-
"""Read the catalog from `path` (default: the seeded catalog shipped with lockwire).
|
|
162
|
+
"""Read the catalog from `path` (default: the seeded catalog shipped with lockwire).
|
|
163
|
+
|
|
164
|
+
The default also merges the user's private parts from ~/.lockwire/parts.yaml when present;
|
|
165
|
+
an explicit `path` reads only that file.
|
|
166
|
+
"""
|
|
100
167
|
yaml = YAML(typ="safe")
|
|
101
168
|
p = Path(path) if path is not None else _SEED_PATH
|
|
102
|
-
|
|
169
|
+
try:
|
|
170
|
+
data = yaml.load(p.read_text(encoding="utf-8"))
|
|
171
|
+
except (YAMLError, UnicodeDecodeError):
|
|
172
|
+
data = None
|
|
173
|
+
if not isinstance(data, dict):
|
|
174
|
+
raise PrivatePartsError(
|
|
175
|
+
f"{path or p} is not a parts catalog; pass a catalog .yaml, or leave it off for the bundled one"
|
|
176
|
+
)
|
|
177
|
+
for part in data.get("parts", []):
|
|
178
|
+
if isinstance(part, dict):
|
|
179
|
+
_refuse_bad_units(p, part)
|
|
180
|
+
private = Path.home() / ".lockwire" / "parts.yaml"
|
|
181
|
+
if path is None and private.is_file():
|
|
182
|
+
try:
|
|
183
|
+
mine = yaml.load(private.read_text(encoding="utf-8"))
|
|
184
|
+
except (OSError, YAMLError) as error:
|
|
185
|
+
raise PrivatePartsError(
|
|
186
|
+
f"{private}: not valid YAML: {str(error).splitlines()[0]}"
|
|
187
|
+
) from error
|
|
188
|
+
if not isinstance(mine, list):
|
|
189
|
+
raise PrivatePartsError(f"{private}: must be a list of parts")
|
|
190
|
+
public_ids = {part["id"] for part in data["parts"]}
|
|
191
|
+
for n, part in enumerate(mine, 1):
|
|
192
|
+
if not isinstance(part, dict) or "id" not in part:
|
|
193
|
+
raise PrivatePartsError(f"{private}: entry {n} has no id")
|
|
194
|
+
if part["id"] in public_ids:
|
|
195
|
+
raise PrivatePartsError(f"{private}: part {part['id']!r} reuses a public id")
|
|
196
|
+
_refuse_bad_units(private, part)
|
|
197
|
+
try:
|
|
198
|
+
return Catalog.model_validate({**data, "parts": [*data["parts"], *mine]})
|
|
199
|
+
except ValidationError as error:
|
|
200
|
+
first = error.errors()[0]
|
|
201
|
+
loc, where = first["loc"][1:], "" # ("parts", index, field, ...)
|
|
202
|
+
if loc and isinstance(loc[0], int):
|
|
203
|
+
part_id = mine[loc[0] - len(data["parts"])]["id"]
|
|
204
|
+
where = f"part {part_id!r} {'.'.join(map(str, loc[1:])) or 'entry'}: "
|
|
205
|
+
raise PrivatePartsError(f"{private}: {where}{first['msg']}") from error
|
|
103
206
|
return Catalog.model_validate(data)
|
|
104
207
|
|
|
105
208
|
|
|
@@ -156,7 +259,7 @@ class Robot(BaseModel):
|
|
|
156
259
|
|
|
157
260
|
def load_robots(path: Path | str | None = None) -> list[Robot]:
|
|
158
261
|
"""The robot rows (default: the ones shipped with lockwire)."""
|
|
159
|
-
data = YAML(typ="safe").load(Path(path or _ROBOTS_PATH).read_text())
|
|
262
|
+
data = YAML(typ="safe").load(Path(path or _ROBOTS_PATH).read_text(encoding="utf-8"))
|
|
160
263
|
robots = [Robot.model_validate(row) for row in data["robots"]]
|
|
161
264
|
if len({r.id for r in robots}) != len(robots):
|
|
162
265
|
raise ValueError("duplicate robot id in the catalog")
|