From 684f6f0064243057b56bfb399f5b946a517dc93d Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 5 May 2024 15:50:59 +0200 Subject: [PATCH] Apply `black` --- src/wireviz/DataClasses.py | 6 ++++-- src/wireviz/Harness.py | 27 ++++++++++++++++----------- src/wireviz/wireviz.py | 6 ++++-- src/wireviz/wv_bom.py | 12 ++++++++++-- src/wireviz/wv_html.py | 6 +++--- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 1756ef4..7f5f59b 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -212,7 +212,9 @@ class Connector: raise Exception("Loops must be between exactly two pins!") for pin in loop: if pin not in self.pins: - raise Exception(f'Unknown loop pin "{pin}" for connector "{self.name}"!') + raise Exception( + f'Unknown loop pin "{pin}" for connector "{self.name}"!' + ) # Make sure loop connected pins are not hidden. self.activate_pin(pin) @@ -234,7 +236,7 @@ class Connector: return self.pincount elif qty_multiplier == "populated": return sum(self.visible_pins.values()) - elif qty_multiplier == 'unpopulated': + elif qty_multiplier == "unpopulated": return max(0, self.pincount - sum(self.visible_pins.values())) else: raise ValueError( diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index da4f2bf..93100db 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -94,7 +94,7 @@ class Harness: to_pin: (int, str), ) -> None: # check from and to connectors - for (name, pin) in zip([from_name, to_name], [from_pin, to_pin]): + for name, pin in zip([from_name, to_name], [from_pin, to_pin]): if name is not None and name in self.connectors: connector = self.connectors[name] # check if provided name is ambiguous @@ -372,16 +372,20 @@ class Harness: ) manufacturer_info = pn_info_string( HEADER_MPN, - cable.manufacturer[i - 1] - if isinstance(cable.manufacturer, list) - else None, + ( + 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( HEADER_SPN, - cable.supplier[i - 1] - if isinstance(cable.supplier, list) - else None, + ( + 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: @@ -444,9 +448,11 @@ class Harness: # shield is shown with specified color and black borders, or as a thin black wire otherwise dot.attr( "edge", - color=":".join(["#000000", shield_color_hex, "#000000"]) - if isinstance(cable.shield, str) - else "#000000", + color=( + ":".join(["#000000", shield_color_hex, "#000000"]) + if isinstance(cable.shield, str) + else "#000000" + ), ) if connection.from_pin is not None: # connect to left from_connector = self.connectors[connection.from_name] @@ -650,7 +656,6 @@ class Harness: graph = self.graph return embed_svg_images(graph.pipe(format="svg").decode("utf-8"), Path.cwd()) - def output( self, filename: (str, Path), diff --git a/src/wireviz/wireviz.py b/src/wireviz/wireviz.py index cf851f8..bc974e8 100755 --- a/src/wireviz/wireviz.py +++ b/src/wireviz/wireviz.py @@ -117,7 +117,9 @@ def parse( # When title is not given, either deduce it from filename, or use default text. if "title" not in harness.metadata: - harness.metadata["title"] = Path(yaml_file).stem if yaml_file else "WireViz diagram and BOM" + harness.metadata["title"] = ( + Path(yaml_file).stem if yaml_file else "WireViz diagram and BOM" + ) # add items # parse YAML input file ==================================================== @@ -202,7 +204,6 @@ def parse( expected_type = alternating_types[1 - alternating_types.index(expected_type)] for connection_set in connection_sets: - # figure out number of parallel connections within this set connectioncount = [] for entry in connection_set: @@ -408,6 +409,7 @@ def _get_yaml_data_and_path(inp: Union[str, Path, Dict]) -> (Dict, Path): # when trying to expand and resolve it as a path. # Catch this error, but raise any others from errno import ENAMETOOLONG + if type(e) is OSError and e.errno != ENAMETOOLONG: raise e # file does not exist; assume inp is a YAML string diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index a233eca..27ee59b 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -36,7 +36,11 @@ def get_additional_component_table( if component.additional_components: rows.append(["Additional components"]) # Ignore components that have qty 0 - for part in [part for part in component.additional_components if component.get_qty_multiplier(part.qty_multiplier)]: + for part in [ + part + for part in component.additional_components + if component.get_qty_multiplier(part.qty_multiplier) + ]: common_args = { "qty": part.qty * component.get_qty_multiplier(part.qty_multiplier), "unit": part.unit, @@ -65,7 +69,11 @@ def get_additional_component_bom(component: Union[Connector, Cable]) -> List[BOM """Return a list of BOM entries with additional components.""" bom_entries = [] # Ignore components that have qty 0 - for part in [part for part in component.additional_components if component.get_qty_multiplier(part.qty_multiplier)]: + for part in [ + part + for part in component.additional_components + if component.get_qty_multiplier(part.qty_multiplier) + ]: bom_entries.append( { "description": part.description, diff --git a/src/wireviz/wv_html.py b/src/wireviz/wv_html.py index 1534266..763da9d 100644 --- a/src/wireviz/wv_html.py +++ b/src/wireviz/wv_html.py @@ -97,9 +97,9 @@ def generate_html_output( if isinstance(entry, Dict): replacements[f""] = str(category) for entry_key, entry_value in entry.items(): - replacements[ - f"" - ] = html_line_breaks(str(entry_value)) + replacements[f""] = ( + html_line_breaks(str(entry_value)) + ) replacements['"sheetsize_default"'] = '"{}"'.format( metadata.get("template", {}).get("sheetsize", "")