Skip to content

Commit cf2db16

Browse files
committed
Move generic functions to wv_helper.py
1 parent 0e84768 commit cf2db16

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/wireviz/wv_bom.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from wireviz.DataClasses import Connector, Cable
88
from wireviz.wv_gv_html import html_line_breaks
9+
from wireviz.wv_helper import clean_whitespace
910

1011
def get_additional_component_table(harness, component: Union[Connector, Cable]) -> List[str]:
1112
rows = []
@@ -172,9 +173,6 @@ def manufacturer_info_field(manufacturer, mpn):
172173
else:
173174
return None
174175

175-
def clean_whitespace(inp):
176-
return ' '.join(inp.split()).replace(' ,', ',') if isinstance(inp, str) else inp
177-
178176
# Return the value indexed if it is a list, or simply the value otherwise.
179177
def index_if_list(value, index):
180178
return value[index] if isinstance(value, list) else value

src/wireviz/wv_gv_html.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66

77
from wireviz.wv_colors import translate_color
8+
from wireviz.wv_helper import remove_links
89

910
def nested_html_table(rows):
1011
# input: list, each item may be scalar or list
@@ -61,8 +62,5 @@ def html_size_attr(image):
6162
+ (f' height="{image.height}"' if image.height else '')
6263
+ ( ' fixedsize="true"' if image.fixedsize else '')) if image else ''
6364

64-
def remove_links(inp):
65-
return re.sub(r'<[aA] [^>]*>([^<]*)</[aA]>', r'\1', inp) if isinstance(inp, str) else inp
66-
6765
def html_line_breaks(inp):
6866
return remove_links(inp).replace('\n', '<br />') if isinstance(inp, str) else inp

src/wireviz/wv_helper.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from typing import List
55
import re
66

7-
from wireviz.wv_gv_html import remove_links
8-
97
awg_equiv_table = {
108
'0.09': '28',
119
'0.14': '26',
@@ -89,6 +87,15 @@ def tuplelist2tsv(inp, header=None):
8987
output = output + '\t'.join(str(remove_links(item)) for item in row) + '\n'
9088
return output
9189

90+
91+
def remove_links(inp):
92+
return re.sub(r'<[aA] [^>]*>([^<]*)</[aA]>', r'\1', inp) if isinstance(inp, str) else inp
93+
94+
95+
def clean_whitespace(inp):
96+
return ' '.join(inp.split()).replace(' ,', ',') if isinstance(inp, str) else inp
97+
98+
9299
def open_file_read(filename):
93100
# TODO: Intelligently determine encoding
94101
return open(filename, 'r', encoding='UTF-8')

0 commit comments

Comments
 (0)