Skip to content

Commit 3bfd925

Browse files
formatter
1 parent 18178a7 commit 3bfd925

12 files changed

+521
-434
lines changed

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"tspan"
1111
],
1212
"python.linting.pylintEnabled": false,
13-
"python.linting.flake8Enabled": true,
13+
"python.linting.flake8Enabled": false,
1414
"python.linting.enabled": true
1515
}

schemascii/__init__.py

+28-20
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,44 @@ def render(filename: str, text: str = None, **options) -> str:
1919
# get everything
2020
grid = Grid(filename, text)
2121
# Passed-in options override diagram inline options
22-
options = apply_config_defaults(options
23-
| get_inline_configs(grid)
24-
| options.get("override_options", {}))
22+
options = apply_config_defaults(
23+
options | get_inline_configs(grid) | options.get("override_options", {})
24+
)
2525
components, bom_data = find_all(grid)
2626
terminals = {c: find_edge_marks(grid, c) for c in components}
27-
fixed_bom_data = {c: [b for b in bom_data if
28-
b.id == c.id and b.type == c.type]
29-
for c in components}
27+
fixed_bom_data = {
28+
c: [b for b in bom_data if b.id == c.id and b.type == c.type]
29+
for c in components
30+
}
3031
# get some options
31-
padding = options['padding']
32-
scale = options['scale']
32+
padding = options["padding"]
33+
scale = options["scale"]
3334

3435
wires = get_wires(grid, **options)
35-
components_strs = (render_component(
36-
c, terminals[c], fixed_bom_data[c], **options)
37-
for c in components)
36+
components_strs = (
37+
render_component(c, terminals[c], fixed_bom_data[c], **options)
38+
for c in components
39+
)
3840
return XML.svg(
39-
wires, *components_strs,
41+
wires,
42+
*components_strs,
4043
width=grid.width * scale + padding * 2,
4144
height=grid.height * scale + padding * 2,
42-
viewBox=f'{-padding} {-padding} '
43-
f'{grid.width * scale + padding * 2} '
44-
f'{grid.height * scale + padding * 2}',
45+
viewBox=f"{-padding} {-padding} "
46+
f"{grid.width * scale + padding * 2} "
47+
f"{grid.height * scale + padding * 2}",
4548
xmlns="http://www.w3.org/2000/svg",
4649
class_="schemascii",
4750
)
4851

4952

50-
if __name__ == '__main__':
51-
print(render(
52-
"test_data/test_resistors.txt",
53-
scale=20, padding=20, stroke_width=2,
54-
stroke="black"))
53+
if __name__ == "__main__":
54+
print(
55+
render(
56+
"test_data/test_resistors.txt",
57+
scale=20,
58+
padding=20,
59+
stroke_width=2,
60+
stroke="black",
61+
)
62+
)

schemascii/__main__.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88

99
def cli_main():
1010
ap = argparse.ArgumentParser(
11-
prog="schemascii",
12-
description="Render ASCII-art schematics into SVG.")
13-
ap.add_argument("-V", "--version",
14-
action="version",
15-
version="%(prog)s " + __version__)
16-
ap.add_argument("in_file",
17-
help="File to process.")
18-
ap.add_argument("-o", "--out",
19-
default=None,
20-
dest="out_file",
21-
help="Output SVG file. (default input file plus .svg)")
11+
prog="schemascii", description="Render ASCII-art schematics into SVG."
12+
)
13+
ap.add_argument(
14+
"-V", "--version", action="version", version="%(prog)s " + __version__
15+
)
16+
ap.add_argument("in_file", help="File to process.")
17+
ap.add_argument(
18+
"-o",
19+
"--out",
20+
default=None,
21+
dest="out_file",
22+
help="Output SVG file. (default input file plus .svg)",
23+
)
2224
add_config_arguments(ap)
2325
args = ap.parse_args()
2426
if args.out_file is None:
@@ -43,5 +45,5 @@ def cli_main():
4345
out.write(result_svg)
4446

4547

46-
if __name__ == '__main__':
48+
if __name__ == "__main__":
4749
cli_main()

schemascii/components.py

+31-25
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .errors import DiagramSyntaxError, BOMError
55

66

7-
SMALL_COMPONENT_OR_BOM = re.compile(r'#*([A-Z]+)(\d*|\.\w+)(:[^\s]+)?#*')
7+
SMALL_COMPONENT_OR_BOM = re.compile(r"#*([A-Z]+)(\d*|\.\w+)(:[^\s]+)?#*")
88

99

1010
def find_small(grid: Grid) -> tuple[list[Cbox], list[BOMData]]:
@@ -14,20 +14,24 @@ def find_small(grid: Grid) -> tuple[list[Cbox], list[BOMData]]:
1414
boms: list[BOMData] = []
1515
for i, line in enumerate(grid.lines):
1616
for m in SMALL_COMPONENT_OR_BOM.finditer(line):
17-
ident = m.group(2) or '0'
17+
ident = m.group(2) or "0"
1818
if m.group(3):
19-
boms.append(BOMData(m.group(1),
20-
ident, m.group(3)[1:]))
19+
boms.append(BOMData(m.group(1), ident, m.group(3)[1:]))
2120
else:
22-
components.append(Cbox(complex(m.start(), i),
23-
complex(m.end() - 1, i),
24-
m.group(1), ident))
21+
components.append(
22+
Cbox(
23+
complex(m.start(), i),
24+
complex(m.end() - 1, i),
25+
m.group(1),
26+
ident,
27+
)
28+
)
2529
for z in range(*m.span(0)):
2630
grid.setmask(complex(z, i))
2731
return components, boms
2832

2933

30-
TOP_OF_BOX = re.compile(r'\.~+\.')
34+
TOP_OF_BOX = re.compile(r"\.~+\.")
3135

3236

3337
def find_big(grid: Grid) -> tuple[list[Cbox], list[BOMData]]:
@@ -49,35 +53,37 @@ def find_big(grid: Grid) -> tuple[list[Cbox], list[BOMData]]:
4953
if cs == tb:
5054
y2 = j
5155
break
52-
if not cs[0] == cs[-1] == ':':
56+
if not cs[0] == cs[-1] == ":":
5357
raise DiagramSyntaxError(
54-
f'{grid.filename}: Fragmented box '
55-
f'starting at line {y1 + 1}, col {x1 + 1}')
58+
f"{grid.filename}: Fragmented box "
59+
f"starting at line {y1 + 1}, col {x1 + 1}"
60+
)
5661
else:
5762
raise DiagramSyntaxError(
58-
f'{grid.filename}: Unfinished box '
59-
f'starting at line {y1 + 1}, col {x1 + 1}')
63+
f"{grid.filename}: Unfinished box "
64+
f"starting at line {y1 + 1}, col {x1 + 1}"
65+
)
6066
inside = grid.clip(complex(x1, y1), complex(x2, y2))
6167
results, resb = find_small(inside)
6268
if len(results) == 0 and len(resb) == 0:
6369
raise BOMError(
64-
f'{grid.filename}: Box starting at '
65-
f'line {y1 + 1}, col {x1 + 1} is '
66-
f'missing reference designator')
70+
f"{grid.filename}: Box starting at "
71+
f"line {y1 + 1}, col {x1 + 1} is "
72+
f"missing reference designator"
73+
)
6774
if len(results) != 1 and len(resb) != 1:
6875
raise BOMError(
69-
f'{grid.filename}: Box starting at '
70-
f'line {y1 + 1}, col {x1 + 1} has '
71-
f'multiple reference designators')
76+
f"{grid.filename}: Box starting at "
77+
f"line {y1 + 1}, col {x1 + 1} has "
78+
f"multiple reference designators"
79+
)
7280
if not results:
7381
merd = resb[0]
7482
else:
7583
merd = results[0]
7684
boxes.append(
77-
Cbox(complex(x1, y1),
78-
complex(x2 - 1, y2),
79-
merd.type,
80-
merd.id))
85+
Cbox(complex(x1, y1), complex(x2 - 1, y2), merd.type, merd.id)
86+
)
8187
boms.extend(resb)
8288
# mark everything
8389
for i in range(x1, x2):
@@ -94,10 +100,10 @@ def find_all(grid: Grid) -> tuple[list[Cbox], list[BOMData]]:
94100
and masks off all of them, leaving only wires and extraneous text."""
95101
b1, l1 = find_big(grid)
96102
b2, l2 = find_small(grid)
97-
return b1+b2, l1+l2
103+
return b1 + b2, l1 + l2
98104

99105

100-
if __name__ == '__main__':
106+
if __name__ == "__main__":
101107
test_grid = Grid("test_data/test_resistors.txt")
102108
bbb, _ = find_all(test_grid)
103109
all_pts = []

0 commit comments

Comments
 (0)