Skip to content

Commit 536c5e5

Browse files
make a test and main
1 parent 57c3557 commit 536c5e5

File tree

7 files changed

+36
-6
lines changed

7 files changed

+36
-6
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ requires-python = ">=3.10"
2525
[project.urls]
2626
Homepage = "https://github.com/dragoncoder047/schemascii"
2727

28-
# [project.scripts]
29-
# schemascii = "schemascii.__init__:cli_main"
28+
[project.scripts]
29+
schemascii = "schemascii.__main__:cli_main"

schemascii/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ def render(filename: str, text: str = None, **options) -> str:
4343

4444
if __name__ == '__main__':
4545
print(render(
46-
"../test_data/test_resistors.txt",
46+
"test_data/test_resistors.txt",
4747
scale=20, padding=20, stroke_width=2,
4848
stroke="black"))

schemascii/__main__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import argparse
2+
import sys
3+
from . import render, __version__
4+
5+
6+
def cli_main():
7+
ap = argparse.ArgumentParser(
8+
prog="schemascii",
9+
description="Render ASCII-art schematics into SVG.")
10+
ap.add_argument("in_file",
11+
help="File to process.")
12+
ap.add_argument("-o", "--out",
13+
default=None,
14+
dest="out_file",
15+
help="Output SVG file. (default input file plus .svg)")
16+
args = ap.parse_args()
17+
if args.out_file is None:
18+
args.out_file = args.in_file + ".svg"
19+
try:
20+
result_svg = render(args.in_file)
21+
except Exception as e:
22+
print("error:", e, file=sys.stderr)
23+
sys.exit(1)
24+
with open(args.out_file, "w", encoding="utf-8") as out:
25+
out.write(result_svg)
26+
27+
28+
if __name__ == '__main__':
29+
cli_main()

schemascii/components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def find_all(grid: Grid) -> tuple[list[Cbox], list[BOMData]]:
9595

9696

9797
if __name__ == '__main__':
98-
grid = Grid("../test_data/test_resistors.txt")
98+
grid = Grid("test_data/test_resistors.txt")
9999
bbb, _ = find_all(grid)
100100
all_pts = []
101101
for box in bbb:

schemascii/components_render.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def render_component(
262262
"Render the component into an SVG string."
263263
if box.type not in RENDERERS:
264264
raise NameError(
265-
f"No renderer defined for {box.type} component")
265+
f"Unsupported component type: {box.type}")
266266
return XML.g(
267267
RENDERERS[box.type](box, terminals, bom_data, **kwargs),
268268
class_=f"component {box.type}"

schemascii/wires.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,6 @@ def get_wires(grid: Grid, **options) -> str:
137137

138138

139139
if __name__ == '__main__':
140-
xg = Grid('../test_data/test_resistors.txt')
140+
xg = Grid('test_data/test_resistors.txt')
141141
print(get_wires(xg, scale=20))
142142
print(xg)

test_data/test_resistors.txt.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)