From 2d5a3c6e3816be88e351dcf48682e9ff0b9c8cb0 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Fri, 27 Aug 2021 18:31:45 +0200 Subject: [PATCH 01/11] Add `supplier` and `spn` fields --- src/wireviz/DataClasses.py | 8 +++++++- src/wireviz/Harness.py | 13 +++++++++++-- src/wireviz/wv_bom.py | 15 +++++++++------ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index e80437b2..39416092 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -101,6 +101,8 @@ class AdditionalComponent: subtype: Optional[MultilineHypertext] = None manufacturer: Optional[MultilineHypertext] = None mpn: Optional[MultilineHypertext] = None + supplier: Optional[MultilineHypertext] = None + spn: Optional[MultilineHypertext] = None pn: Optional[Hypertext] = None qty: float = 1 unit: Optional[str] = None @@ -116,6 +118,8 @@ class Connector: name: Designator manufacturer: Optional[MultilineHypertext] = None mpn: Optional[MultilineHypertext] = None + supplier: Optional[MultilineHypertext] = None + spn: Optional[MultilineHypertext] = None pn: Optional[Hypertext] = None style: Optional[str] = None category: Optional[str] = None @@ -198,6 +202,8 @@ class Cable: name: Designator manufacturer: Union[MultilineHypertext, List[MultilineHypertext], None] = None mpn: Union[MultilineHypertext, List[MultilineHypertext], None] = None + supplier: Union[MultilineHypertext, List[MultilineHypertext], None] = None + spn: Union[MultilineHypertext, List[MultilineHypertext], None] = None pn: Union[Hypertext, List[Hypertext], None] = None category: Optional[str] = None type: Optional[MultilineHypertext] = None @@ -288,7 +294,7 @@ def __post_init__(self) -> None: raise Exception('"s" may not be used as a wire label for a shielded cable.') # if lists of part numbers are provided check this is a bundle and that it matches the wirecount. - for idfield in [self.manufacturer, self.mpn, self.pn]: + for idfield in [self.manufacturer, self.mpn, self.supplier, self.spn, self.pn]: if isinstance(idfield, list): if self.category == "bundle": # check the length diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 39180500..9de4cdc3 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -125,7 +125,8 @@ def create_graph(self) -> Graph: 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(manufacturer_info_field(connector.manufacturer, connector.mpn))], + html_line_breaks(manufacturer_info_field(connector.manufacturer, connector.mpn)), + html_line_breaks(manufacturer_info_field(connector.supplier, connector.spn))], [html_line_breaks(connector.type), html_line_breaks(connector.subtype), f'{connector.pincount}-pin' if connector.show_pincount else None, @@ -210,7 +211,10 @@ def create_graph(self) -> Graph: [f'P/N: {remove_links(cable.pn)}' if (cable.pn and not isinstance(cable.pn, list)) else None, html_line_breaks(manufacturer_info_field( cable.manufacturer if not isinstance(cable.manufacturer, list) else None, - cable.mpn if not isinstance(cable.mpn, list) else None))], + cable.mpn if not isinstance(cable.mpn, list) else None)), + html_line_breaks(manufacturer_info_field( + 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), f'{cable.wirecount}x' if cable.show_wirecount else None, f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else None, @@ -266,8 +270,13 @@ def create_graph(self) -> Graph: manufacturer_info = manufacturer_info_field( cable.manufacturer[i - 1] if isinstance(cable.manufacturer, list) else None, cable.mpn[i - 1] if isinstance(cable.mpn, list) else None) + supplier_info = manufacturer_info_field( + 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: wireidentification.append(html_line_breaks(manufacturer_info)) + if supplier_info: + wireidentification.append(html_line_breaks(supplier_info)) # print parameters into a table row under the wire if len(wireidentification) > 0 : wirehtml.append(' ') diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index 76ba4a1d..b1ae99d8 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -11,7 +11,7 @@ from wireviz.wv_helper import clean_whitespace BOM_COLUMNS_ALWAYS = ('id', 'description', 'qty', 'unit', 'designators') -BOM_COLUMNS_OPTIONAL = ('pn', 'manufacturer', 'mpn') +BOM_COLUMNS_OPTIONAL = ('pn', 'manufacturer', 'mpn', 'supplier', 'spn') BOM_COLUMNS_IN_KEY = ('description', 'unit') + BOM_COLUMNS_OPTIONAL BOMKey = Tuple[str, ...] @@ -144,7 +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" + "mpn": "MPN", + "spn": "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 @@ -156,16 +157,18 @@ def component_table_entry( pn: Optional[str] = None, manufacturer: Optional[str] = None, mpn: Optional[str] = None, + supplier: Optional[str] = None, + spn: Optional[str] = None, ) -> str: """Return a diagram node table row string with an additional component.""" manufacturer_str = manufacturer_info_field(manufacturer, mpn) + supplier_str = manufacturer_info_field(supplier, spn) + part_number_list = [pn, manufacturer_str, supplier_str] output = (f'{qty}' + (f' {unit}' if unit else '') + f' x {type}' - + ('
' if pn or manufacturer_str else '') - + (f'P/N: {pn}' if pn else '') - + (', ' if pn and manufacturer_str else '') - + (manufacturer_str or '')) + + ('
' if any([part_number_list]) else '') + + (', '.join([x for x in part_number_list if x]))) # format the above output as left aligned text in a single visible cell # indent is set to two to match the indent in the generated html table return f''' From 0c1e7293dc0c8b7f6692cb54b4029ff5ad192fc9 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Fri, 27 Aug 2021 18:41:03 +0200 Subject: [PATCH 02/11] Update tutorial08 --- tutorial/tutorial08.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tutorial/tutorial08.yml b/tutorial/tutorial08.yml index 2dc55443..67ee7ce2 100644 --- a/tutorial/tutorial08.yml +++ b/tutorial/tutorial08.yml @@ -5,6 +5,8 @@ connectors: subtype: female manufacturer: 'Molex' # set manufacter name mpn: '22013047' # set manufacturer part number + supplier: Digimouse + spn: 1234 # add a list of additional components to a part (shown in graph) additional_components: - @@ -27,6 +29,8 @@ cables: color_code: IEC manufacturer: CablesCo mpn: ABC123 + supplier: Cables R Us + spn: 999-888-777 pn: CAB1 W2: category: bundle @@ -35,6 +39,8 @@ cables: colors: [YE, BK, BK, RD] manufacturer: [WiresCo,WiresCo,WiresCo,WiresCo] # set a manufacter per wire mpn: [W1-YE,W1-BK,W1-BK,W1-RD] + supplier: [WireShack,WireShack,WireShack,WireShack] + spn: [1001,1002,1002,1009] pn: [WIRE1,WIRE2,WIRE2,WIRE3] # add a list of additional components to a part (shown in graph) additional_components: From 6e59163cca69ca5504a4d2736d1df00461ee1d11 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Fri, 27 Aug 2021 18:52:36 +0200 Subject: [PATCH 03/11] generalize MPN/SPN string generation rename `manufacturer_info_field()` to `pn_info_string()` and add parameter to specify MPN or SPN --- src/wireviz/Harness.py | 14 +++++++------- src/wireviz/wv_bom.py | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 9de4cdc3..f1f3b433 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -14,7 +14,7 @@ from wireviz.wv_colors import get_color_hex, translate_color from wireviz.wv_gv_html import nested_html_table, html_colorbar, html_image, \ html_caption, remove_links, html_line_breaks -from wireviz.wv_bom import manufacturer_info_field, component_table_entry, \ +from wireviz.wv_bom import pn_info_string, component_table_entry, \ get_additional_component_table, bom_list, generate_bom from wireviz.wv_html import generate_html_output from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, flatten2d, \ @@ -125,8 +125,8 @@ def create_graph(self) -> Graph: 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(manufacturer_info_field(connector.manufacturer, connector.mpn)), - html_line_breaks(manufacturer_info_field(connector.supplier, connector.spn))], + 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(connector.type), html_line_breaks(connector.subtype), f'{connector.pincount}-pin' if connector.show_pincount else None, @@ -209,10 +209,10 @@ def create_graph(self) -> Graph: 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(manufacturer_info_field( + html_line_breaks(pn_info_string("mpn", cable.manufacturer if not isinstance(cable.manufacturer, list) else None, cable.mpn if not isinstance(cable.mpn, list) else None)), - html_line_breaks(manufacturer_info_field( + html_line_breaks(pn_info_string("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 @@ def create_graph(self) -> Graph: wireidentification = [] if isinstance(cable.pn, list): wireidentification.append(f'P/N: {remove_links(cable.pn[i - 1])}') - manufacturer_info = manufacturer_info_field( + manufacturer_info = pn_info_string("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 = manufacturer_info_field( + supplier_info = pn_info_string("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: diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index b1ae99d8..cc17c451 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -161,8 +161,8 @@ def component_table_entry( spn: Optional[str] = None, ) -> str: """Return a diagram node table row string with an additional component.""" - manufacturer_str = manufacturer_info_field(manufacturer, mpn) - supplier_str = manufacturer_info_field(supplier, spn) + manufacturer_str = pn_info_string("mpn", manufacturer, mpn) + supplier_str = pn_info_string("spn", supplier, spn) part_number_list = [pn, manufacturer_str, supplier_str] output = (f'{qty}' + (f' {unit}' if unit else '') @@ -175,10 +175,10 @@ def component_table_entry(
{html_line_breaks(output)}
''' -def manufacturer_info_field(manufacturer: Optional[str], mpn: Optional[str]) -> Optional[str]: - """Return the manufacturer and/or the mpn in one single string or None otherwise.""" - if manufacturer or mpn: - return f'{manufacturer if manufacturer else "MPN"}{": " + str(mpn) if mpn else ""}' +def pn_info_string(nametype: str, name: Optional[str], number: Optional[str]) -> Optional[str]: + """Return the company name and/or the part number in one single string or None otherwise.""" + if name or number: + return f'{name if name else nametype.upper()}{": " + str(number) if number else ""}' else: return None From f0b3789d9d56267c30cfb99133f1985ad38f3113 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Fri, 27 Aug 2021 19:03:06 +0200 Subject: [PATCH 04/11] Update `syntax.md` --- docs/syntax.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/syntax.md b/docs/syntax.md index 4a7a52ac..dae3071e 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -100,8 +100,10 @@ additional_bom_items: # custom items to add to BOM # product information (all optional) ignore_in_bom: # if set to true the connector is not added to the BOM pn: # [internal] part number - mpn: # manufacturer part number manufacturer: # manufacturer name + mpn: # manufacturer part number + supplier: # supplier name + spn: # supplier part number additional_components: # additional components - # additional component (see below) @@ -173,8 +175,10 @@ Since the auto-incremented and auto-assigned designator is not known to the user # product information (all optional) ignore_in_bom: # if set to true the cable or wires are not added to the BOM pn: # [internal] part number - mpn: # manufacturer part number manufacturer: # manufacturer name + mpn: # manufacturer part number + supplier: # supplier name + spn: # supplier part number additional_components: # additional components - # additional component (see below) @@ -309,8 +313,10 @@ Parts can be added to a connector or cable in the section ` pn: # [internal] part number - mpn: # manufacturer part number manufacturer: # manufacturer name + mpn: # manufacturer part number + supplier: # supplier name + spn: # supplier part number ``` Alternatively items can be added to just the BOM by putting them in the section `` above. @@ -323,8 +329,10 @@ Alternatively items can be added to just the BOM by putting them in the section unit: designators: pn: # [internal] part number - mpn: # manufacturer part number manufacturer: # manufacturer name + mpn: # manufacturer part number + supplier: # supplier name + spn: # supplier part number ``` ## Colors @@ -402,6 +410,8 @@ The following attributes accept multiline strings: - `notes` - `manufacturer` - `mpn` +- `supplier` +- `spn` - `image.caption` ### Method 1 From 7bd52b77e4a390c17b7ca80d79e2c8d1fb51728e Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Fri, 27 Aug 2021 19:20:13 +0200 Subject: [PATCH 05/11] Update tutorial08 --- tutorial/tutorial08.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tutorial/tutorial08.yml b/tutorial/tutorial08.yml index 67ee7ce2..1e5e4f20 100644 --- a/tutorial/tutorial08.yml +++ b/tutorial/tutorial08.yml @@ -1,3 +1,6 @@ +options: + mini_bom_mode: false + connectors: X1: &template1 # define a template for later use type: Molex KK 254 @@ -15,6 +18,14 @@ connectors: qty_multiplier: populated # multipier for quantity (number of populated pins) manufacturer: Molex # set manufacter name mpn: 08500030 # set manufacturer part number + - + type: Test + qty: 1 + pn: ABC + manufacturer: Molex + mpn: 45454 + supplier: Mousikey + spn: 9999 X2: <<: *template1 # reuse template pn: CON4 # set an internal part number for just this connector From 2e56f829889b9b35b88a3c5aa3909a9f0b42fb2f Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 29 Aug 2021 11:02:14 +0200 Subject: [PATCH 06/11] Use constant identifiers instead of repeating literals Co-authored-by: kvid --- src/wireviz/Harness.py | 12 ++++++------ src/wireviz/wv_bom.py | 12 +++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index f1f3b433..cbab7b51 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -125,8 +125,8 @@ def create_graph(self) -> Graph: 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 @@ def create_graph(self) -> Graph: 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 @@ def create_graph(self) -> Graph: 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: diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index cc17c451..e203145f 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -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}' From a30d26e6af34338a6fc412724ae555bd8f6366df Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 29 Aug 2021 11:02:49 +0200 Subject: [PATCH 07/11] Fix bug when checking for empty list Co-authored-by: kvid --- src/wireviz/wv_bom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index e203145f..aa77501c 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -169,7 +169,7 @@ def component_table_entry( output = (f'{qty}' + (f' {unit}' if unit else '') + f' x {type}' - + ('
' if any([part_number_list]) else '') + + ('
' if any(part_number_list) else '') + (', '.join([x for x in part_number_list if x]))) # format the above output as left aligned text in a single visible cell # indent is set to two to match the indent in the generated html table From 07a6360c16bc5f104f5e74fd0a135cdcfceef7da Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 29 Aug 2021 11:25:58 +0200 Subject: [PATCH 08/11] Rename `HDR_*` to `HEADER_*`, fix missing `P/N` string in output --- src/wireviz/Harness.py | 15 ++++++++------- src/wireviz/wv_bom.py | 16 ++++++++++------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index cbab7b51..bb7c329c 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -15,7 +15,8 @@ from wireviz.wv_gv_html import nested_html_table, html_colorbar, html_image, \ html_caption, remove_links, html_line_breaks from wireviz.wv_bom import pn_info_string, component_table_entry, \ - get_additional_component_table, bom_list, generate_bom + get_additional_component_table, bom_list, generate_bom, \ + HEADER_MPN, HEADER_SPN from wireviz.wv_html import generate_html_output from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, flatten2d, \ open_file_read, open_file_write @@ -125,8 +126,8 @@ def create_graph(self) -> Graph: 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(HDR_MPN, connector.manufacturer, connector.mpn)), - html_line_breaks(pn_info_string(HDR_SPN, connector.supplier, connector.spn))], + html_line_breaks(pn_info_string(HEADER_MPN, connector.manufacturer, connector.mpn)), + html_line_breaks(pn_info_string(HEADER_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 +210,10 @@ def create_graph(self) -> Graph: 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(HDR_MPN, + html_line_breaks(pn_info_string(HEADER_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(HDR_SPN, + html_line_breaks(pn_info_string(HEADER_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 +268,10 @@ def create_graph(self) -> Graph: wireidentification = [] if isinstance(cable.pn, list): wireidentification.append(f'P/N: {remove_links(cable.pn[i - 1])}') - manufacturer_info = pn_info_string(HDR_MPN, + manufacturer_info = pn_info_string(HEADER_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(HDR_SPN, + supplier_info = pn_info_string(HEADER_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: diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index aa77501c..0d24a584 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -14,6 +14,10 @@ BOM_COLUMNS_OPTIONAL = ('pn', 'manufacturer', 'mpn', 'supplier', 'spn') BOM_COLUMNS_IN_KEY = ('description', 'unit') + BOM_COLUMNS_OPTIONAL +HEADER_PN = 'P/N' +HEADER_MPN = 'MPN' +HEADER_SPN = 'SPN' + BOMKey = Tuple[str, ...] BOMColumn = str # = Literal[*BOM_COLUMNS_ALWAYS, *BOM_COLUMNS_OPTIONAL] BOMEntry = Dict[BOMColumn, Union[str, int, float, List[str], None]] @@ -143,9 +147,9 @@ def bom_list(bom: List[BOMEntry]) -> List[List[str]]: # Custom mapping from internal name to BOM column headers. # Headers not specified here are generated by capitilising the internal name. bom_headings = { - "pn": "P/N", - "mpn": HDR_MPN, - "spn": HDR_SPN, + "pn": HEADER_PN, + "mpn": HEADER_MPN, + "spn": HEADER_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 @@ -162,9 +166,9 @@ def component_table_entry( ) -> str: """Return a diagram node table row string with an additional component.""" part_number_list = [ - pn, - pn_info_string(HDR_MPN, manufacturer, mpn), - pn_info_string(HDR_SPN, supplier, spn), + pn_info_string(HEADER_PN, None, pn), + pn_info_string(HEADER_MPN, manufacturer, mpn), + pn_info_string(HEADER_SPN, supplier, spn), ] output = (f'{qty}' + (f' {unit}' if unit else '') From 893f24c88be06f1af6a718fdd193885117234279 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 29 Aug 2021 11:34:52 +0200 Subject: [PATCH 09/11] Homogenize code --- src/wireviz/Harness.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index bb7c329c..93d15f07 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -16,7 +16,7 @@ html_caption, remove_links, html_line_breaks from wireviz.wv_bom import pn_info_string, component_table_entry, \ get_additional_component_table, bom_list, generate_bom, \ - HEADER_MPN, HEADER_SPN + HEADER_PN, HEADER_MPN, HEADER_SPN from wireviz.wv_html import generate_html_output from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, flatten2d, \ open_file_read, open_file_write @@ -125,7 +125,7 @@ def create_graph(self) -> Graph: html = [] rows = [[remove_links(connector.name) if connector.show_name else None], - [f'P/N: {remove_links(connector.pn)}' if connector.pn else None, + [pn_info_string(HEADER_PN, None, remove_links(connector.pn)), html_line_breaks(pn_info_string(HEADER_MPN, connector.manufacturer, connector.mpn)), html_line_breaks(pn_info_string(HEADER_SPN, connector.supplier, connector.spn))], [html_line_breaks(connector.type), @@ -209,7 +209,8 @@ def create_graph(self) -> Graph: awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)' 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, + [pn_info_string(HEADER_PN, None, + remove_links(cable.pn)) if not isinstance(cable.pn, list) else None, html_line_breaks(pn_info_string(HEADER_MPN, cable.manufacturer if not isinstance(cable.manufacturer, list) else None, cable.mpn if not isinstance(cable.mpn, list) else None)), @@ -267,7 +268,7 @@ def create_graph(self) -> Graph: # create a list of wire parameters wireidentification = [] if isinstance(cable.pn, list): - wireidentification.append(f'P/N: {remove_links(cable.pn[i - 1])}') + wireidentification.append(pn_info_string(HEADER_PN, None, remove_links(cable.pn[i - 1]))) manufacturer_info = pn_info_string(HEADER_MPN, cable.manufacturer[i - 1] if isinstance(cable.manufacturer, list) else None, cable.mpn[i - 1] if isinstance(cable.mpn, list) else None) From cf98f2eb2e07b7b8532e88915c9be1fdfb5bba02 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 29 Aug 2021 11:40:36 +0200 Subject: [PATCH 10/11] Change double quotes to single quotes for consistency --- src/wireviz/wv_bom.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index 0d24a584..f2817860 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -147,9 +147,9 @@ def bom_list(bom: List[BOMEntry]) -> List[List[str]]: # Custom mapping from internal name to BOM column headers. # Headers not specified here are generated by capitilising the internal name. bom_headings = { - "pn": HEADER_PN, - "mpn": HEADER_MPN, - "spn": HEADER_SPN, + 'pn': HEADER_PN, + 'mpn': HEADER_MPN, + 'spn': HEADER_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 From 03a013febd1f523e7c01e0d619101c6d531880fd Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Wed, 8 Sep 2021 18:00:19 +0200 Subject: [PATCH 11/11] Add more suggestions --- src/wireviz/wv_bom.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index f2817860..bd7aedeb 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -174,17 +174,18 @@ def component_table_entry( + (f' {unit}' if unit else '') + f' x {type}' + ('
' if any(part_number_list) else '') - + (', '.join([x for x in part_number_list if x]))) + + (', '.join([pn for pn in part_number_list if pn]))) # format the above output as left aligned text in a single visible cell # indent is set to two to match the indent in the generated html table return f'''
{html_line_breaks(output)}
''' -def pn_info_string(nametype: str, name: Optional[str], number: Optional[str]) -> Optional[str]: +def pn_info_string(header: str, name: Optional[str], number: Optional[str]) -> Optional[str]: """Return the company name and/or the part number in one single string or None otherwise.""" + number = str(number).strip() if number is not None else '' if name or number: - return f'{name if name else nametype.upper()}{": " + str(number) if number else ""}' + return f'{name if name else header}{": " + number if number else ""}' else: return None