44from .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
1010def 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
3337def 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