From 8343f62f411af85242683b9b8a075c1ac142caf5 Mon Sep 17 00:00:00 2001 From: Laurier Loiselle Date: Mon, 30 Jan 2023 16:33:28 -0500 Subject: [PATCH] tweak: remove support --- docs/syntax.md | 28 ------------- src/wireviz/wireviz.py | 3 +- src/wireviz/wv_dataclasses.py | 6 --- src/wireviz/wv_graphviz.py | 74 +---------------------------------- src/wireviz/wv_harness.py | 5 --- 5 files changed, 2 insertions(+), 114 deletions(-) diff --git a/docs/syntax.md b/docs/syntax.md index 36ce1a1..5f7128e 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -37,8 +37,6 @@ options: # dictionary of common attributes for the whole harness : # optional harness attributes (see below) ... -tweak: # optional tweaking of .gv output - ... ``` ## Connector attributes @@ -422,31 +420,6 @@ Alternatively items can be added to just the BOM by putting them in the section spn: # supplier part number ``` -## GraphViz tweaking (experimental) - -```yaml - # Optional tweaking of the .gv output. - # This feature is experimental and might change - # or be removed in future versions. - - override: # dict of .gv entries to override - # Each entry is identified by its leading string - # in lines beginning with a TAB character. - # The leading string might be in "quotes" in - # the .gv output. This leading string must be - # followed by attributes in [square brackets]. - # Entries with an attribute containing HTML are - # not supported. - : # leading string of .gv entry - : # attribute and its new value - # Any number of attributes can be overridden - # for each entry. Attributes not already existing - # in the entry will be appended to the entry. - # Use null as new value to delete an attribute. - - append: # string or list of strings to append to the .gv output -``` - ## Colors Colors are defined via uppercase, two character strings. @@ -529,7 +502,6 @@ The following attributes accept multiline strings: - `supplier` - `spn` - `image.caption` -- `tweak.append` ### Method 1 diff --git a/src/wireviz/wireviz.py b/src/wireviz/wireviz.py index 0613c1a..88e31c3 100755 --- a/src/wireviz/wireviz.py +++ b/src/wireviz/wireviz.py @@ -7,7 +7,7 @@ from typing import Any, Dict, List, Tuple, Union import yaml -from wireviz.wv_dataclasses import AUTOGENERATED_PREFIX, Metadata, Options, Tweak +from wireviz.wv_dataclasses import AUTOGENERATED_PREFIX, Metadata, Options from wireviz.wv_harness import Harness from wireviz.wv_utils import ( expand, @@ -97,7 +97,6 @@ def parse( **{"output_name": output_name}, ), options=Options(**yaml_data.get("options", {})), - tweak=Tweak(**yaml_data.get("tweak", {})), shared_bom=shared_bom, ) # others diff --git a/src/wireviz/wv_dataclasses.py b/src/wireviz/wv_dataclasses.py index fcae863..375bec2 100644 --- a/src/wireviz/wv_dataclasses.py +++ b/src/wireviz/wv_dataclasses.py @@ -411,12 +411,6 @@ class Options: self.bgcolor_bundle = SingleColor(self.bgcolor_bundle) or self.bgcolor_cable -@dataclass -class Tweak: - override: Optional[Dict[Designator, Dict[str, Optional[str]]]] = None - append: Union[str, List[str], None] = None - - @dataclass class Image: # Attributes of the image object : diff --git a/src/wireviz/wv_graphviz.py b/src/wireviz/wv_graphviz.py index e16de57..2ecf59a 100644 --- a/src/wireviz/wv_graphviz.py +++ b/src/wireviz/wv_graphviz.py @@ -145,7 +145,7 @@ def bom_bubble(id) -> Table: return None else: # TODO: activate BOM bubbles - return None + #return None # size and style of BOM bubble is optimized to be a rounded square, # big enough to hold any two-digit ID without GraphViz warnings text = id @@ -522,75 +522,3 @@ def set_dot_basics(dot, options): fontname=options.fontname, ) dot.attr("edge", style="bold", fontname=options.fontname) - - -def apply_dot_tweaks(dot, tweak): - def typecheck(name: str, value: Any, expect: type) -> None: - if not isinstance(value, expect): - raise Exception( - f"Unexpected value type of {name}: " - f"Expected {expect}, got {type(value)}\n{value}" - ) - - # TODO?: Differ between override attributes and HTML? - if tweak.override is not None: - typecheck("tweak.override", tweak.override, dict) - for k, d in tweak.override.items(): - typecheck(f"tweak.override.{k} key", k, str) - typecheck(f"tweak.override.{k} value", d, dict) - for a, v in d.items(): - typecheck(f"tweak.override.{k}.{a} key", a, str) - typecheck(f"tweak.override.{k}.{a} value", v, (str, type(None))) - - # Override generated attributes of selected entries matching tweak.override. - for i, entry in enumerate(dot.body): - if not isinstance(entry, str): - continue - # Find a possibly quoted keyword after leading TAB(s) and followed by [ ]. - match = re.match(r'^\t*(")?((?(1)[^"]|[^ "])+)(?(1)") \[.*\]$', entry, re.S) - keyword = match and match[2] - if not keyword in tweak.override.keys(): - continue - - for attr, value in tweak.override[keyword].items(): - if value is None: - entry, n_subs = re.subn( - f'( +)?{attr}=("[^"]*"|[^] ]*)(?(1)| *)', "", entry - ) - if n_subs < 1: - print( - "Harness.create_graph() warning: " - f"{attr} not found in {keyword}!" - ) - elif n_subs > 1: - print( - "Harness.create_graph() warning: " - f"{attr} removed {n_subs} times in {keyword}!" - ) - continue - - if len(value) == 0 or " " in value: - value = value.replace('"', r"\"") - value = f'"{value}"' - entry, n_subs = re.subn( - f'{attr}=("[^"]*"|[^] ]*)', f"{attr}={value}", entry - ) - if n_subs < 1: - # If attr not found, then append it - entry = re.sub(r"\]$", f" {attr}={value}]", entry) - elif n_subs > 1: - print( - "Harness.create_graph() warning: " - f"{attr} overridden {n_subs} times in {keyword}!" - ) - - dot.body[i] = entry - - if tweak.append is not None: - if isinstance(tweak.append, list): - for i, element in enumerate(tweak.append, 1): - typecheck(f"tweak.append[{i}]", element, str) - dot.body.extend(tweak.append) - else: - typecheck("tweak.append", tweak.append, str) - dot.body.append(tweak.append) diff --git a/src/wireviz/wv_harness.py b/src/wireviz/wv_harness.py index b773998..c244f4f 100644 --- a/src/wireviz/wv_harness.py +++ b/src/wireviz/wv_harness.py @@ -20,10 +20,8 @@ from wireviz.wv_dataclasses import ( Metadata, Options, Side, - Tweak, ) from wireviz.wv_graphviz import ( - apply_dot_tweaks, calculate_node_bgcolor, gv_connector_loops, gv_edge_mate, @@ -40,7 +38,6 @@ from wireviz.wv_utils import bom2tsv class Harness: metadata: Metadata options: Options - tweak: Tweak additional_bom_items: List[Component] = field(default_factory=list) shared_bom: Dict = field(default_factory=dict) @@ -327,8 +324,6 @@ class Harness: dot.attr("edge", color=color, style="dashed", dir=dir) dot.edge(code_from, code_to) - apply_dot_tweaks(dot, self.tweak) - return dot # cache for the GraphViz Graph object