Use constant identifiers instead of repeating literals

Co-authored-by: kvid <kvid@users.noreply.github.com>
This commit is contained in:
Daniel Rojas 2021-08-29 11:02:14 +02:00 committed by GitHub
parent 7bd52b77e4
commit 2e56f82988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 11 deletions

View File

@ -125,8 +125,8 @@ class Harness:
rows = [[remove_links(connector.name) if connector.show_name else None],
[f'P/N: {remove_links(connector.pn)}' if connector.pn else None,
html_line_breaks(pn_info_string("mpn", connector.manufacturer, connector.mpn)),
html_line_breaks(pn_info_string("spn", connector.supplier, connector.spn))],
html_line_breaks(pn_info_string(HDR_MPN, connector.manufacturer, connector.mpn)),
html_line_breaks(pn_info_string(HDR_SPN, connector.supplier, connector.spn))],
[html_line_breaks(connector.type),
html_line_breaks(connector.subtype),
f'{connector.pincount}-pin' if connector.show_pincount else None,
@ -209,10 +209,10 @@ class Harness:
rows = [[remove_links(cable.name) if cable.show_name else None],
[f'P/N: {remove_links(cable.pn)}' if (cable.pn and not isinstance(cable.pn, list)) else None,
html_line_breaks(pn_info_string("mpn",
html_line_breaks(pn_info_string(HDR_MPN,
cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
cable.mpn if not isinstance(cable.mpn, list) else None)),
html_line_breaks(pn_info_string("spn",
html_line_breaks(pn_info_string(HDR_SPN,
cable.supplier if not isinstance(cable.supplier, list) else None,
cable.spn if not isinstance(cable.spn, list) else None))],
[html_line_breaks(cable.type),
@ -267,10 +267,10 @@ class Harness:
wireidentification = []
if isinstance(cable.pn, list):
wireidentification.append(f'P/N: {remove_links(cable.pn[i - 1])}')
manufacturer_info = pn_info_string("mpn",
manufacturer_info = pn_info_string(HDR_MPN,
cable.manufacturer[i - 1] if isinstance(cable.manufacturer, list) else None,
cable.mpn[i - 1] if isinstance(cable.mpn, list) else None)
supplier_info = pn_info_string("spn",
supplier_info = pn_info_string(HDR_SPN,
cable.supplier[i - 1] if isinstance(cable.supplier, list) else None,
cable.spn[i - 1] if isinstance(cable.spn, list) else None)
if manufacturer_info:

View File

@ -144,8 +144,8 @@ def bom_list(bom: List[BOMEntry]) -> List[List[str]]:
# Headers not specified here are generated by capitilising the internal name.
bom_headings = {
"pn": "P/N",
"mpn": "MPN",
"spn": "SPN"
"mpn": HDR_MPN,
"spn": HDR_SPN,
}
return ([[bom_headings.get(k, k.capitalize()) for k in keys]] + # Create header row with key names
[[make_str(entry.get(k)) for k in keys] for entry in bom]) # Create string list for each entry row
@ -161,9 +161,11 @@ def component_table_entry(
spn: Optional[str] = None,
) -> str:
"""Return a diagram node table row string with an additional component."""
manufacturer_str = pn_info_string("mpn", manufacturer, mpn)
supplier_str = pn_info_string("spn", supplier, spn)
part_number_list = [pn, manufacturer_str, supplier_str]
part_number_list = [
pn,
pn_info_string(HDR_MPN, manufacturer, mpn),
pn_info_string(HDR_SPN, supplier, spn),
]
output = (f'{qty}'
+ (f' {unit}' if unit else '')
+ f' x {type}'