Change a few details suggested in review by owner
- Improve syntax description - Improve typecheck() function parameter names and type hints Co-authored-by: Daniel Rojas <github@danielrojas.net>
This commit is contained in:
parent
723235759b
commit
04a7dab010
@ -329,7 +329,7 @@ Alternatively items can be added to just the BOM by putting them in the section
|
|||||||
manufacturer: <str> # manufacturer name
|
manufacturer: <str> # manufacturer name
|
||||||
```
|
```
|
||||||
|
|
||||||
## Tweak entries
|
## GraphViz tweaking (experimental)
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# Optional tweaking of the .gv output.
|
# Optional tweaking of the .gv output.
|
||||||
@ -342,15 +342,14 @@ Alternatively items can be added to just the BOM by putting them in the section
|
|||||||
# The leading string might be in "quotes" in
|
# The leading string might be in "quotes" in
|
||||||
# the .gv output. This leading string must be
|
# the .gv output. This leading string must be
|
||||||
# followed by attributes in [square brackets].
|
# followed by attributes in [square brackets].
|
||||||
# Entries containing HTML in an attribute are
|
# Entries with an attribute containing HTML are
|
||||||
# not supported.
|
# not supported.
|
||||||
<str>: # leading string of .gv entry
|
<str>: # leading string of .gv entry
|
||||||
<str> : <str> # attribute and its new value
|
<str> : <str> # attribute and its new value
|
||||||
# Any number of attributes can be overridden
|
# Any number of attributes can be overridden
|
||||||
# for each entry
|
# for each entry
|
||||||
|
|
||||||
append: # single or list of .gv entries to append
|
append: <str/list> # string or list of strings to append to the .gv output
|
||||||
<str> # strings to append might have multiple lines
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Colors
|
## Colors
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
from graphviz import Graph
|
from graphviz import Graph
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from typing import List, Union
|
from typing import Any, List, Union
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
@ -345,9 +345,9 @@ class Harness:
|
|||||||
dot.node(cable.name, label=f'<\n{html}\n>', shape='box',
|
dot.node(cable.name, label=f'<\n{html}\n>', shape='box',
|
||||||
style=style, fillcolor=translate_color(bgcolor, "HEX"))
|
style=style, fillcolor=translate_color(bgcolor, "HEX"))
|
||||||
|
|
||||||
def typecheck(name: str, var, type) -> None:
|
def typecheck(name: str, value: Any, expect: type) -> None:
|
||||||
if not isinstance(var, type):
|
if not isinstance(value, expect):
|
||||||
raise Exception(f'Unexpected value type of {name}: {var}')
|
raise Exception(f'Unexpected value type of {name}: Expected {expect}, got {type(value)}\n{value}')
|
||||||
|
|
||||||
# TODO?: Differ between override attributes and HTML?
|
# TODO?: Differ between override attributes and HTML?
|
||||||
if self.tweak.override is not None:
|
if self.tweak.override is not None:
|
||||||
@ -380,7 +380,7 @@ class Harness:
|
|||||||
typecheck(f'tweak.append[{i}]', element, str)
|
typecheck(f'tweak.append[{i}]', element, str)
|
||||||
dot.body.extend(self.tweak.append)
|
dot.body.extend(self.tweak.append)
|
||||||
else:
|
else:
|
||||||
typecheck(f'tweak.append', self.tweak.append, str)
|
typecheck('tweak.append', self.tweak.append, str)
|
||||||
dot.body.append(self.tweak.append)
|
dot.body.append(self.tweak.append)
|
||||||
|
|
||||||
return dot
|
return dot
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user