tweak: remove support
This commit is contained in:
parent
8a21201c86
commit
8343f62f41
@ -37,8 +37,6 @@ options: # dictionary of common attributes for the whole harness
|
|||||||
<str> : <value> # optional harness attributes (see below)
|
<str> : <value> # optional harness attributes (see below)
|
||||||
...
|
...
|
||||||
|
|
||||||
tweak: # optional tweaking of .gv output
|
|
||||||
...
|
|
||||||
```
|
```
|
||||||
## Connector attributes
|
## Connector attributes
|
||||||
|
|
||||||
@ -422,31 +420,6 @@ Alternatively items can be added to just the BOM by putting them in the section
|
|||||||
spn: <str> # supplier part number
|
spn: <str> # 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.
|
|
||||||
<str>: # leading string of .gv entry
|
|
||||||
<str> : <str/null> # 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: <str/list> # string or list of strings to append to the .gv output
|
|
||||||
```
|
|
||||||
|
|
||||||
## Colors
|
## Colors
|
||||||
|
|
||||||
Colors are defined via uppercase, two character strings.
|
Colors are defined via uppercase, two character strings.
|
||||||
@ -529,7 +502,6 @@ The following attributes accept multiline strings:
|
|||||||
- `supplier`
|
- `supplier`
|
||||||
- `spn`
|
- `spn`
|
||||||
- `image.caption`
|
- `image.caption`
|
||||||
- `tweak.append`
|
|
||||||
|
|
||||||
### Method 1
|
### Method 1
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ from typing import Any, Dict, List, Tuple, Union
|
|||||||
|
|
||||||
import yaml
|
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_harness import Harness
|
||||||
from wireviz.wv_utils import (
|
from wireviz.wv_utils import (
|
||||||
expand,
|
expand,
|
||||||
@ -97,7 +97,6 @@ def parse(
|
|||||||
**{"output_name": output_name},
|
**{"output_name": output_name},
|
||||||
),
|
),
|
||||||
options=Options(**yaml_data.get("options", {})),
|
options=Options(**yaml_data.get("options", {})),
|
||||||
tweak=Tweak(**yaml_data.get("tweak", {})),
|
|
||||||
shared_bom=shared_bom,
|
shared_bom=shared_bom,
|
||||||
)
|
)
|
||||||
# others
|
# others
|
||||||
|
|||||||
@ -411,12 +411,6 @@ class Options:
|
|||||||
self.bgcolor_bundle = SingleColor(self.bgcolor_bundle) or self.bgcolor_cable
|
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
|
@dataclass
|
||||||
class Image:
|
class Image:
|
||||||
# Attributes of the image object <img>:
|
# Attributes of the image object <img>:
|
||||||
|
|||||||
@ -145,7 +145,7 @@ def bom_bubble(id) -> Table:
|
|||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
# TODO: activate BOM bubbles
|
# TODO: activate BOM bubbles
|
||||||
return None
|
#return None
|
||||||
# size and style of BOM bubble is optimized to be a rounded square,
|
# size and style of BOM bubble is optimized to be a rounded square,
|
||||||
# big enough to hold any two-digit ID without GraphViz warnings
|
# big enough to hold any two-digit ID without GraphViz warnings
|
||||||
text = id
|
text = id
|
||||||
@ -522,75 +522,3 @@ def set_dot_basics(dot, options):
|
|||||||
fontname=options.fontname,
|
fontname=options.fontname,
|
||||||
)
|
)
|
||||||
dot.attr("edge", style="bold", 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)
|
|
||||||
|
|||||||
@ -20,10 +20,8 @@ from wireviz.wv_dataclasses import (
|
|||||||
Metadata,
|
Metadata,
|
||||||
Options,
|
Options,
|
||||||
Side,
|
Side,
|
||||||
Tweak,
|
|
||||||
)
|
)
|
||||||
from wireviz.wv_graphviz import (
|
from wireviz.wv_graphviz import (
|
||||||
apply_dot_tweaks,
|
|
||||||
calculate_node_bgcolor,
|
calculate_node_bgcolor,
|
||||||
gv_connector_loops,
|
gv_connector_loops,
|
||||||
gv_edge_mate,
|
gv_edge_mate,
|
||||||
@ -40,7 +38,6 @@ from wireviz.wv_utils import bom2tsv
|
|||||||
class Harness:
|
class Harness:
|
||||||
metadata: Metadata
|
metadata: Metadata
|
||||||
options: Options
|
options: Options
|
||||||
tweak: Tweak
|
|
||||||
additional_bom_items: List[Component] = field(default_factory=list)
|
additional_bom_items: List[Component] = field(default_factory=list)
|
||||||
shared_bom: Dict = field(default_factory=dict)
|
shared_bom: Dict = field(default_factory=dict)
|
||||||
|
|
||||||
@ -327,8 +324,6 @@ class Harness:
|
|||||||
dot.attr("edge", color=color, style="dashed", dir=dir)
|
dot.attr("edge", color=color, style="dashed", dir=dir)
|
||||||
dot.edge(code_from, code_to)
|
dot.edge(code_from, code_to)
|
||||||
|
|
||||||
apply_dot_tweaks(dot, self.tweak)
|
|
||||||
|
|
||||||
return dot
|
return dot
|
||||||
|
|
||||||
# cache for the GraphViz Graph object
|
# cache for the GraphViz Graph object
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user