boardwright 0.8.2__tar.gz → 0.8.4__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 (164) hide show
  1. {boardwright-0.8.2 → boardwright-0.8.4}/CHANGELOG.md +37 -1
  2. {boardwright-0.8.2 → boardwright-0.8.4}/PKG-INFO +1 -1
  3. {boardwright-0.8.2 → boardwright-0.8.4}/pyproject.toml +1 -1
  4. boardwright-0.8.4/src/boardwright/__init__.py +1 -0
  5. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/copper.py +13 -0
  6. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/dsn.py +28 -4
  7. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/existing.py +32 -11
  8. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/sch.py +40 -3
  9. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/update.py +35 -1
  10. boardwright-0.8.4/tests/test_reroute_safety.py +76 -0
  11. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_sch_add.py +86 -0
  12. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_update.py +62 -0
  13. boardwright-0.8.2/src/boardwright/__init__.py +0 -1
  14. {boardwright-0.8.2 → boardwright-0.8.4}/.gitignore +0 -0
  15. {boardwright-0.8.2 → boardwright-0.8.4}/LICENSE +0 -0
  16. {boardwright-0.8.2 → boardwright-0.8.4}/README.md +0 -0
  17. {boardwright-0.8.2 → boardwright-0.8.4}/docs/devlog/README.md +0 -0
  18. {boardwright-0.8.2 → boardwright-0.8.4}/examples/existing/README.md +0 -0
  19. {boardwright-0.8.2 → boardwright-0.8.4}/examples/libs/customlib/README.md +0 -0
  20. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/__main__.py +0 -0
  21. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/board.py +0 -0
  22. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/build.py +0 -0
  23. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/check.py +0 -0
  24. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/circuit.py +0 -0
  25. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/cli.py +0 -0
  26. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/edits.py +0 -0
  27. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/env.py +0 -0
  28. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/errors.py +0 -0
  29. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/live.py +0 -0
  30. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/model.py +0 -0
  31. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/pins.py +0 -0
  32. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/placement.py +0 -0
  33. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/preview.py +0 -0
  34. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/project.py +0 -0
  35. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/review.py +0 -0
  36. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/route.py +0 -0
  37. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/selection.py +0 -0
  38. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/ses.py +0 -0
  39. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/si.py +0 -0
  40. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/silk.py +0 -0
  41. {boardwright-0.8.2 → boardwright-0.8.4}/src/boardwright/verify.py +0 -0
  42. {boardwright-0.8.2 → boardwright-0.8.4}/tests/conftest.py +0 -0
  43. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/create_golden/customlib_test.kicad_pcb +0 -0
  44. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/create_golden/esp32c3_min.kicad_pcb +0 -0
  45. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/create_golden/ldo_breakout.kicad_pcb +0 -0
  46. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/create_golden/rp2040_min.kicad_pcb +0 -0
  47. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/create_golden/stm32f103_4l.kicad_pcb +0 -0
  48. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/create_golden/stm32f103_min.kicad_pcb +0 -0
  49. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/create_golden/tps54202_buck.kicad_pcb +0 -0
  50. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/customlib_test.dsn +0 -0
  51. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/customlib_test.kicad_pcb +0 -0
  52. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/customlib_test.kicad_pro +0 -0
  53. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/esp32c3_min.dsn +0 -0
  54. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/esp32c3_min.kicad_pcb +0 -0
  55. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/esp32c3_min.kicad_pro +0 -0
  56. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/esp32c3_min_back.dsn +0 -0
  57. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/esp32c3_min_back.kicad_pcb +0 -0
  58. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/esp32c3_min_back.kicad_pro +0 -0
  59. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/ldo_arcs.dsn +0 -0
  60. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/ldo_arcs.kicad_pcb +0 -0
  61. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/ldo_arcs.kicad_pro +0 -0
  62. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/ldo_breakout.dsn +0 -0
  63. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/ldo_breakout.kicad_pcb +0 -0
  64. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/ldo_breakout.kicad_pro +0 -0
  65. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/rp2040_min.dsn +0 -0
  66. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/rp2040_min.kicad_pcb +0 -0
  67. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/rp2040_min.kicad_pro +0 -0
  68. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/stm32f103_4l.dsn +0 -0
  69. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/stm32f103_4l.kicad_pcb +0 -0
  70. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/stm32f103_4l.kicad_pro +0 -0
  71. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/stm32f103_min.dsn +0 -0
  72. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/stm32f103_min.kicad_pcb +0 -0
  73. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/stm32f103_min.kicad_pro +0 -0
  74. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/tps54202_buck.dsn +0 -0
  75. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/tps54202_buck.kicad_pcb +0 -0
  76. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/tps54202_buck.kicad_pro +0 -0
  77. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/tps54202_routed.dsn +0 -0
  78. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/tps54202_routed.kicad_pcb +0 -0
  79. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/dsn/tps54202_routed.kicad_pro +0 -0
  80. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ldo_r50.net +0 -0
  81. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/live_unsaved/r1_moved.kicad_pcb.txt +0 -0
  82. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/live_unsaved/untouched.kicad_pcb.txt +0 -0
  83. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/customlib_test.kicad_pcb +0 -0
  84. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/customlib_test.kicad_sch.sha256 +0 -0
  85. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/esp32c3_min.kicad_pcb +0 -0
  86. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/esp32c3_min.kicad_sch.sha256 +0 -0
  87. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/esp32c3_min_u1_r90.kicad_pcb +0 -0
  88. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/esp32c3_min_u1_r90.kicad_sch.sha256 +0 -0
  89. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/esp32c3_min_u1_r90_back.kicad_pcb +0 -0
  90. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/esp32c3_min_u1_r90_back.kicad_sch.sha256 +0 -0
  91. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/ldo_breakout.kicad_pcb +0 -0
  92. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/ldo_breakout.kicad_sch.sha256 +0 -0
  93. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/rp2040_min.kicad_pcb +0 -0
  94. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/rp2040_min.kicad_sch.sha256 +0 -0
  95. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/stm32f103_4l.kicad_pcb +0 -0
  96. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/stm32f103_4l.kicad_sch.sha256 +0 -0
  97. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/stm32f103_min.kicad_pcb +0 -0
  98. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/stm32f103_min.kicad_sch.sha256 +0 -0
  99. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/tps54202_buck.kicad_pcb +0 -0
  100. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/place_golden/tps54202_buck.kicad_sch.sha256 +0 -0
  101. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/reader/cheapino_kicad8.NOTICE +0 -0
  102. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/reader/cheapino_kicad8.kicad_pcb +0 -0
  103. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/reader/demos.json +0 -0
  104. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/reader/golden.json +0 -0
  105. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/reader/kicad_tools_moves.json +0 -0
  106. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/schematic_golden/customlib_test.kicad_sch +0 -0
  107. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/schematic_golden/esp32c3_min.kicad_sch +0 -0
  108. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/schematic_golden/ldo_breakout.kicad_sch +0 -0
  109. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/schematic_golden/rp2040_min.kicad_sch +0 -0
  110. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/schematic_golden/stm32f103_4l.kicad_sch +0 -0
  111. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/schematic_golden/stm32f103_min.kicad_sch +0 -0
  112. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/schematic_golden/tps54202_buck.kicad_sch +0 -0
  113. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/esp32c3_min.golden.kicad_pcb +0 -0
  114. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/esp32c3_min.kicad_pcb +0 -0
  115. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/esp32c3_min.ses +0 -0
  116. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/ldo_breakout.golden.kicad_pcb +0 -0
  117. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/ldo_breakout.kicad_pcb +0 -0
  118. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/ldo_breakout.ses +0 -0
  119. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/ldo_routed.golden.kicad_pcb +0 -0
  120. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/ldo_routed.kicad_pcb +0 -0
  121. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/ldo_routed.ses +0 -0
  122. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/ldo_stubs.golden.kicad_pcb +0 -0
  123. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/ldo_stubs.kicad_pcb +0 -0
  124. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/ldo_stubs.ses +0 -0
  125. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/stm32f103_4l.golden.kicad_pcb +0 -0
  126. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/stm32f103_4l.kicad_pcb +0 -0
  127. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/stm32f103_4l.ses +0 -0
  128. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/tps54202_buck.golden.kicad_pcb +0 -0
  129. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/tps54202_buck.kicad_pcb +0 -0
  130. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/ses/tps54202_buck.ses +0 -0
  131. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/silk_refs/customlib_test.kicad_pcb +0 -0
  132. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/silk_refs/esp32c3_min.kicad_pcb +0 -0
  133. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/silk_refs/golden.json +0 -0
  134. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/silk_refs/ldo_breakout.kicad_pcb +0 -0
  135. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/silk_refs/rp2040_min.kicad_pcb +0 -0
  136. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/silk_refs/stm32f103_4l.kicad_pcb +0 -0
  137. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/silk_refs/stm32f103_min.kicad_pcb +0 -0
  138. {boardwright-0.8.2 → boardwright-0.8.4}/tests/data/silk_refs/tps54202_buck.kicad_pcb +0 -0
  139. {boardwright-0.8.2 → boardwright-0.8.4}/tests/reader_dump.py +0 -0
  140. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_board_model.py +0 -0
  141. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_board_reader.py +0 -0
  142. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_clearance.py +0 -0
  143. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_create_golden.py +0 -0
  144. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_dsn_export.py +0 -0
  145. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_edit_route.py +0 -0
  146. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_env_kicad_cli.py +0 -0
  147. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_env_pcbnew.py +0 -0
  148. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_library_scope.py +0 -0
  149. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_live.py +0 -0
  150. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_live_unsaved.py +0 -0
  151. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_open_in_kicad.py +0 -0
  152. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_pipeline.py +0 -0
  153. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_place_golden.py +0 -0
  154. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_remove.py +0 -0
  155. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_sch_cli.py +0 -0
  156. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_sch_repoint.py +0 -0
  157. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_sch_subsheet.py +0 -0
  158. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_schematic_golden.py +0 -0
  159. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_ses_import.py +0 -0
  160. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_si.py +0 -0
  161. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_silk_refs.py +0 -0
  162. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_unwritable_output.py +0 -0
  163. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_verify_existing.py +0 -0
  164. {boardwright-0.8.2 → boardwright-0.8.4}/tests/test_workflows.py +0 -0
@@ -7,6 +7,40 @@ the command line).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.8.4] - 2026-11-20
11
+
12
+ ### Fixed
13
+
14
+ - `existing reroute` leaves the board as it was read when the route cannot
15
+ run, and exits 4 with the reason. It wrote the named nets' rip-up first and
16
+ left it there when Freerouting gave no SES; on a timeout it also said
17
+ "nothing was checked or written as a result" (#104).
18
+ - The DSN export refuses a board whose Edge.Cuts outline does not close
19
+ within 1 um, naming the open ends. It wrote a DSN with no boundary, which
20
+ Freerouting 2.5.0 fails on with a NullPointerException (#105).
21
+ - `existing apply` refuses a `VIAS` entry that is not
22
+ `(net, x, y[, size, drill])` with exit 64 before changing anything. A nested
23
+ `("NET", (x, y))` crashed with an IndexError, exit 2, after the rip-up and
24
+ moves were written (#107).
25
+ - `sch add` takes a net named the way KiCad's netlist names a local label,
26
+ with the sheet path in front (`/LED_A`), as that label. It wrote a new
27
+ label `/LED_A`, which KiCad kept on a net of its own. Any other name with a
28
+ `/` in it is refused (exit 64), naming the sheet's local labels (#102).
29
+
30
+ ## [0.8.3] - 2026-11-20
31
+
32
+ ### Fixed
33
+
34
+ - `existing update` sets or clears each footprint's `dnp` and
35
+ `exclude_from_bom` attributes from its symbol, as KiCad's Update PCB does,
36
+ leaving its other attributes as they are. They were never read, so KiCad's
37
+ schematic parity check reported "'Do not populate' settings differ" and
38
+ "'Exclude from bill of materials' settings differ" (#98).
39
+ - `sch add` with a library symbol no longer stops with a traceback (exit 2)
40
+ when the sheet's first placed part has no pins: it takes its pin format
41
+ from a part that has one. A sheet with none refuses the library part with a
42
+ message (exit 1); copying an existing part still works there (#99).
43
+
10
44
  ## [0.8.2] - 2026-11-20
11
45
 
12
46
  ### Fixed
@@ -357,7 +391,9 @@ First public release.
357
391
  - `boardwright impedance` (IPC-2141 closed form) and `doctor`.
358
392
  - Seven example boards and specs for KiCad's own demo projects.
359
393
 
360
- [Unreleased]: https://github.com/heibench/boardwright/compare/v0.8.2...HEAD
394
+ [Unreleased]: https://github.com/heibench/boardwright/compare/v0.8.4...HEAD
395
+ [0.8.4]: https://github.com/heibench/boardwright/compare/v0.8.3...v0.8.4
396
+ [0.8.3]: https://github.com/heibench/boardwright/compare/v0.8.2...v0.8.3
361
397
  [0.8.2]: https://github.com/heibench/boardwright/compare/v0.8.1...v0.8.2
362
398
  [0.8.1]: https://github.com/heibench/boardwright/compare/v0.8.0...v0.8.1
363
399
  [0.8.0]: https://github.com/heibench/boardwright/compare/v0.7.0...v0.8.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: boardwright
3
- Version: 0.8.2
3
+ Version: 0.8.4
4
4
  Summary: Generate and edit KiCad boards and schematics from a short Python description, checked by KiCad itself.
5
5
  Project-URL: Homepage, https://github.com/heibench/boardwright
6
6
  Project-URL: Documentation, https://heibench.com/boardwright/
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "boardwright"
3
- version = "0.8.2"
3
+ version = "0.8.4"
4
4
  description = "Generate and edit KiCad boards and schematics from a short Python description, checked by KiCad itself."
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
@@ -0,0 +1 @@
1
+ __version__ = "0.8.4"
@@ -11,6 +11,8 @@ import re
11
11
  import uuid
12
12
  from pathlib import Path
13
13
 
14
+ from .errors import Usage
15
+
14
16
 
15
17
  def num(v: float) -> str:
16
18
  """A length or angle as KiCad writes it: at most 6 decimals (1 nm), no
@@ -146,9 +148,20 @@ def _cross(p1, p2, p3, p4) -> bool:
146
148
  return o(p1, p2, p3) * o(p1, p2, p4) < 0 and o(p3, p4, p1) * o(p3, p4, p2) < 0
147
149
 
148
150
 
151
+ def check_vias(m) -> None:
152
+ """Each VIAS entry is (net, x, y[, size, drill]); anything else is a usage
153
+ error naming the entry, before anything is written (#107)."""
154
+ for v in getattr(m, "VIAS", []):
155
+ ok = (isinstance(v, (tuple, list)) and len(v) in (3, 5) and isinstance(v[0], str)
156
+ and all(isinstance(n, (int, float)) and not isinstance(n, bool) for n in v[1:]))
157
+ if not ok:
158
+ raise Usage(f"VIAS entry {v!r} is not (net, x, y[, size, drill])")
159
+
160
+
149
161
  def check_tracks(m) -> None:
150
162
  """Hand routes of different nets must not cross on a layer, or pass over a foreign hand via."""
151
163
  import math
164
+ check_vias(m)
152
165
  segs = [(t[0], a, b, t[3] if len(t) > 3 else "F.Cu", t[2] if len(t) > 2 else 0.25)
153
166
  for t in getattr(m, "TRACKS", []) for a, b in zip(t[1], t[1][1:])]
154
167
  for i, (n1, a, b, l1, _w) in enumerate(segs):
@@ -62,6 +62,7 @@ from dataclasses import dataclass, field
62
62
  from pathlib import Path
63
63
 
64
64
  from .copper import blocks
65
+ from .errors import EnvironmentFault
65
66
  from .model import _arc_points
66
67
 
67
68
  # KiCad's Default net class as kicad-tools 0.29 named and sized it when a board
@@ -377,6 +378,27 @@ def _outline(root: list) -> tuple[list, list]:
377
378
  return list(board.exterior.coords)[:-1], [list(c.exterior.coords)[:-1] for c in cutouts if c.area > 0]
378
379
 
379
380
 
381
+ def _outline_problem(root: list) -> str:
382
+ """Why the top-level Edge.Cuts gives no closed board outline, for the error
383
+ that stops the export (#105): its unreadable shape, or its open ends."""
384
+ try:
385
+ segs = _outline_segments(root)
386
+ except ValueError as e:
387
+ return str(e)
388
+ if not segs:
389
+ return "there is no Edge.Cuts outline"
390
+ ends: dict = {}
391
+ for a, b in segs:
392
+ for p in (a, b):
393
+ k = (round(p[0], 3), round(p[1], 3))
394
+ ends[k] = ends.get(k, 0) + 1
395
+ open_ = sorted(p for p, n in ends.items() if n % 2)
396
+ if not open_:
397
+ return "the Edge.Cuts outline does not enclose an area"
398
+ shown = ", ".join(f"({x:g}, {y:g})" for x, y in open_[:6]) + (", ..." if len(open_) > 6 else "")
399
+ return f"the Edge.Cuts outline does not close within 1 um: open ends at {shown} (board mm)"
400
+
401
+
380
402
  def _inset(outline: list, cutouts: list, edge: float) -> tuple[list, list]:
381
403
  """Move the boundary in, and the cutouts out, by the copper-to-edge clearance:
382
404
  Specctra has no edge rule, but a router keeps copper inside the boundary and
@@ -647,10 +669,12 @@ class _Dsn:
647
669
  out += [f" (layer {_q(layer)}", " (type signal)", " (property", f" (index {i})",
648
670
  " )", " )"]
649
671
  boundary, cutouts = _inset(*_outline(self.root), self.edge)
650
- if boundary:
651
- out += [" (boundary", " (path pcb 0"]
652
- out += [f" {_um(x):.1f} {_um(y):.1f}" for x, y in boundary + boundary[:1]]
653
- out += [" )", " )"]
672
+ if not boundary: # Freerouting cannot build a board without one (#105)
673
+ raise EnvironmentFault(f"{self.pcb.name}: no board outline for the router: {_outline_problem(self.root)}. "
674
+ "Close it on Edge.Cuts in KiCad.")
675
+ out += [" (boundary", " (path pcb 0"]
676
+ out += [f" {_um(x):.1f} {_um(y):.1f}" for x, y in boundary + boundary[:1]]
677
+ out += [" )", " )"]
654
678
  d = self.classes["Default"]
655
679
  c = _um(d.clearance)
656
680
  out += [" (rule", f" (width {_um(d.width):.1f})", f" (clearance {c:.1f})",
@@ -36,6 +36,7 @@ import json
36
36
  import math
37
37
  import re
38
38
  import subprocess
39
+ import sys
39
40
  import types
40
41
  from pathlib import Path
41
42
 
@@ -348,6 +349,7 @@ def remove_footprints(t: str, names: list[str], force: bool = False) -> tuple[st
348
349
  def apply(d: Path, force: bool = False) -> int:
349
350
  pcb, m = find(d), spec(d)
350
351
  env.warn_if_open_in_kicad(pcb)
352
+ copper.check_vias(m)
351
353
  rm = list(getattr(m, "REMOVE", []))
352
354
  if rm:
353
355
  original = pcb.read_text()
@@ -458,15 +460,42 @@ def reroute(d: Path, nets_: list[str]) -> int:
458
460
  text0, n = copper.ripup(original, set(nets_))
459
461
  pcb.write_text(text0)
460
462
  print(f"ripped up {n} item(s)")
463
+ try:
464
+ kept, arcs = _route_and_graft(pcb, m, o, nets_, original, names0, was_open, text0)
465
+ except BaseException:
466
+ # nothing lands unless the route does: a failure leaves the board as it was read (#104)
467
+ if pcb.read_text() != original:
468
+ pcb.write_text(original)
469
+ print(f"{pcb.name} restored as it was read; nothing changed", file=sys.stderr)
470
+ raise
471
+ b1 = Board(pcb)
472
+ for net in nets_:
473
+ L = sum(t.length for t in b1.tracks if t.net == net)
474
+ print(f" {net}: {L:.2f} mm routed, {sum(1 for v in b1.vias if v.net == net)} via(s)")
475
+ left = len(ratsnest(b1, {z.net for z in b1.zones if not z.keepout}))
476
+ print(f"kept {kept} new item(s) on the named nets; {arcs} curved track(s) shown to the router as fixed; "
477
+ f"tracks {len(b0.tracks)} -> {len(b1.tracks)}; unrouted connections on unpoured nets: {left}")
478
+ write_preview(pcb, o / "preview.png")
479
+ return 0
480
+
481
+
482
+ def _route_and_graft(pcb, m, o, nets_, original, names0, was_open, text0) -> tuple[int, int]:
483
+ """reroute's routing half, on the board with the named nets ripped up: export,
484
+ Freerouting, and the graft of its result. Any failure raises; reroute then
485
+ puts the board back as it was read. Returns the items grafted and the arcs
486
+ the router was shown as fixed."""
461
487
  dsn, ses = o / f"{m.NAME}.dsn", o / f"{m.NAME}.ses"
462
488
  if ses.exists():
463
489
  ses.unlink()
464
490
  arcs = dsn_.export(pcb, dsn)
465
491
  cmd = [*env.freerouting(), "-de", str(dsn), "-do", str(ses), "-mp", str(getattr(m, "FR_PASSES", 5))]
466
- r = subprocess.run(cmd, capture_output=True, text=True, timeout=getattr(m, "FR_TIMEOUT", 900))
492
+ limit = getattr(m, "FR_TIMEOUT", 900)
493
+ try:
494
+ r = subprocess.run(cmd, capture_output=True, text=True, timeout=limit)
495
+ except subprocess.TimeoutExpired as e:
496
+ raise EnvironmentFault(f"freerouting did not finish in FR_TIMEOUT = {limit} s") from e
467
497
  (o / "freerouting.log").write_text(r.stdout + r.stderr)
468
498
  if not ses.exists():
469
- pcb.write_text(text0)
470
499
  raise EnvironmentFault("freerouting produced no SES; see boardwright_out/freerouting.log")
471
500
  layers = ses_.copper_layers(text0)
472
501
  tracks, vias = ses_.read(ses, layers)
@@ -489,15 +518,7 @@ def reroute(d: Path, nets_: list[str]) -> int:
489
518
  text = text.rstrip()[:-1].rstrip() + "".join(old) + "\n)\n"
490
519
  pcb.write_text(text)
491
520
  print(f" the router could not finish {failed}: original routing restored")
492
- b1 = Board(pcb)
493
- for net in nets_:
494
- L = sum(t.length for t in b1.tracks if t.net == net)
495
- print(f" {net}: {L:.2f} mm routed, {sum(1 for v in b1.vias if v.net == net)} via(s)")
496
- left = len(ratsnest(b1, {z.net for z in b1.zones if not z.keepout}))
497
- print(f"kept {len(graft)} new item(s) on the named nets; {arcs} curved track(s) shown to the router as fixed; "
498
- f"tracks {len(b0.tracks)} -> {len(b1.tracks)}; unrouted connections on unpoured nets: {left}")
499
- write_preview(pcb, o / "preview.png")
500
- return 0
521
+ return len(graft), arcs
501
522
 
502
523
 
503
524
  def cli(argv: list[str]) -> int:
@@ -368,7 +368,11 @@ def _from_library(template: str, body: str, lib_id: str, x: float, y: float) ->
368
368
  t = _fresh(template)
369
369
  p0 = re.search(r"\n\t\t\(property ", t)
370
370
  i0 = re.search(r"\n\t\t\(instances\b", t)
371
- pin_tpl = next(t[s:e] for s, e in blocks(t, ("pin",)))
371
+ pins_ = blocks(t, ("pin",))
372
+ if not pins_:
373
+ raise SystemExit(f"no placed part on the sheet has a pin to take the file's format from; "
374
+ f"add {lib_id} in KiCad, or name an existing part to copy (#99)")
375
+ pin_tpl = t[pins_[0][0]:pins_[0][1]]
372
376
  head, tail = t[:p0.start()], t[i0.start():]
373
377
  head = re.sub(r'\(lib_id "[^"]*"\)', f'(lib_id "{lib_id}")', head, count=1)
374
378
  head = re.sub(r"\n\t\t\(lib_name \"[^\"]*\"\)", "", head)
@@ -432,6 +436,34 @@ def _target(d: Path, name: str | None, all_sheets: list[Sheet]) -> Sheet:
432
436
  return hits[0]
433
437
 
434
438
 
439
+ def _sheet_path(sh: Sheet, all_sheets: list[Sheet], top: Path) -> str:
440
+ """The sheet's path as KiCad's netlist names it: "/" for the root, then each
441
+ sheet's name down to this one, "/power/" or "/io/adc/"."""
442
+ names, here = [], sh
443
+ while here.path != top:
444
+ parent = next(((p, b) for p in all_sheets for a, e in blocks(p.text, ("sheet",)) for b in [p.text[a:e]]
445
+ if re.search(r'\(property "Sheetfile" "%s"' % re.escape(here.path.name), b)), None)
446
+ if parent is None:
447
+ break
448
+ here, block = parent
449
+ names.append(prop(block, "Sheetname") or "")
450
+ return "/" + "".join(n + "/" for n in reversed(names))
451
+
452
+
453
+ def _local_name(net: str, prefix: str, labels: set[str], known: set[str], where: str) -> str:
454
+ """The label text for a net named in a pin map. KiCad names a local label's
455
+ net with its sheet path in front (/LED_A on the root sheet), so that form
456
+ joins the label; any other name with a "/" in it is refused rather than
457
+ written as a new label with the slash in its text (#102)."""
458
+ if net in known or "/" not in net:
459
+ return net
460
+ name = net[len(prefix):] if net.startswith(prefix) else None
461
+ if name and "/" not in name and name in labels:
462
+ return name
463
+ raise Usage(f"net {net!r} is not a label on {where}: a name with a sheet path in front ({prefix}NAME) must name one "
464
+ f"of its local labels ({', '.join(sorted(labels)) or 'none'}). Nothing written.")
465
+
466
+
435
467
  def add(d: Path, spec_path: str) -> int:
436
468
  sp = importlib.util.spec_from_file_location("sch_spec", spec_path)
437
469
  m = importlib.util.module_from_spec(sp)
@@ -465,15 +497,20 @@ def add(d: Path, spec_path: str) -> int:
465
497
  glabel_t, hlabel_t = first("global_label", [t, *rest]), first("hierarchical_label", [t])
466
498
  if wire_t is None or (label_t is None and glabel_t is None):
467
499
  raise SystemExit("the project has no wire or no label to take the file's format from")
468
- template = next((b for b in here if not (prop(b, "Reference") or "#").startswith("#")), None)
500
+ parts = [b for b in here if not (prop(b, "Reference") or "#").startswith("#")]
501
+ # a part with a pin, which a symbol added from the library copies its pin lines from (#99);
502
+ # any part carries the sheet's instance path
503
+ template = next((b for b in parts if blocks(b, ("pin",))), parts[0] if parts else None)
469
504
  if template is None:
470
505
  raise SystemExit(f"{sh.path.name} has no placed part to take its format and hierarchy path from; add one in KiCad first")
471
506
  path = _instance_path(template)
507
+ prefix = _sheet_path(sh, all_sheets, root(d).path)
472
508
  plan = [] # (ref, like, value, footprint, pins, lib_id, source, from library, extent)
473
509
  for ref, like, value, footprint, pins in m.ADD:
474
510
  if ref in taken or any(ref == p[0] for p in plan):
475
511
  raise Usage(f"{ref} already exists")
476
- pins = {str(k): v for k, v in pins.items()}
512
+ pins = {str(k): _local_name(v, prefix, labels, labels | hier | globals_ | set(power), sh.path.name)
513
+ for k, v in pins.items()}
477
514
  if like in by_ref and not like.startswith("#"):
478
515
  src_text, src = by_ref[like]
479
516
  lib_id = re.search(r'\(lib_id "([^"]*)"', src).group(1)
@@ -78,6 +78,7 @@ def read_netlist(path: Path) -> tuple[dict, dict]:
78
78
  "ref": _str(c, "ref"), "value": _str(c, "value") or "", "footprint": _str(c, "footprint") or "",
79
79
  "sheetname": re.sub(r"\\(.)", r"\1", sp.group(1)), "sheetfile": props.get("Sheetfile", ""),
80
80
  "skip": "exclude_from_board" in props, "fields": fields,
81
+ "dnp": "dnp" in props, "exclude_from_bom": "exclude_from_bom" in props,
81
82
  }
82
83
  pins = {}
83
84
  for s, e in blocks(text, ("net",)):
@@ -127,6 +128,36 @@ def with_fields(fp: str, fields: dict[str, str]) -> tuple[str, list[str]]:
127
128
  return fp, changed
128
129
 
129
130
 
131
+ # The order KiCad 10 writes a footprint's (attr ...) tokens in.
132
+ _ATTR_ORDER = ("smd", "through_hole", "board_only", "exclude_from_pos_files", "exclude_from_bom",
133
+ "allow_missing_courtyard", "dnp", "allow_soldermask_bridges")
134
+
135
+
136
+ def with_flags(fp: str, sym: dict) -> tuple[str, list[str]]:
137
+ """The board footprint with its symbol's "Do not populate" and "Exclude
138
+ from bill of materials" flags in its (attr ...), as KiCad's Update PCB
139
+ sets them; its other attributes are left as they are (#98). Returns the
140
+ block and what changed, e.g. ["dnp set"]."""
141
+ m = re.search(r"\n\t\t\(attr((?: [a-z_]+)*)\)", fp)
142
+ have = m.group(1).split() if m else []
143
+ want = [a for a in have if a not in ("dnp", "exclude_from_bom")] + [a for a in ("dnp", "exclude_from_bom") if sym[a]]
144
+ want.sort(key=lambda a: _ATTR_ORDER.index(a) if a in _ATTR_ORDER else len(_ATTR_ORDER))
145
+ if want == have:
146
+ return fp, []
147
+ changed = [f"{a} {'set' if sym[a] else 'cleared'}" for a in ("dnp", "exclude_from_bom") if (a in have) != sym[a]]
148
+ line = f"\n\t\t(attr {' '.join(want)})" if want else ""
149
+ if m:
150
+ return fp[:m.start()] + line + fp[m.end():], changed
151
+ k = max((e for s, e in blocks(fp, ("property",)) if fp[s:s + 13] == "\n\t\t(property "), default=None)
152
+ for key in ("path", "sheetname", "sheetfile"):
153
+ km = re.search(r'\n\t\t\(%s "[^"]*"\)' % key, fp)
154
+ if km:
155
+ k = km.end()
156
+ if k is None:
157
+ k = fp.index("\n", fp.index("\n\t\t(at "))
158
+ return fp[:k] + line + fp[k:], changed
159
+
160
+
130
161
  def _footprints(t: str) -> list[tuple[int, int]]:
131
162
  return [(s, e) for s, e in blocks(t, ("footprint",)) if t[s:s + 13] == "\n\t(footprint "]
132
163
 
@@ -460,6 +491,9 @@ def update(d: Path, pcb: Path, netlist: str | None = None, body: str = "keep") -
460
491
  new, fields = with_fields(new, c["fields"])
461
492
  if fields:
462
493
  notes.append(f"{c['ref']}: {', '.join(fields)} from the symbol")
494
+ new, flags = with_flags(new, c)
495
+ if flags:
496
+ notes.append(f"{c['ref']}: {', '.join(flags)}")
463
497
  for _s, _e, num, have in _pads(new):
464
498
  if num in want and want[num] != have:
465
499
  notes.append(f"{c['ref']}.{num}: net {have or '(none)'} -> {want[num]}")
@@ -482,7 +516,7 @@ def update(d: Path, pcb: Path, netlist: str | None = None, body: str = "keep") -
482
516
  text = mod.read_text()
483
517
  ex0, ey0, ex1, ey1 = _extent(text)
484
518
  fx, fy = round(x - ex0, 2), round(y - ey0, 2)
485
- made.append(with_fields(new_footprint(text, c["footprint"], c, path, fx, fy, want), c["fields"])[0])
519
+ made.append(with_flags(with_fields(new_footprint(text, c["footprint"], c, path, fx, fy, want), c["fields"])[0], c)[0])
486
520
  print(f"{c['ref']}: added {c['footprint']} at ({fx:g}, {fy:g}), beside the board: place it")
487
521
  y += ey1 - ey0 + 2.54
488
522
  row = max(row, ex1 - ex0)
@@ -0,0 +1,76 @@
1
+ """`existing reroute` and `existing apply` change nothing when they cannot finish
2
+ (#104, #105, #107). The router here is a stand-in: these failures happen before
3
+ or instead of a route, so they need no Freerouting."""
4
+
5
+ import hashlib
6
+ import sys
7
+
8
+ import pytest
9
+
10
+ from boardwright import copper, dsn, env
11
+ from boardwright.cli import main
12
+ from boardwright.errors import EnvironmentFault, Usage
13
+
14
+
15
+ def _hash(p):
16
+ return hashlib.sha256(p.read_bytes()).hexdigest()
17
+
18
+
19
+ @pytest.fixture
20
+ def board(ldo_copy):
21
+ return ldo_copy / "ldo_breakout.kicad_pcb"
22
+
23
+
24
+ @pytest.mark.parametrize("router, spec, says", [
25
+ ("pass", "", "freerouting produced no SES"),
26
+ ("import time; time.sleep(30)", "FR_TIMEOUT = 0.5\n", "freerouting did not finish in FR_TIMEOUT = 0.5 s"),
27
+ ], ids=["no SES", "timeout"])
28
+ def test_a_failed_reroute_leaves_the_board_as_it_was(ldo_copy, board, monkeypatch, capsys, router, spec, says):
29
+ """It wrote the ripped-up board and left it there: LED_A's track was gone,
30
+ and a timeout said "nothing was checked or written" (#104)."""
31
+ monkeypatch.setattr(env, "freerouting", lambda: [sys.executable, "-c", router])
32
+ if spec:
33
+ (ldo_copy / "boardwright.py").write_text(spec)
34
+ before = _hash(board)
35
+ assert main(["existing", str(ldo_copy), "reroute", "LED_A"]) == 4
36
+ err = capsys.readouterr().err
37
+ assert says in err and "restored as it was read; nothing changed" in err
38
+ assert _hash(board) == before
39
+
40
+
41
+ def test_an_open_outline_stops_the_export_naming_its_ends(ldo_copy, board, monkeypatch, capsys):
42
+ """A 5 um gap gave a DSN with no boundary, on which Freerouting 2.5.0 throws
43
+ a NullPointerException (#105). Now the export refuses, and reroute leaves the
44
+ board as it was."""
45
+ t = board.read_text()
46
+ a = "(gr_line\n\t\t(start 133.5 95)\n\t\t(end 163.5 95)"
47
+ assert t.count(a) == 1
48
+ board.write_text(t.replace(a, "(gr_line\n\t\t(start 133.5 95)\n\t\t(end 163.495 95)"))
49
+ with pytest.raises(EnvironmentFault, match=r"open ends at \(163\.495, 95\), \(163\.5, 95\)"):
50
+ dsn.export(board, ldo_copy / "x.dsn")
51
+ monkeypatch.setattr(env, "freerouting", lambda: pytest.fail("no route without an outline"))
52
+ before = _hash(board)
53
+ assert main(["existing", str(ldo_copy), "reroute", "LED_A"]) == 4
54
+ assert "does not close within 1 um" in capsys.readouterr().err
55
+ assert _hash(board) == before
56
+
57
+
58
+ @pytest.mark.parametrize("entry", [("LED_A", (10.0, 10.0)), ("LED_A", 10.0), ("LED_A", 1.0, 2.0, 0.6),
59
+ (None, 1.0, 2.0), ("LED_A", "1", 2.0), "LED_A"])
60
+ def test_a_via_in_another_form_is_a_usage_error(entry):
61
+ with pytest.raises(Usage, match=r"is not \(net, x, y\[, size, drill\]\)"):
62
+ copper.check_vias(type("M", (), {"VIAS": [entry]}))
63
+
64
+
65
+ @pytest.mark.parametrize("entry", [("LED_A", 1.0, 2.0), ("LED_A", 1, 2, 0.6, 0.3), ["LED_A", 1.0, 2.0]])
66
+ def test_the_documented_via_forms_pass(entry):
67
+ copper.check_vias(type("M", (), {"VIAS": [entry]}))
68
+
69
+
70
+ def test_apply_refuses_a_bad_via_before_ripping_anything_up(ldo_copy, board, capsys):
71
+ """It ripped up and moved first, then crashed with an IndexError, exit 2 (#107)."""
72
+ (ldo_copy / "boardwright.py").write_text('RIPUP = ["LED_A"]\nVIAS = [("LED_A", (10.0, 10.0))]\n')
73
+ before = _hash(board)
74
+ assert main(["existing", str(ldo_copy), "apply"]) == 64
75
+ assert "VIAS entry ('LED_A', (10.0, 10.0)) is not (net, x, y[, size, drill])" in capsys.readouterr().err
76
+ assert _hash(board) == before
@@ -223,3 +223,89 @@ def test_a_project_row_naming_the_stock_folder_is_found(tmp_path, monkeypatch, k
223
223
  (d / table).write_text(f'({table.replace("-", "_")}\n (version 7)\n'
224
224
  f' (lib (name "{nick}")(type "KiCad")(uri "${{{var}}}/{lib}")(options "")(descr ""))\n)\n')
225
225
  assert sch._in_table(d / table, nick, d, kind=kind) == (True, stock / lib)
226
+
227
+
228
+ def _strip_pins(f, refs):
229
+ """The sheet with the placed parts `refs` written without (pin ...) lines,
230
+ as a part with no pins (a mounting hole, a logo) is."""
231
+ t = f.read_text()
232
+ for s, e in reversed(sch.Sheet(f).instances()):
233
+ if sch.prop(t[s:e], "Reference") in refs:
234
+ t = t[:s] + re.sub(r'\n\t\t\(pin "[^"]*" \(uuid "[^"]*"\)\n\t\t\)', "", t[s:e]) + t[e:]
235
+ f.write_text(t)
236
+
237
+
238
+ def test_a_library_part_is_added_when_the_first_part_has_no_pins(proj, tmp_path):
239
+ """#99: add took its pin lines from the sheet's first placed part, J1 here,
240
+ and crashed (StopIteration, exit 2) when it had none."""
241
+ _strip_pins(proj / SCH, {"J1"})
242
+ assert main(["sch", str(proj), "add", _spec(tmp_path, [R50])]) == 0
243
+ after = (proj / SCH).read_text()
244
+ part = next(after[s:e] for s, e in sch.Sheet(proj / SCH).instances() if '(lib_id "Mine:R_new")' in after[s:e])
245
+ assert sorted(re.findall(r'\(pin "([^"]*)"', part)) == ["1", "2"]
246
+
247
+
248
+ def test_a_sheet_with_no_pinned_part_refuses_a_library_part_with_a_message(proj, tmp_path, capsys):
249
+ f = proj / SCH
250
+ _strip_pins(f, {sch.prop(f.read_text()[s:e], "Reference") for s, e in sch.Sheet(f).instances()})
251
+ before = f.read_text()
252
+ assert main(["sch", str(proj), "add", _spec(tmp_path, [R50])]) == 1
253
+ assert "no placed part on the sheet has a pin" in capsys.readouterr().err
254
+ assert f.read_text() == before
255
+
256
+
257
+ def test_a_sheet_with_no_pinned_part_still_copies_an_existing_part(proj, tmp_path):
258
+ f = proj / SCH
259
+ _strip_pins(f, {sch.prop(f.read_text()[s:e], "Reference") for s, e in sch.Sheet(f).instances()})
260
+ assert main(["sch", str(proj), "add", _spec(tmp_path, [("R51", "R1", "2k", "Resistor_SMD:R_0805_2012Metric",
261
+ {1: "+3V3", 2: "GND"})])]) == 0
262
+ assert '(reference "R51")' in f.read_text()
263
+
264
+
265
+ def _led_a_local(f):
266
+ """LED_A's two global labels turned into local labels at the same places,
267
+ so KiCad's netlist names the net /LED_A."""
268
+ t = f.read_text()
269
+ t, n = re.subn(r'\t\(global_label "LED_A" \(shape bidirectional\) \(at ([-\d.]+ [-\d.]+ [-\d.]+)\) \(fields_autoplaced yes\)\n'
270
+ r'\t\t\(effects\n\t\t\t\(font\n\t\t\t\t\(size 1\.27 1\.27\)\n\t\t\t\)\n\t\t\t\(justify left\)\n\t\t\)\n'
271
+ r'\t\t\(uuid "([^"]+)"\)\n\t\)',
272
+ lambda m: f'\t(label "LED_A"\n\t\t(at {m.group(1)})\n\t\t(effects\n\t\t\t(font\n\t\t\t\t(size 1.27 1.27)\n'
273
+ f'\t\t\t)\n\t\t\t(justify left bottom)\n\t\t)\n\t\t(uuid "{m.group(2)}")\n\t)', t)
274
+ assert n == 2
275
+ f.write_text(t)
276
+
277
+
278
+ @pytest.mark.parametrize("net", ["/LED_A", "LED_A"])
279
+ def test_a_netlist_name_joins_the_local_label(proj, tmp_path, capsys, net):
280
+ """#102: KiCad's netlist calls the root sheet's local label LED_A "/LED_A".
281
+ That name, like the bare one, joins the label; it wrote (label "/LED_A"),
282
+ a net of its own."""
283
+ f = proj / SCH
284
+ _led_a_local(f)
285
+ assert main(["sch", str(proj), "add", _spec(tmp_path, [("R50", "R1", "1k", "Resistor_SMD:R_0805_2012Metric",
286
+ {1: net, 2: "GND"})])]) == 0
287
+ assert "R50.1 -> LED_A [label]" in capsys.readouterr().out
288
+ after = f.read_text()
289
+ assert '(label "/LED_A"' not in after and after.count('(label "LED_A"') == 3
290
+
291
+
292
+ @pytest.mark.parametrize("net", ["/NOPE", "/sub/LED_A", "LED_A/x"])
293
+ def test_a_slashed_name_that_is_no_label_here_is_refused(proj, tmp_path, capsys, net):
294
+ f = proj / SCH
295
+ _led_a_local(f)
296
+ before = f.read_text()
297
+ assert main(["sch", str(proj), "add", _spec(tmp_path, [("R50", "R1", "1k", "Resistor_SMD:R_0805_2012Metric",
298
+ {1: net, 2: "GND"})])]) == 64
299
+ assert "is not a label on ldo_breakout.kicad_sch" in capsys.readouterr().err
300
+ assert f.read_text() == before
301
+
302
+
303
+ def test_a_sub_sheet_path_is_its_sheet_names(tmp_path):
304
+ def sheet(name, *subs):
305
+ body = "".join(f'\t(sheet\n\t\t(property "Sheetname" "{n}"\n\t\t)\n\t\t(property "Sheetfile" "{f}"\n\t\t)\n\t)\n'
306
+ for n, f in subs)
307
+ (tmp_path / name).write_text(f"(kicad_sch\n{body})\n")
308
+ return sch.Sheet(tmp_path / name)
309
+ top, io, adc = sheet("top.kicad_sch", ("io", "io.kicad_sch")), sheet("io.kicad_sch", ("adc", "adc.kicad_sch")), sheet("adc.kicad_sch")
310
+ all_ = [top, io, adc]
311
+ assert [sch._sheet_path(s, all_, top.path) for s in all_] == ["/", "/io/", "/io/adc/"]
@@ -475,3 +475,65 @@ def test_kicad_finds_no_field_mismatch_after_an_update(ldo, tmp_path):
475
475
  assert before == {"footprint_symbol_field_mismatch", "missing_footprint"}
476
476
  assert main(["existing", str(ldo), "update"]) == 0
477
477
  assert _gate(ldo, tmp_path, "after")["schematic_parity"] == []
478
+
479
+
480
+ def _with_flag(text: str, ref: str, flag: str) -> str:
481
+ """NET with `ref` carrying the component property `flag` (dnp,
482
+ exclude_from_bom), in the form KiCad 10.0.8 writes it."""
483
+ i = text.index(f'(ref "{ref}")')
484
+ j = text.index('\t\t\t(property\n\t\t\t\t(name "Sheetname")', i)
485
+ return text[:j] + f'\t\t\t(property\n\t\t\t\t(name "{flag}")\n\t\t\t)\n' + text[j:]
486
+
487
+
488
+ def test_update_carries_dnp_and_exclude_from_bom_onto_the_footprint(ldo, tmp_path, capsys):
489
+ """KiCad's parity check flags a footprint whose "Do not populate" or
490
+ "Exclude from bill of materials" differs from its symbol's (#98). Set,
491
+ then a second run changes nothing, then cleared in the schematic."""
492
+ _unlink(ldo)
493
+ text = _with_flag(_with_flag(NET.read_text(), "C1", "dnp"), "R1", "exclude_from_bom")
494
+ f = tmp_path / "flags.net"
495
+ f.write_text(text)
496
+ board = ldo / "ldo_breakout.kicad_pcb"
497
+ assert main(["existing", str(ldo), "update", str(f)]) == 0
498
+ out = capsys.readouterr().out
499
+ assert "C1: dnp set" in out and "R1: exclude_from_bom set" in out
500
+ new = board.read_text()
501
+ fp = {update._prop(new[s:e], "Reference"): new[s:e] for s, e in update._footprints(new)}
502
+ assert "\n\t\t(attr smd dnp)\n" in fp["C1"] and "\n\t\t(attr smd exclude_from_bom)\n" in fp["R1"]
503
+ assert "\n\t\t(attr smd)\n" in fp["D1"]
504
+ assert main(["existing", str(ldo), "update", str(f)]) == 0
505
+ assert board.read_text() == new
506
+ assert main(["existing", str(ldo), "update", str(NET)]) == 0
507
+ out = capsys.readouterr().out
508
+ assert "C1: dnp cleared" in out and "R1: exclude_from_bom cleared" in out
509
+ assert "(attr smd dnp)" not in board.read_text() and "exclude_from_bom)" not in board.read_text()
510
+
511
+
512
+ @pytest.mark.parametrize("attr, sym, want", [
513
+ ("(attr through_hole)", {"dnp": True, "exclude_from_bom": True}, "(attr through_hole exclude_from_bom dnp)"),
514
+ ("(attr exclude_from_pos_files exclude_from_bom)", {"dnp": False, "exclude_from_bom": False},
515
+ "(attr exclude_from_pos_files)"),
516
+ ("(attr smd allow_missing_courtyard)", {"dnp": True, "exclude_from_bom": False}, "(attr smd allow_missing_courtyard dnp)"),
517
+ ])
518
+ def test_flags_keep_the_other_attributes_in_kicads_order(attr, sym, want):
519
+ fp = f'\n\t(footprint "X"\n\t\t(at 1 2)\n\t\t{attr}\n\t)'
520
+ assert update.with_flags(fp, sym)[0] == f'\n\t(footprint "X"\n\t\t(at 1 2)\n\t\t{want}\n\t)'
521
+
522
+
523
+ def test_a_footprint_without_attr_gets_one_after_its_link():
524
+ fp = '\n\t(footprint "X"\n\t\t(at 1 2)\n\t\t(property "Reference" "X1"\n\t\t)\n\t\t(path "/a")\n\t\t(sheetfile "x.kicad_sch")\n\t)'
525
+ new, changed = update.with_flags(fp, {"dnp": True, "exclude_from_bom": False})
526
+ assert changed == ["dnp set"] and '(sheetfile "x.kicad_sch")\n\t\t(attr dnp)\n\t)' in new
527
+
528
+
529
+ @pytest.mark.kicad
530
+ @needs_kicad
531
+ def test_kicad_finds_no_flag_mismatch_after_an_update(ldo, tmp_path):
532
+ """#98: D1 set do-not-populate and R1 left out of the BOM in the schematic.
533
+ KiCad's parity check flags both before the update and neither after."""
534
+ assert main(["sch", str(ldo), "set", "D1", "dnp=yes"]) == 0
535
+ assert main(["sch", str(ldo), "set", "R1", "in_bom=no"]) == 0
536
+ before = [v["description"] for v in _gate(ldo, tmp_path, "before")["schematic_parity"]]
537
+ assert len(before) == 2 and all("settings differ" in d for d in before)
538
+ assert main(["existing", str(ldo), "update"]) == 0
539
+ assert _gate(ldo, tmp_path, "after")["schematic_parity"] == []
@@ -1 +0,0 @@
1
- __version__ = "0.8.2"
File without changes
File without changes
File without changes