")
- wirehtml.append(
- f' '
- )
- wirehtml.append(
- ' '
- )
- for j, bgcolor in enumerate(
- bgcolors[::-1]
- ): # Reverse to match the curved wires when more than 2 colors
- wirehtml.append(
- f' | '
- )
+ wirehtml.append(f' ')
+ wirehtml.append(' ')
+ for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors
+ wirehtml.append(f' | ')
wirehtml.append(" ")
wirehtml.append(" | ")
wirehtml.append(" ")
- if (
- cable.category == "bundle"
- ): # for bundles individual wires can have part information
+ # fmt: on
+
+ # for bundles, individual wires can have part information
+ if cable.category == "bundle":
# create a list of wire parameters
wireidentification = []
if isinstance(cable.pn, list):
@@ -439,14 +389,14 @@ class Harness:
wireidentification.append(html_line_breaks(supplier_info))
# print parameters into a table row under the wire
if len(wireidentification) > 0:
+ # fmt: off
wirehtml.append(' ')
- wirehtml.append(
- ' '
- )
+ wirehtml.append(' ')
for attrib in wireidentification:
wirehtml.append(f" | {attrib} | ")
wirehtml.append(" ")
wirehtml.append(" ")
+ # fmt: on
if cable.shield:
wirehtml.append(" | | ") # spacer
@@ -464,9 +414,9 @@ class Harness:
else:
# shield is shown as a thin black wire
attributes = f'height="2" bgcolor="#000000" border="0"'
- wirehtml.append(
- f' | '
- )
+ # fmt: off
+ wirehtml.append(f' | ')
+ # fmt: on
wirehtml.append(" | | ")
wirehtml.append(" ")
@@ -477,9 +427,8 @@ class Harness:
# connections
for connection in cable.connections:
- if isinstance(
- connection.via_port, int
- ): # check if it's an actual wire and not a shield
+ if isinstance(connection.via_port, int):
+ # check if it's an actual wire and not a shield
dot.attr(
"edge",
color=":".join(
@@ -734,15 +683,15 @@ class Harness:
with open_file_write(f"{filename}.bom.tsv") as file:
file.write(tuplelist2tsv(bomlist))
if "csv" in fmt:
- print(
- "CSV output is not yet supported"
- ) # TODO: implement CSV output (preferrably using CSV library)
+ # TODO: implement CSV output (preferrably using CSV library)
+ print("CSV output is not yet supported")
# HTML output
if "html" in fmt:
generate_html_output(filename, bomlist, self.metadata, self.options)
# PDF output
if "pdf" in fmt:
- print("PDF output is not yet supported") # TODO: implement PDF output
+ # TODO: implement PDF output
+ print("PDF output is not yet supported")
# delete SVG if not needed
if "html" in fmt and not "svg" in fmt and not svg_already_exists:
Path(f"{filename}.svg").unlink()
diff --git a/src/wireviz/wireviz.py b/src/wireviz/wireviz.py
index 5f11736..032afca 100755
--- a/src/wireviz/wireviz.py
+++ b/src/wireviz/wireviz.py
@@ -86,12 +86,10 @@ def parse(
tweak=Tweak(**yaml_data.get("tweak", {})),
)
# others
- designators_and_templates = (
- {}
- ) # store mapping of components to their respective template
- autogenerated_designators = (
- {}
- ) # keep track of auto-generated designators to avoid duplicates
+ # store mapping of components to their respective template
+ designators_and_templates = {}
+ # keep track of auto-generated designators to avoid duplicates
+ autogenerated_designators = {}
if "title" not in harness.metadata:
harness.metadata["title"] = Path(file_out).stem
@@ -110,9 +108,8 @@ def parse(
image = attribs.get("image")
if isinstance(image, dict):
image_path = image["src"]
- if (
- image_path and not Path(image_path).is_absolute()
- ): # resolve relative image path
+ if image_path and not Path(image_path).is_absolute():
+ # resolve relative image path
image["src"] = smart_file_resolve(
image_path, image_paths
)
@@ -187,9 +184,8 @@ def parse(
if isinstance(entry, list):
connectioncount.append(len(entry))
elif isinstance(entry, dict):
- connectioncount.append(
- len(expand(list(entry.values())[0]))
- ) # - X1: [1-4,6] yields 5
+ connectioncount.append(len(expand(list(entry.values())[0])))
+ # e.g.: - X1: [1-4,6] yields 5
else:
pass # strings do not reveal connectioncount
if not any(connectioncount):
@@ -258,9 +254,8 @@ def parse(
if designator in harness.connectors: # existing connector instance
check_type(designator, template, "connector")
- elif (
- template in template_connectors.keys()
- ): # generate new connector instance from template
+ elif template in template_connectors.keys():
+ # generate new connector instance from template
check_type(designator, template, "connector")
harness.add_connector(
name=designator, **template_connectors[template]
@@ -268,9 +263,8 @@ def parse(
elif designator in harness.cables: # existing cable instance
check_type(designator, template, "cable/arrow")
- elif (
- template in template_cables.keys()
- ): # generate new cable instance from template
+ elif template in template_cables.keys():
+ # generate new cable instance from template
check_type(designator, template, "cable/arrow")
harness.add_cable(name=designator, **template_cables[template])
@@ -295,18 +289,16 @@ def parse(
designator = list(item.keys())[0]
if designator in harness.cables:
- if (
- index_item == 0
- ): # list started with a cable, no connector to join on left side
+ if index_item == 0:
+ # list started with a cable, no connector to join on left side
from_name, from_pin = (None, None)
else:
from_name, from_pin = get_single_key_and_value(
entry[index_item - 1]
)
via_name, via_pin = (designator, item[designator])
- if (
- index_item == len(entry) - 1
- ): # list ends with a cable, no connector to join on right side
+ if index_item == len(entry) - 1:
+ # list ends with a cable, no connector to join on right side
to_name, to_pin = (None, None)
else:
to_name, to_pin = get_single_key_and_value(
@@ -335,9 +327,8 @@ def parse(
harness.add_mate_pin(
from_name, from_pin, to_name, to_pin, designator
)
- elif (
- "=" in designator and index_entry == 0
- ): # mate two connectors as a whole
+ elif "=" in designator and index_entry == 0:
+ # mate two connectors as a whole
harness.add_mate_component(from_name, to_name, designator)
# harness population completed =============================================
diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py
index 29b49ef..6689d79 100644
--- a/src/wireviz/wv_bom.py
+++ b/src/wireviz/wv_bom.py
@@ -214,11 +214,8 @@ def get_bom_index(bom: List[BOMEntry], target: BOMKey) -> int:
def bom_list(bom: List[BOMEntry]) -> List[List[str]]:
"""Return list of BOM rows as lists of column strings with headings in top row."""
keys = list(BOM_COLUMNS_ALWAYS) # Always include this fixed set of BOM columns.
- for (
- fieldname
- ) in (
- BOM_COLUMNS_OPTIONAL
- ): # Include only those optional BOM columns that are in use.
+ for fieldname in BOM_COLUMNS_OPTIONAL:
+ # Include only those optional BOM columns that are in use.
if any(entry.get(fieldname) for entry in bom):
keys.append(fieldname)
# Custom mapping from internal name to BOM column headers.
diff --git a/src/wireviz/wv_cli.py b/src/wireviz/wv_cli.py
index b3f3daf..65a20a6 100644
--- a/src/wireviz/wv_cli.py
+++ b/src/wireviz/wv_cli.py
@@ -23,7 +23,8 @@ format_codes = {
"t": "tsv",
}
-epilog = "The -f or --format option accepts a string containing one or more of the following characters to specify which file types to output:\n"
+epilog = "The -f or --format option accepts a string containing one or more of the "
+epilog += "following characters to specify which file types to output:\n"
epilog += ", ".join([f"{key} ({value.upper()})" for key, value in format_codes.items()])
diff --git a/src/wireviz/wv_colors.py b/src/wireviz/wv_colors.py
index 7e9a6b4..857f307 100644
--- a/src/wireviz/wv_colors.py
+++ b/src/wireviz/wv_colors.py
@@ -3,177 +3,38 @@
from typing import Dict, List
COLOR_CODES = {
+ # fmt: off
"DIN": [
- "WH",
- "BN",
- "GN",
- "YE",
- "GY",
- "PK",
- "BU",
- "RD",
- "BK",
- "VT",
- "GYPK",
- "RDBU",
- "WHGN",
- "BNGN",
- "WHYE",
- "YEBN",
- "WHGY",
- "GYBN",
- "WHPK",
- "PKBN",
- "WHBU",
- "BNBU",
- "WHRD",
- "BNRD",
- "WHBK",
- "BNBK",
- "GYGN",
- "YEGY",
- "PKGN",
- "YEPK",
- "GNBU",
- "YEBU",
- "GNRD",
- "YERD",
- "GNBK",
- "YEBK",
- "GYBU",
- "PKBU",
- "GYRD",
- "PKRD",
- "GYBK",
- "PKBK",
- "BUBK",
- "RDBK",
- "WHBNBK",
- "YEGNBK",
- "GYPKBK",
- "RDBUBK",
- "WHGNBK",
- "BNGNBK",
- "WHYEBK",
- "YEBNBK",
- "WHGYBK",
- "GYBNBK",
- "WHPKBK",
- "PKBNBK",
- "WHBUBK",
- "BNBUBK",
- "WHRDBK",
- "BNRDBK",
+ "WH", "BN", "GN", "YE", "GY", "PK", "BU", "RD", "BK", "VT", "GYPK", "RDBU",
+ "WHGN", "BNGN", "WHYE", "YEBN", "WHGY", "GYBN", "WHPK", "PKBN", "WHBU", "BNBU",
+ "WHRD", "BNRD", "WHBK", "BNBK", "GYGN", "YEGY", "PKGN", "YEPK", "GNBU", "YEBU",
+ "GNRD", "YERD", "GNBK", "YEBK", "GYBU", "PKBU", "GYRD", "PKRD", "GYBK", "PKBK",
+ "BUBK", "RDBK", "WHBNBK", "YEGNBK", "GYPKBK", "RDBUBK", "WHGNBK", "BNGNBK",
+ "WHYEBK", "YEBNBK", "WHGYBK", "GYBNBK", "WHPKBK", "PKBNBK", "WHBUBK",
+ "BNBUBK", "WHRDBK", "BNRDBK",
],
+ # fmt: on
"IEC": ["BN", "RD", "OG", "YE", "GN", "BU", "VT", "GY", "WH", "BK"],
"BW": ["BK", "WH"],
# 25-pair color code - see also https://en.wikipedia.org/wiki/25-pair_color_code
# 5 major colors (WH,RD,BK,YE,VT) combined with 5 minor colors (BU,OG,GN,BN,SL).
# Each POTS pair tip (+) had major/minor color, and ring (-) had minor/major color.
+ # fmt: off
"TEL": [ # 25x2: Ring and then tip of each pair
- "BUWH",
- "WHBU",
- "OGWH",
- "WHOG",
- "GNWH",
- "WHGN",
- "BNWH",
- "WHBN",
- "SLWH",
- "WHSL",
- "BURD",
- "RDBU",
- "OGRD",
- "RDOG",
- "GNRD",
- "RDGN",
- "BNRD",
- "RDBN",
- "SLRD",
- "RDSL",
- "BUBK",
- "BKBU",
- "OGBK",
- "BKOG",
- "GNBK",
- "BKGN",
- "BNBK",
- "BKBN",
- "SLBK",
- "BKSL",
- "BUYE",
- "YEBU",
- "OGYE",
- "YEOG",
- "GNYE",
- "YEGN",
- "BNYE",
- "YEBN",
- "SLYE",
- "YESL",
- "BUVT",
- "VTBU",
- "OGVT",
- "VTOG",
- "GNVT",
- "VTGN",
- "BNVT",
- "VTBN",
- "SLVT",
- "VTSL",
+ "BUWH", "WHBU", "OGWH", "WHOG", "GNWH", "WHGN", "BNWH", "WHBN", "SLWH", "WHSL",
+ "BURD", "RDBU", "OGRD", "RDOG", "GNRD", "RDGN", "BNRD", "RDBN", "SLRD", "RDSL",
+ "BUBK", "BKBU", "OGBK", "BKOG", "GNBK", "BKGN", "BNBK", "BKBN", "SLBK", "BKSL",
+ "BUYE", "YEBU", "OGYE", "YEOG", "GNYE", "YEGN", "BNYE", "YEBN", "SLYE", "YESL",
+ "BUVT", "VTBU", "OGVT", "VTOG", "GNVT", "VTGN", "BNVT", "VTBN", "SLVT", "VTSL",
],
"TELALT": [ # 25x2: Tip and then ring of each pair
- "WHBU",
- "BU",
- "WHOG",
- "OG",
- "WHGN",
- "GN",
- "WHBN",
- "BN",
- "WHSL",
- "SL",
- "RDBU",
- "BURD",
- "RDOG",
- "OGRD",
- "RDGN",
- "GNRD",
- "RDBN",
- "BNRD",
- "RDSL",
- "SLRD",
- "BKBU",
- "BUBK",
- "BKOG",
- "OGBK",
- "BKGN",
- "GNBK",
- "BKBN",
- "BNBK",
- "BKSL",
- "SLBK",
- "YEBU",
- "BUYE",
- "YEOG",
- "OGYE",
- "YEGN",
- "GNYE",
- "YEBN",
- "BNYE",
- "YESL",
- "SLYE",
- "VTBU",
- "BUVT",
- "VTOG",
- "OGVT",
- "VTGN",
- "GNVT",
- "VTBN",
- "BNVT",
- "VTSL",
- "SLVT",
+ "WHBU", "BU", "WHOG", "OG", "WHGN", "GN", "WHBN", "BN", "WHSL", "SL",
+ "RDBU", "BURD", "RDOG", "OGRD", "RDGN", "GNRD", "RDBN", "BNRD", "RDSL", "SLRD",
+ "BKBU", "BUBK", "BKOG", "OGBK", "BKGN", "GNBK", "BKBN", "BNBK", "BKSL", "SLBK",
+ "YEBU", "BUYE", "YEOG", "OGYE", "YEGN", "GNYE", "YEBN", "BNYE", "YESL", "SLYE",
+ "VTBU", "BUVT", "VTOG", "OGVT", "VTGN", "GNVT", "VTBN", "BNVT", "VTSL", "SLVT",
],
+ # fmt: on
"T568A": ["WHGN", "GN", "WHOG", "BU", "WHBU", "OG", "WHBN", "BN"],
"T568B": ["WHOG", "OG", "WHGN", "BU", "WHBU", "GN", "WHBN", "BN"],
}
diff --git a/src/wireviz/wv_gv_html.py b/src/wireviz/wv_gv_html.py
index ea52c10..ec80aa7 100644
--- a/src/wireviz/wv_gv_html.py
+++ b/src/wireviz/wv_gv_html.py
@@ -25,15 +25,15 @@ def nested_html_table(
if isinstance(row, List):
if len(row) > 0 and any(row):
html.append(" | ")
- html.append(
- ' '
- )
+ # fmt: off
+ html.append(' ')
+ # fmt: on
for cell in row:
if cell is not None:
# Inject attributes to the preceeding | tag where needed
- html.append(
- f' | {cell} | '.replace(">{cell}'.replace("> ")
html.append(" ")
num_rows = num_rows + 1
@@ -43,9 +43,8 @@ def nested_html_table(
html.append(" ")
num_rows = num_rows + 1
if num_rows == 0: # empty table
- html.append(
- " | "
- ) # generate empty cell to avoid GraphViz errors
+ # generate empty cell to avoid GraphViz errors
+ html.append(" | ")
html.append(" ")
return html
diff --git a/src/wireviz/wv_helper.py b/src/wireviz/wv_helper.py
index 7cbe125..a10f6ac 100644
--- a/src/wireviz/wv_helper.py
+++ b/src/wireviz/wv_helper.py
@@ -58,9 +58,8 @@ def expand(yaml_data):
else: # a == b
output.append(a) # range of length 1
except:
- output.append(
- e
- ) # '-' was not a delimiter between two ints, pass e through unchanged
+ # '-' was not a delimiter between two ints, pass e through unchanged
+ output.append(e)
else:
try:
x = int(e) # single int
diff --git a/src/wireviz/wv_html.py b/src/wireviz/wv_html.py
index 6389503..6b85ef7 100644
--- a/src/wireviz/wv_html.py
+++ b/src/wireviz/wv_html.py
@@ -104,14 +104,15 @@ def generate_html_output(
replacements['"sheetsize_default"'] = '"{}"'.format(
metadata.get("template", {}).get("sheetsize", "")
- ) # include quotes so no replacement happens within | |