Break longer lines not caught by black
because they were unbroken strings or comments
This commit is contained in:
parent
496b6b1146
commit
9c48b625ec
@ -14,7 +14,8 @@ from wireviz.wv_colors import (
|
|||||||
)
|
)
|
||||||
from wireviz.wv_helper import aspect_ratio, awg_equiv, mm2_equiv
|
from wireviz.wv_helper import aspect_ratio, awg_equiv, mm2_equiv
|
||||||
|
|
||||||
# Each type alias have their legal values described in comments - validation might be implemented in the future
|
# Each type alias have their legal values described in comments
|
||||||
|
# - validation might be implemented in the future
|
||||||
PlainText = str # Text not containing HTML tags nor newlines
|
PlainText = str # Text not containing HTML tags nor newlines
|
||||||
Hypertext = str # Text possibly including HTML hyperlinks that are removed in all outputs except HTML output
|
Hypertext = str # Text possibly including HTML hyperlinks that are removed in all outputs except HTML output
|
||||||
MultilineHypertext = (
|
MultilineHypertext = (
|
||||||
@ -280,7 +281,8 @@ class Connector(Component):
|
|||||||
)
|
)
|
||||||
if not self.pincount:
|
if not self.pincount:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"You need to specify at least one, pincount, pins, pinlabels, or pincolors"
|
"You need to specify at least one: "
|
||||||
|
"pincount, pins, pinlabels, or pincolors"
|
||||||
)
|
)
|
||||||
|
|
||||||
# create default list for pins (sequential) if not specified
|
# create default list for pins (sequential) if not specified
|
||||||
@ -318,7 +320,8 @@ class Connector(Component):
|
|||||||
|
|
||||||
for loop in self.loops:
|
for loop in self.loops:
|
||||||
# TODO: check that pins to connect actually exist
|
# TODO: check that pins to connect actually exist
|
||||||
# TODO: allow using pin labels in addition to pin numbers, just like when defining regular connections
|
# TODO: allow using pin labels in addition to pin numbers,
|
||||||
|
# just like when defining regular connections
|
||||||
# TODO: include properties of wire used to create the loop
|
# TODO: include properties of wire used to create the loop
|
||||||
if len(loop) != 2:
|
if len(loop) != 2:
|
||||||
raise Exception("Loops must be between exactly two pins!")
|
raise Exception("Loops must be between exactly two pins!")
|
||||||
@ -427,13 +430,15 @@ class Cable(Component):
|
|||||||
g, u = self.gauge.split(" ")
|
g, u = self.gauge.split(" ")
|
||||||
except Exception:
|
except Exception:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Cable {self.name} gauge={self.gauge} - Gauge must be a number, or number and unit separated by a space"
|
f"Cable {self.name} gauge={self.gauge} - "
|
||||||
|
"Gauge must be a number, or number and unit separated by a space"
|
||||||
)
|
)
|
||||||
self.gauge = g
|
self.gauge = g
|
||||||
|
|
||||||
if self.gauge_unit is not None:
|
if self.gauge_unit is not None:
|
||||||
print(
|
print(
|
||||||
f"Warning: Cable {self.name} gauge_unit={self.gauge_unit} is ignored because its gauge contains {u}"
|
f"Warning: Cable {self.name} gauge_unit={self.gauge_unit} "
|
||||||
|
f"is ignored because its gauge contains {u}"
|
||||||
)
|
)
|
||||||
if u.upper() == "AWG":
|
if u.upper() == "AWG":
|
||||||
self.gauge_unit = u.upper()
|
self.gauge_unit = u.upper()
|
||||||
@ -452,12 +457,14 @@ class Cable(Component):
|
|||||||
L = float(L)
|
L = float(L)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Cable {self.name} length={self.length} - Length must be a number, or number and unit separated by a space"
|
f"Cable {self.name} length={self.length} - "
|
||||||
|
"Length must be a number, or number and unit separated by a space"
|
||||||
)
|
)
|
||||||
self.length = L
|
self.length = L
|
||||||
if self.length_unit is not None:
|
if self.length_unit is not None:
|
||||||
print(
|
print(
|
||||||
f"Warning: Cable {self.name} length_unit={self.length_unit} is ignored because its length contains {u}"
|
f"Warning: Cable {self.name} length_unit={self.length_unit} is ignored "
|
||||||
|
f"because its length contains {u}"
|
||||||
)
|
)
|
||||||
self.length_unit = u
|
self.length_unit = u
|
||||||
elif not any(isinstance(self.length, t) for t in [int, float]):
|
elif not any(isinstance(self.length, t) for t in [int, float]):
|
||||||
@ -484,7 +491,8 @@ class Cable(Component):
|
|||||||
else: # wirecount implicit in length of color list
|
else: # wirecount implicit in length of color list
|
||||||
if not self.colors:
|
if not self.colors:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"Unknown number of wires. Must specify wirecount or colors (implicit length)"
|
"Unknown number of wires. "
|
||||||
|
"Must specify wirecount or colors (implicit length)"
|
||||||
)
|
)
|
||||||
self.wirecount = len(self.colors)
|
self.wirecount = len(self.colors)
|
||||||
|
|
||||||
@ -494,7 +502,8 @@ class Cable(Component):
|
|||||||
'"s" may not be used as a wire label for a shielded cable.'
|
'"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.
|
# 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.supplier, self.spn, self.pn]:
|
for idfield in [self.manufacturer, self.mpn, self.supplier, self.spn, self.pn]:
|
||||||
if isinstance(idfield, list):
|
if isinstance(idfield, list):
|
||||||
if self.category == "bundle":
|
if self.category == "bundle":
|
||||||
|
|||||||
@ -88,9 +88,11 @@ class Harness:
|
|||||||
if pin in connector.pins and pin in connector.pinlabels:
|
if pin in connector.pins and pin in connector.pinlabels:
|
||||||
if connector.pins.index(pin) != connector.pinlabels.index(pin):
|
if connector.pins.index(pin) != connector.pinlabels.index(pin):
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"{name}:{pin} is defined both in pinlabels and pins, for different pins."
|
f"{name}:{pin} is defined both in pinlabels and pins, "
|
||||||
|
"for different pins."
|
||||||
)
|
)
|
||||||
# TODO: Maybe issue a warning if present in both lists but referencing the same pin?
|
# TODO: Maybe issue a warning if present in both lists
|
||||||
|
# but referencing the same pin?
|
||||||
if pin in connector.pinlabels:
|
if pin in connector.pinlabels:
|
||||||
if connector.pinlabels.count(pin) > 1:
|
if connector.pinlabels.count(pin) > 1:
|
||||||
raise Exception(f"{name}:{pin} is defined more than once.")
|
raise Exception(f"{name}:{pin} is defined more than once.")
|
||||||
@ -110,9 +112,11 @@ class Harness:
|
|||||||
if via_wire in cable.colors and via_wire in cable.wirelabels:
|
if via_wire in cable.colors and via_wire in cable.wirelabels:
|
||||||
if cable.colors.index(via_wire) != cable.wirelabels.index(via_wire):
|
if cable.colors.index(via_wire) != cable.wirelabels.index(via_wire):
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"{via_name}:{via_wire} is defined both in colors and wirelabels, for different wires."
|
f"{via_name}:{via_wire} is defined both in colors and wirelabels, "
|
||||||
|
"for different wires."
|
||||||
)
|
)
|
||||||
# TODO: Maybe issue a warning if present in both lists but referencing the same wire?
|
# TODO: Maybe issue a warning if present in both lists
|
||||||
|
# but referencing the same wire?
|
||||||
if via_wire in cable.colors:
|
if via_wire in cable.colors:
|
||||||
if cable.colors.count(via_wire) > 1:
|
if cable.colors.count(via_wire) > 1:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
|
|||||||
@ -93,7 +93,8 @@ def parse(
|
|||||||
output_file = output_dir / output_name
|
output_file = output_dir / output_name
|
||||||
|
|
||||||
if yaml_file:
|
if yaml_file:
|
||||||
# if reading from file, ensure that input file's parent directory is included in image_paths
|
# if reading from file, ensure that input file's parent directory
|
||||||
|
# is included in image_paths
|
||||||
default_image_path = yaml_file.parent.resolve()
|
default_image_path = yaml_file.parent.resolve()
|
||||||
if not default_image_path in [Path(x).resolve() for x in image_paths]:
|
if not default_image_path in [Path(x).resolve() for x in image_paths]:
|
||||||
image_paths.append(default_image_path)
|
image_paths.append(default_image_path)
|
||||||
@ -128,7 +129,8 @@ def parse(
|
|||||||
if len(yaml_data[sec]) > 0: # section has contents
|
if len(yaml_data[sec]) > 0: # section has contents
|
||||||
if ty == dict:
|
if ty == dict:
|
||||||
for key, attribs in yaml_data[sec].items():
|
for key, attribs in yaml_data[sec].items():
|
||||||
# The Image dataclass might need to open an image file with a relative path.
|
# The Image dataclass might need to open
|
||||||
|
# an image file with a relative path.
|
||||||
image = attribs.get("image")
|
image = attribs.get("image")
|
||||||
if isinstance(image, dict):
|
if isinstance(image, dict):
|
||||||
image_path = image["src"]
|
image_path = image["src"]
|
||||||
@ -164,12 +166,16 @@ def parse(
|
|||||||
autogenerated_designators[template] = (
|
autogenerated_designators[template] = (
|
||||||
autogenerated_designators.get(template, 0) + 1
|
autogenerated_designators.get(template, 0) + 1
|
||||||
)
|
)
|
||||||
designator = f"{AUTOGENERATED_PREFIX}{template}_{autogenerated_designators[template]}"
|
designator = (
|
||||||
|
f"{AUTOGENERATED_PREFIX}"
|
||||||
|
"{template}_{autogenerated_designators[template]}"
|
||||||
|
)
|
||||||
# check if redefining existing component to different template
|
# check if redefining existing component to different template
|
||||||
if designator in designators_and_templates:
|
if designator in designators_and_templates:
|
||||||
if designators_and_templates[designator] != template:
|
if designators_and_templates[designator] != template:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Trying to redefine {designator} from {designators_and_templates[designator]} to {template}"
|
f"Trying to redefine {designator}"
|
||||||
|
f" from {designators_and_templates[designator]} to {template}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
designators_and_templates[designator] = template
|
designators_and_templates[designator] = template
|
||||||
@ -300,7 +306,8 @@ def parse(
|
|||||||
f"{template} is an unknown template/designator/arrow."
|
f"{template} is an unknown template/designator/arrow."
|
||||||
)
|
)
|
||||||
|
|
||||||
alternate_type() # entries in connection set must alternate between connectors and cables/arrows
|
# entries in connection set must alternate between connectors and cables/arrows
|
||||||
|
alternate_type()
|
||||||
|
|
||||||
# transpose connection set list
|
# transpose connection set list
|
||||||
# before: one item per component, one subitem per connection in set
|
# before: one item per component, one subitem per connection in set
|
||||||
|
|||||||
@ -58,7 +58,10 @@ epilog += ", ".join([f"{key} ({value.upper()})" for key, value in format_codes.i
|
|||||||
"--output-name",
|
"--output-name",
|
||||||
default=None,
|
default=None,
|
||||||
type=str,
|
type=str,
|
||||||
help="File name (without extension) to use for output files, if different from input file name.",
|
help=(
|
||||||
|
"File name (without extension) to use for output files, "
|
||||||
|
"if different from input file name."
|
||||||
|
),
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"-V",
|
"-V",
|
||||||
|
|||||||
@ -430,7 +430,8 @@ def image_and_caption_cells(component: Component) -> (Td, Td):
|
|||||||
image_tag = Img(scale=component.image.scale, src=component.image.src)
|
image_tag = Img(scale=component.image.scale, src=component.image.src)
|
||||||
image_cell_inner = Td(image_tag, flat=True)
|
image_cell_inner = Td(image_tag, flat=True)
|
||||||
if component.image.fixedsize:
|
if component.image.fixedsize:
|
||||||
# further nest the image in a table with width/height/fixedsize parameters, and place that table in a cell
|
# further nest the image in a table with width/height/fixedsize parameters,
|
||||||
|
# and place that table in a cell
|
||||||
image_cell_inner.update_attribs(**html_size_attr_dict(component.image))
|
image_cell_inner.update_attribs(**html_size_attr_dict(component.image))
|
||||||
image_cell = Td(
|
image_cell = Td(
|
||||||
Table(Tr(image_cell_inner), border=0, cellborder=0, cellspacing=0, id="!")
|
Table(Tr(image_cell_inner), border=0, cellborder=0, cellspacing=0, id="!")
|
||||||
@ -500,7 +501,8 @@ def apply_dot_tweaks(dot, tweak):
|
|||||||
def typecheck(name: str, value: Any, expect: type) -> None:
|
def typecheck(name: str, value: Any, expect: type) -> None:
|
||||||
if not isinstance(value, expect):
|
if not isinstance(value, expect):
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Unexpected value type of {name}: Expected {expect}, got {type(value)}\n{value}"
|
f"Unexpected value type of {name}: "
|
||||||
|
f"Expected {expect}, got {type(value)}\n{value}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO?: Differ between override attributes and HTML?
|
# TODO?: Differ between override attributes and HTML?
|
||||||
@ -530,11 +532,13 @@ def apply_dot_tweaks(dot, tweak):
|
|||||||
)
|
)
|
||||||
if n_subs < 1:
|
if n_subs < 1:
|
||||||
print(
|
print(
|
||||||
f"Harness.create_graph() warning: {attr} not found in {keyword}!"
|
"Harness.create_graph() warning: "
|
||||||
|
f"{attr} not found in {keyword}!"
|
||||||
)
|
)
|
||||||
elif n_subs > 1:
|
elif n_subs > 1:
|
||||||
print(
|
print(
|
||||||
f"Harness.create_graph() warning: {attr} removed {n_subs} times in {keyword}!"
|
"Harness.create_graph() warning: "
|
||||||
|
f"{attr} removed {n_subs} times in {keyword}!"
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -549,7 +553,8 @@ def apply_dot_tweaks(dot, tweak):
|
|||||||
entry = re.sub(r"\]$", f" {attr}={value}]", entry)
|
entry = re.sub(r"\]$", f" {attr}={value}]", entry)
|
||||||
elif n_subs > 1:
|
elif n_subs > 1:
|
||||||
print(
|
print(
|
||||||
f"Harness.create_graph() warning: {attr} overridden {n_subs} times in {keyword}!"
|
"Harness.create_graph() warning: "
|
||||||
|
f"{attr} overridden {n_subs} times in {keyword}!"
|
||||||
)
|
)
|
||||||
|
|
||||||
dot.body[i] = entry
|
dot.body[i] = entry
|
||||||
|
|||||||
@ -25,7 +25,8 @@ def generate_html_output(
|
|||||||
# load HTML template
|
# load HTML template
|
||||||
templatename = metadata.get("template", {}).get("name")
|
templatename = metadata.get("template", {}).get("name")
|
||||||
if templatename:
|
if templatename:
|
||||||
# if relative path to template was provided, check directory of YAML file first, fall back to built-in template directory
|
# if relative path to template was provided,
|
||||||
|
# check directory of YAML file first, fall back to built-in template directory
|
||||||
templatefile = smart_file_resolve(
|
templatefile = smart_file_resolve(
|
||||||
f"{templatename}.html",
|
f"{templatename}.html",
|
||||||
[Path(filename).parent, Path(__file__).parent / "templates"],
|
[Path(filename).parent, Path(__file__).parent / "templates"],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user