schematizer 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.
- schematizer-0.1.0/LICENSE +21 -0
- schematizer-0.1.0/PKG-INFO +150 -0
- schematizer-0.1.0/README.md +117 -0
- schematizer-0.1.0/pyproject.toml +78 -0
- schematizer-0.1.0/setup.cfg +4 -0
- schematizer-0.1.0/src/schematizer/__init__.py +18 -0
- schematizer-0.1.0/src/schematizer/_utils.py +80 -0
- schematizer-0.1.0/src/schematizer/cli.py +90 -0
- schematizer-0.1.0/src/schematizer/data/power.kicad_sym +12144 -0
- schematizer-0.1.0/src/schematizer/engine/__init__.py +2 -0
- schematizer-0.1.0/src/schematizer/engine/backend.py +183 -0
- schematizer-0.1.0/src/schematizer/engine/bboxes.py +375 -0
- schematizer-0.1.0/src/schematizer/engine/constants.py +16 -0
- schematizer-0.1.0/src/schematizer/engine/debug_draw.py +351 -0
- schematizer-0.1.0/src/schematizer/engine/decisions.py +479 -0
- schematizer-0.1.0/src/schematizer/engine/gen_schematic.py +899 -0
- schematizer-0.1.0/src/schematizer/engine/kicad_backend.py +247 -0
- schematizer-0.1.0/src/schematizer/engine/net_terminal.py +62 -0
- schematizer-0.1.0/src/schematizer/engine/place.py +2103 -0
- schematizer-0.1.0/src/schematizer/engine/route.py +3247 -0
- schematizer-0.1.0/src/schematizer/engine/sch_node.py +402 -0
- schematizer-0.1.0/src/schematizer/engine/sexp_schematic.py +1667 -0
- schematizer-0.1.0/src/schematizer/engine/snap.py +641 -0
- schematizer-0.1.0/src/schematizer/engine/svg_draw.py +351 -0
- schematizer-0.1.0/src/schematizer/engine/svg_schematic.py +647 -0
- schematizer-0.1.0/src/schematizer/engine/tool_module.py +23 -0
- schematizer-0.1.0/src/schematizer/geometry.py +1075 -0
- schematizer-0.1.0/src/schematizer/ir.py +381 -0
- schematizer-0.1.0/src/schematizer/loader.py +146 -0
- schematizer-0.1.0/src/schematizer/render.py +137 -0
- schematizer-0.1.0/src/schematizer.egg-info/PKG-INFO +150 -0
- schematizer-0.1.0/src/schematizer.egg-info/SOURCES.txt +36 -0
- schematizer-0.1.0/src/schematizer.egg-info/dependency_links.txt +1 -0
- schematizer-0.1.0/src/schematizer.egg-info/entry_points.txt +2 -0
- schematizer-0.1.0/src/schematizer.egg-info/requires.txt +4 -0
- schematizer-0.1.0/src/schematizer.egg-info/top_level.txt +1 -0
- schematizer-0.1.0/tests/test_render.py +147 -0
- schematizer-0.1.0/tests/test_svg.py +214 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Dave Vandenbout.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: schematizer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Turn a generic hierarchical netlist (JSON) into a KiCad schematic.
|
|
5
|
+
Author-email: Dave Vandenbout <dave@vdb.name>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/devbisme/schematizer
|
|
8
|
+
Project-URL: Repository, https://github.com/devbisme/schematizer
|
|
9
|
+
Project-URL: Issues, https://github.com/devbisme/schematizer/issues
|
|
10
|
+
Keywords: KiCad,schematic,netlist,EDA,SKiDL
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: simp_sexp
|
|
30
|
+
Provides-Extra: test
|
|
31
|
+
Requires-Dist: pytest; extra == "test"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+

|
|
35
|
+

|
|
36
|
+

|
|
37
|
+

|
|
38
|
+

|
|
39
|
+

|
|
40
|
+

|
|
41
|
+

|
|
42
|
+
|
|
43
|
+
# schematizer
|
|
44
|
+
|
|
45
|
+
Turn a **generic, hierarchical netlist** (JSON) into a KiCad schematic or an SVG drawing of one.
|
|
46
|
+
|
|
47
|
+
`schematizer` does the *graphical* half of EDA: it takes a tool-neutral netlist
|
|
48
|
+
document and does all the drawing work — component placement, wire routing, and
|
|
49
|
+
writing either editable `.kicad_sch` files or static, cross-linked `.svg` pages
|
|
50
|
+
for a selected KiCad version (6–10). It is not tied to any particular front end: **any** tool that emits the netlist format can use
|
|
51
|
+
it. [SKiDL](https://github.com/devbisme/skidl) is the first such producer —
|
|
52
|
+
SKiDL describes electrical interconnection in code and hands the netlist to
|
|
53
|
+
`schematizer` — but the input is just JSON, so other generators work too.
|
|
54
|
+
|
|
55
|
+
The netlist document (produced by
|
|
56
|
+
`skidl.schematic_netlist.build_generic_netlist`, or any equivalent emitter)
|
|
57
|
+
embeds each component's symbol definition and carries layout *hints* —
|
|
58
|
+
component mirror/rotate (`symtx`) and net stubbing (`stub`/`netio`). Because
|
|
59
|
+
symbols are embedded, this tool needs **no access to KiCad symbol libraries**.
|
|
60
|
+
|
|
61
|
+
## Install
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install schematizer
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Command-line use
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# netlist.json -> KiCad 9 schematic files in ./out/
|
|
71
|
+
schematizer netlist.json --tool kicad9 -o out --top-name mydesign
|
|
72
|
+
|
|
73
|
+
# ...or a set of linked SVG pages instead
|
|
74
|
+
schematizer netlist.json --tool kicad9 -o out --top-name mydesign --format svg
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Library use
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import json
|
|
81
|
+
from schematizer import render
|
|
82
|
+
|
|
83
|
+
with open("netlist.json") as f:
|
|
84
|
+
netlist = json.load(f)
|
|
85
|
+
|
|
86
|
+
render(netlist, tool="kicad9", filepath="out", top_name="mydesign")
|
|
87
|
+
render(netlist, tool="kicad9", filepath="out", format="svg")
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`render()` also accepts a path to the JSON file directly.
|
|
91
|
+
|
|
92
|
+
## How it fits with SKiDL
|
|
93
|
+
|
|
94
|
+
To the SKiDL end user nothing changes: `Circuit.generate_schematic()` and
|
|
95
|
+
`Circuit.generate_svg()` build the generic netlist internally and call `render()`
|
|
96
|
+
here (with `format="kicad"` and `format="svg"` respectively). Because the seam is a
|
|
97
|
+
plain JSON document, `schematizer` can be iterated and improved independently of
|
|
98
|
+
SKiDL — and reused by any other front end that emits the same format.
|
|
99
|
+
|
|
100
|
+
## Status
|
|
101
|
+
|
|
102
|
+
**Self-contained.** The placement/routing/writer engine is vendored under
|
|
103
|
+
`schematizer/engine`, and the netlist is reconstructed into a lightweight
|
|
104
|
+
intermediate representation (`schematizer.ir`: `SchPart`/`SchPin`/`SchNet`) that
|
|
105
|
+
the engine consumes directly — no `.kicad_sym` re-parse, no KiCad library
|
|
106
|
+
access, and **no runtime dependency on skidl**. The only runtime dependency is
|
|
107
|
+
`simp_sexp`. The KiCad power-symbol library (for `GND`/rail nets) is vendored in
|
|
108
|
+
`schematizer/data`.
|
|
109
|
+
|
|
110
|
+
## Output formats
|
|
111
|
+
|
|
112
|
+
`--format kicad` (the default) writes editable `.kicad_sch` files.
|
|
113
|
+
`--format svg` writes static `.svg` pages instead:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
schematizer netlist.json --tool kicad9 --format svg -o out
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Both come off the same placement and routing pass and differ only in the final
|
|
120
|
+
serialization, so an SVG page has the layout of the `.kicad_sch` it would have
|
|
121
|
+
produced. Symbols are drawn from the graphics embedded in the netlist, so SVG
|
|
122
|
+
output needs no KiCad libraries either.
|
|
123
|
+
|
|
124
|
+
`--flatness` controls hierarchy for both formats. At `0.0` (the default) every
|
|
125
|
+
subcircuit gets its own page; in the SVG output a child appears on its parent's
|
|
126
|
+
page as a **hyperlinked rectangle**, and each child page carries links back to
|
|
127
|
+
its parent and to the top sheet, so a hierarchical design can be clicked
|
|
128
|
+
through in a browser. At `1.0` everything collapses onto one page, and values
|
|
129
|
+
in between flatten only the smaller subcircuits.
|
|
130
|
+
|
|
131
|
+
Each SVG page is sized to its drawing rather than to an A-size sheet, since an
|
|
132
|
+
SVG renders at whatever size it declares.
|
|
133
|
+
|
|
134
|
+
## Randomized layout
|
|
135
|
+
|
|
136
|
+
Placement starts parts at random positions and the router breaks ties randomly,
|
|
137
|
+
so the same netlist produces a different — equally valid — drawing on every
|
|
138
|
+
run. There is no way to pin a layout down: if you get one you want to keep,
|
|
139
|
+
keep the generated files.
|
|
140
|
+
|
|
141
|
+
## Supported KiCad versions
|
|
142
|
+
|
|
143
|
+
`--tool` accepts `kicad6` … `kicad10`, which share one modern S-expression
|
|
144
|
+
writer (with a couple of KiCad-8 format toggles). The version still matters for
|
|
145
|
+
`--format svg`, because the embedded symbol graphics are KiCad-version flavored.
|
|
146
|
+
|
|
147
|
+
KiCad 5 is **not** supported and is rejected with an explanatory error. It
|
|
148
|
+
needs the legacy EESCHEMA `.sch` format rather than `.kicad_sch`, and KiCad 5
|
|
149
|
+
libraries describe symbols in a different, non-s-expression form that the
|
|
150
|
+
generic netlist does not carry.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+

|
|
2
|
+

|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
# schematizer
|
|
11
|
+
|
|
12
|
+
Turn a **generic, hierarchical netlist** (JSON) into a KiCad schematic or an SVG drawing of one.
|
|
13
|
+
|
|
14
|
+
`schematizer` does the *graphical* half of EDA: it takes a tool-neutral netlist
|
|
15
|
+
document and does all the drawing work — component placement, wire routing, and
|
|
16
|
+
writing either editable `.kicad_sch` files or static, cross-linked `.svg` pages
|
|
17
|
+
for a selected KiCad version (6–10). It is not tied to any particular front end: **any** tool that emits the netlist format can use
|
|
18
|
+
it. [SKiDL](https://github.com/devbisme/skidl) is the first such producer —
|
|
19
|
+
SKiDL describes electrical interconnection in code and hands the netlist to
|
|
20
|
+
`schematizer` — but the input is just JSON, so other generators work too.
|
|
21
|
+
|
|
22
|
+
The netlist document (produced by
|
|
23
|
+
`skidl.schematic_netlist.build_generic_netlist`, or any equivalent emitter)
|
|
24
|
+
embeds each component's symbol definition and carries layout *hints* —
|
|
25
|
+
component mirror/rotate (`symtx`) and net stubbing (`stub`/`netio`). Because
|
|
26
|
+
symbols are embedded, this tool needs **no access to KiCad symbol libraries**.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install schematizer
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Command-line use
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# netlist.json -> KiCad 9 schematic files in ./out/
|
|
38
|
+
schematizer netlist.json --tool kicad9 -o out --top-name mydesign
|
|
39
|
+
|
|
40
|
+
# ...or a set of linked SVG pages instead
|
|
41
|
+
schematizer netlist.json --tool kicad9 -o out --top-name mydesign --format svg
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Library use
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import json
|
|
48
|
+
from schematizer import render
|
|
49
|
+
|
|
50
|
+
with open("netlist.json") as f:
|
|
51
|
+
netlist = json.load(f)
|
|
52
|
+
|
|
53
|
+
render(netlist, tool="kicad9", filepath="out", top_name="mydesign")
|
|
54
|
+
render(netlist, tool="kicad9", filepath="out", format="svg")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`render()` also accepts a path to the JSON file directly.
|
|
58
|
+
|
|
59
|
+
## How it fits with SKiDL
|
|
60
|
+
|
|
61
|
+
To the SKiDL end user nothing changes: `Circuit.generate_schematic()` and
|
|
62
|
+
`Circuit.generate_svg()` build the generic netlist internally and call `render()`
|
|
63
|
+
here (with `format="kicad"` and `format="svg"` respectively). Because the seam is a
|
|
64
|
+
plain JSON document, `schematizer` can be iterated and improved independently of
|
|
65
|
+
SKiDL — and reused by any other front end that emits the same format.
|
|
66
|
+
|
|
67
|
+
## Status
|
|
68
|
+
|
|
69
|
+
**Self-contained.** The placement/routing/writer engine is vendored under
|
|
70
|
+
`schematizer/engine`, and the netlist is reconstructed into a lightweight
|
|
71
|
+
intermediate representation (`schematizer.ir`: `SchPart`/`SchPin`/`SchNet`) that
|
|
72
|
+
the engine consumes directly — no `.kicad_sym` re-parse, no KiCad library
|
|
73
|
+
access, and **no runtime dependency on skidl**. The only runtime dependency is
|
|
74
|
+
`simp_sexp`. The KiCad power-symbol library (for `GND`/rail nets) is vendored in
|
|
75
|
+
`schematizer/data`.
|
|
76
|
+
|
|
77
|
+
## Output formats
|
|
78
|
+
|
|
79
|
+
`--format kicad` (the default) writes editable `.kicad_sch` files.
|
|
80
|
+
`--format svg` writes static `.svg` pages instead:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
schematizer netlist.json --tool kicad9 --format svg -o out
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Both come off the same placement and routing pass and differ only in the final
|
|
87
|
+
serialization, so an SVG page has the layout of the `.kicad_sch` it would have
|
|
88
|
+
produced. Symbols are drawn from the graphics embedded in the netlist, so SVG
|
|
89
|
+
output needs no KiCad libraries either.
|
|
90
|
+
|
|
91
|
+
`--flatness` controls hierarchy for both formats. At `0.0` (the default) every
|
|
92
|
+
subcircuit gets its own page; in the SVG output a child appears on its parent's
|
|
93
|
+
page as a **hyperlinked rectangle**, and each child page carries links back to
|
|
94
|
+
its parent and to the top sheet, so a hierarchical design can be clicked
|
|
95
|
+
through in a browser. At `1.0` everything collapses onto one page, and values
|
|
96
|
+
in between flatten only the smaller subcircuits.
|
|
97
|
+
|
|
98
|
+
Each SVG page is sized to its drawing rather than to an A-size sheet, since an
|
|
99
|
+
SVG renders at whatever size it declares.
|
|
100
|
+
|
|
101
|
+
## Randomized layout
|
|
102
|
+
|
|
103
|
+
Placement starts parts at random positions and the router breaks ties randomly,
|
|
104
|
+
so the same netlist produces a different — equally valid — drawing on every
|
|
105
|
+
run. There is no way to pin a layout down: if you get one you want to keep,
|
|
106
|
+
keep the generated files.
|
|
107
|
+
|
|
108
|
+
## Supported KiCad versions
|
|
109
|
+
|
|
110
|
+
`--tool` accepts `kicad6` … `kicad10`, which share one modern S-expression
|
|
111
|
+
writer (with a couple of KiCad-8 format toggles). The version still matters for
|
|
112
|
+
`--format svg`, because the embedded symbol graphics are KiCad-version flavored.
|
|
113
|
+
|
|
114
|
+
KiCad 5 is **not** supported and is rejected with an explanatory error. It
|
|
115
|
+
needs the legacy EESCHEMA `.sch` format rather than `.kicad_sch`, and KiCad 5
|
|
116
|
+
libraries describe symbols in a different, non-s-expression form that the
|
|
117
|
+
generic netlist does not carry.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "schematizer"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Turn a generic hierarchical netlist (JSON) into a KiCad schematic."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Dave Vandenbout", email = "dave@vdb.name" }]
|
|
13
|
+
keywords = ["KiCad", "schematic", "netlist", "EDA", "SKiDL"]
|
|
14
|
+
# The Python-version classifiers feed the README's PyPI "pyversions" badge;
|
|
15
|
+
# keep them in step with requires-python and the tox env_list.
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Intended Audience :: Science/Research",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
24
|
+
"Programming Language :: Python :: 3.8",
|
|
25
|
+
"Programming Language :: Python :: 3.9",
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Programming Language :: Python :: 3.13",
|
|
30
|
+
"Programming Language :: Python :: 3.14",
|
|
31
|
+
"Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
# The placement/routing/writer engine and a lightweight IR are vendored under
|
|
35
|
+
# src/schematizer/engine, so the package is independent of skidl at runtime.
|
|
36
|
+
# Its only runtime dependency is the S-expression reader/writer.
|
|
37
|
+
dependencies = [
|
|
38
|
+
"simp_sexp",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.optional-dependencies]
|
|
42
|
+
test = ["pytest"]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/devbisme/schematizer"
|
|
46
|
+
Repository = "https://github.com/devbisme/schematizer"
|
|
47
|
+
Issues = "https://github.com/devbisme/schematizer/issues"
|
|
48
|
+
|
|
49
|
+
[project.scripts]
|
|
50
|
+
schematizer = "schematizer.cli:main"
|
|
51
|
+
|
|
52
|
+
[tool.setuptools.packages.find]
|
|
53
|
+
where = ["src"]
|
|
54
|
+
|
|
55
|
+
[tool.setuptools.package-data]
|
|
56
|
+
# The vendored KiCad power-symbol library (GND, +3V3, …) used when a net name
|
|
57
|
+
# matches a power symbol. Keeps the tool self-contained.
|
|
58
|
+
schematizer = ["data/*.kicad_sym"]
|
|
59
|
+
|
|
60
|
+
[tool.black]
|
|
61
|
+
line-length = 88
|
|
62
|
+
|
|
63
|
+
# Run the test suite against each supported Python with `tox` (or one with
|
|
64
|
+
# `tox -e py312`). Interpreters come from the global pyenv setting, which puts
|
|
65
|
+
# python3.8 … python3.14 on PATH so tox can find them.
|
|
66
|
+
[tool.tox]
|
|
67
|
+
requires = ["tox>=4.21"]
|
|
68
|
+
env_list = ["py38", "py39", "py310", "py311", "py312", "py313", "py314"]
|
|
69
|
+
skip_missing_interpreters = true
|
|
70
|
+
|
|
71
|
+
[tool.tox.env_run_base]
|
|
72
|
+
description = "run the test suite with {base_python}"
|
|
73
|
+
extras = ["test"]
|
|
74
|
+
# Use the local skidl checkout (editable) instead of the PyPI release.
|
|
75
|
+
deps = ["-e {tox_root}/../skidl"]
|
|
76
|
+
# deps = ["skidl"]
|
|
77
|
+
set_env = { SKIDL_TOOL = "KICAD9" }
|
|
78
|
+
commands = [["pytest", { replace = "posargs", default = ["tests"], extend = true }]]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# The MIT License (MIT) - Copyright (c) Dave Vandenbout.
|
|
4
|
+
|
|
5
|
+
"""schematizer: generic JSON netlist -> KiCad schematic."""
|
|
6
|
+
|
|
7
|
+
# Defined before importing render so the vendored engine (which does
|
|
8
|
+
# ``from .. import __version__`` at import time) can see it.
|
|
9
|
+
__version__ = "0.2.0"
|
|
10
|
+
|
|
11
|
+
from .render import render # noqa: E402
|
|
12
|
+
|
|
13
|
+
# Part of render()'s contract: the exceptions the engine raises when placement
|
|
14
|
+
# or routing can't complete. Exported so callers (e.g. SKiDL) can catch them.
|
|
15
|
+
from .engine.place import PlacementFailure # noqa: E402
|
|
16
|
+
from .engine.route import RoutingFailure # noqa: E402
|
|
17
|
+
|
|
18
|
+
__all__ = ["render", "PlacementFailure", "RoutingFailure", "__version__"]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# The MIT License (MIT) - Copyright (c) Dave Vandenbout.
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Minimal, skidl-free utility surface used by the vendored schematic engine.
|
|
7
|
+
|
|
8
|
+
The engine originally pulled a few helpers from ``skidl.utilities``,
|
|
9
|
+
``skidl.logger`` and ``skidl.scriptinfo``. Only a small, stable subset is
|
|
10
|
+
actually used; it is reproduced here so the package does not depend on skidl.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import logging
|
|
14
|
+
import os
|
|
15
|
+
import sys
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"export_to_all",
|
|
19
|
+
"rmv_attr",
|
|
20
|
+
"sgn",
|
|
21
|
+
"get_script_name",
|
|
22
|
+
"active_logger",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def export_to_all(fn):
|
|
27
|
+
"""Append ``fn.__name__`` to its module's ``__all__`` (decorator, no-op else).
|
|
28
|
+
|
|
29
|
+
Same behavior as ``skidl.utilities.export_to_all``: it lets a module opt a
|
|
30
|
+
name into ``from module import *`` and otherwise returns the function
|
|
31
|
+
unchanged.
|
|
32
|
+
"""
|
|
33
|
+
mod = sys.modules[fn.__module__]
|
|
34
|
+
if hasattr(mod, "__all__"):
|
|
35
|
+
mod.__all__.append(fn.__name__)
|
|
36
|
+
else:
|
|
37
|
+
mod.__all__ = [fn.__name__]
|
|
38
|
+
return fn
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _to_list(x):
|
|
42
|
+
"""Return ``x`` as a list; wrap scalars, pass sequences through."""
|
|
43
|
+
if isinstance(x, (list, tuple, set)):
|
|
44
|
+
return list(x)
|
|
45
|
+
return [x]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def rmv_attr(objs, attrs):
|
|
49
|
+
"""Remove one or more attributes from one or more objects (ignore missing)."""
|
|
50
|
+
for o in _to_list(objs):
|
|
51
|
+
for a in _to_list(attrs):
|
|
52
|
+
try:
|
|
53
|
+
delattr(o, a)
|
|
54
|
+
except AttributeError:
|
|
55
|
+
pass
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def sgn(x):
|
|
59
|
+
"""Return the sign of a number as -1, 0, or +1."""
|
|
60
|
+
return (x > 0) - (x < 0)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def get_script_name():
|
|
64
|
+
"""Return the top-level script name without extension.
|
|
65
|
+
|
|
66
|
+
Used only as the default ``top_name`` for schematic output; callers
|
|
67
|
+
(``render``/CLI) normally pass an explicit name.
|
|
68
|
+
"""
|
|
69
|
+
try:
|
|
70
|
+
name = os.path.basename(sys.argv[0]) if sys.argv and sys.argv[0] else ""
|
|
71
|
+
except Exception:
|
|
72
|
+
name = ""
|
|
73
|
+
return os.path.splitext(name)[0] or "schematic"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# A plain stdlib logger stands in for skidl's ``active_logger``. The engine only
|
|
77
|
+
# calls ``.info`` / ``.warning`` on it.
|
|
78
|
+
active_logger = logging.getLogger("schematizer")
|
|
79
|
+
if not active_logger.handlers:
|
|
80
|
+
active_logger.addHandler(logging.NullHandler())
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# The MIT License (MIT) - Copyright (c) Dave Vandenbout.
|
|
4
|
+
|
|
5
|
+
"""Command-line interface: generic netlist JSON -> schematic files."""
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from . import __version__
|
|
11
|
+
from .render import SUPPORTED_FORMATS, SUPPORTED_TOOLS, render
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def build_parser():
|
|
15
|
+
parser = argparse.ArgumentParser(
|
|
16
|
+
prog="schematizer",
|
|
17
|
+
description="Generate KiCad schematic or SVG files from a generic "
|
|
18
|
+
"hierarchical netlist (JSON).",
|
|
19
|
+
)
|
|
20
|
+
parser.add_argument(
|
|
21
|
+
"netlist",
|
|
22
|
+
help="Path to the generic netlist JSON file.",
|
|
23
|
+
)
|
|
24
|
+
parser.add_argument(
|
|
25
|
+
"-t",
|
|
26
|
+
"--tool",
|
|
27
|
+
default="kicad9",
|
|
28
|
+
choices=SUPPORTED_TOOLS,
|
|
29
|
+
help="Target KiCad version (default: kicad9).",
|
|
30
|
+
)
|
|
31
|
+
parser.add_argument(
|
|
32
|
+
"-f",
|
|
33
|
+
"--format",
|
|
34
|
+
default="kicad",
|
|
35
|
+
choices=SUPPORTED_FORMATS,
|
|
36
|
+
help="Output format: editable .kicad_sch files, or static "
|
|
37
|
+
"cross-linked .svg pages (default: kicad).",
|
|
38
|
+
)
|
|
39
|
+
parser.add_argument(
|
|
40
|
+
"-o",
|
|
41
|
+
"--output",
|
|
42
|
+
default=".",
|
|
43
|
+
help="Output directory for the generated files (default: .).",
|
|
44
|
+
)
|
|
45
|
+
parser.add_argument(
|
|
46
|
+
"--top-name",
|
|
47
|
+
default=None,
|
|
48
|
+
help="Base name for output files (default: from the netlist).",
|
|
49
|
+
)
|
|
50
|
+
parser.add_argument(
|
|
51
|
+
"--title",
|
|
52
|
+
default="SKiDL-Generated Schematic",
|
|
53
|
+
help="Schematic title-block text.",
|
|
54
|
+
)
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
"--flatness",
|
|
57
|
+
type=float,
|
|
58
|
+
default=0.0,
|
|
59
|
+
help="Hierarchy flattening, 0.0 (fully hierarchical, one file per "
|
|
60
|
+
"sheet) .. 1.0 (everything on one sheet).",
|
|
61
|
+
)
|
|
62
|
+
parser.add_argument(
|
|
63
|
+
"--version",
|
|
64
|
+
action="version",
|
|
65
|
+
version=f"%(prog)s {__version__}",
|
|
66
|
+
)
|
|
67
|
+
return parser
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def main(argv=None):
|
|
71
|
+
args = build_parser().parse_args(argv)
|
|
72
|
+
try:
|
|
73
|
+
out = render(
|
|
74
|
+
args.netlist,
|
|
75
|
+
tool=args.tool,
|
|
76
|
+
filepath=args.output,
|
|
77
|
+
top_name=args.top_name,
|
|
78
|
+
title=args.title,
|
|
79
|
+
format=args.format,
|
|
80
|
+
flatness=args.flatness,
|
|
81
|
+
)
|
|
82
|
+
except (ValueError, TypeError, FileNotFoundError) as e:
|
|
83
|
+
print(f"schematizer: error: {e}", file=sys.stderr)
|
|
84
|
+
return 1
|
|
85
|
+
print(f"Wrote {args.format} files to {out}")
|
|
86
|
+
return 0
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if __name__ == "__main__":
|
|
90
|
+
sys.exit(main())
|