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
|
||||
```
|
||||
|
||||
## Tweak entries
|
||||
## GraphViz tweaking (experimental)
|
||||
|
||||
```yaml
|
||||
# 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 .gv output. This leading string must be
|
||||
# followed by attributes in [square brackets].
|
||||
# Entries containing HTML in an attribute are
|
||||
# Entries with an attribute containing HTML are
|
||||
# not supported.
|
||||
<str>: # leading string of .gv entry
|
||||
<str> : <str> # attribute and its new value
|
||||
# Any number of attributes can be overridden
|
||||
# for each entry
|
||||
|
||||
append: # single or list of .gv entries to append
|
||||
<str> # strings to append might have multiple lines
|
||||
append: <str/list> # string or list of strings to append to the .gv output
|
||||
```
|
||||
|
||||
## Colors
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
from graphviz import Graph
|
||||
from collections import Counter
|
||||
from typing import List, Union
|
||||
from typing import Any, List, Union
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from itertools import zip_longest
|
||||
@ -345,9 +345,9 @@ class Harness:
|
||||
dot.node(cable.name, label=f'<\n{html}\n>', shape='box',
|
||||
style=style, fillcolor=translate_color(bgcolor, "HEX"))
|
||||
|
||||
def typecheck(name: str, var, type) -> None:
|
||||
if not isinstance(var, type):
|
||||
raise Exception(f'Unexpected value type of {name}: {var}')
|
||||
def typecheck(name: str, value: Any, expect: type) -> None:
|
||||
if not isinstance(value, expect):
|
||||
raise Exception(f'Unexpected value type of {name}: Expected {expect}, got {type(value)}\n{value}')
|
||||
|
||||
# TODO?: Differ between override attributes and HTML?
|
||||
if self.tweak.override is not None:
|
||||
@ -380,7 +380,7 @@ class Harness:
|
||||
typecheck(f'tweak.append[{i}]', element, str)
|
||||
dot.body.extend(self.tweak.append)
|
||||
else:
|
||||
typecheck(f'tweak.append', self.tweak.append, str)
|
||||
typecheck('tweak.append', self.tweak.append, str)
|
||||
dot.body.append(self.tweak.append)
|
||||
|
||||
return dot
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user