Delete tweak.override attributes with null value
This commit is contained in:
parent
ba8f8423be
commit
4945d262a0
@ -345,10 +345,11 @@ Alternatively items can be added to just the BOM by putting them in the section
|
|||||||
# Entries with an attribute containing HTML 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/null> # attribute and its new value
|
||||||
# Any number of attributes can be overridden
|
# Any number of attributes can be overridden
|
||||||
# for each entry. Attributes not already existing
|
# for each entry. Attributes not already existing
|
||||||
# in the entry will be appended to the entry.
|
# 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
|
append: <str/list> # string or list of strings to append to the .gv output
|
||||||
```
|
```
|
||||||
|
|||||||
@ -61,7 +61,7 @@ class Options:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Tweak:
|
class Tweak:
|
||||||
override: Optional[Dict[Designator, Dict[str, str]]] = None
|
override: Optional[Dict[Designator, Dict[str, Optional[str]]]] = None
|
||||||
append: Union[str, List[str], None] = None
|
append: Union[str, List[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -357,7 +357,7 @@ class Harness:
|
|||||||
typecheck(f'tweak.override.{k} value', d, dict)
|
typecheck(f'tweak.override.{k} value', d, dict)
|
||||||
for a, v in d.items():
|
for a, v in d.items():
|
||||||
typecheck(f'tweak.override.{k}.{a} key', a, str)
|
typecheck(f'tweak.override.{k}.{a} key', a, str)
|
||||||
typecheck(f'tweak.override.{k}.{a} value', v, str)
|
typecheck(f'tweak.override.{k}.{a} value', v, (str, type(None)))
|
||||||
|
|
||||||
# Override generated attributes of selected entries matching tweak.override.
|
# Override generated attributes of selected entries matching tweak.override.
|
||||||
for i, entry in enumerate(dot.body):
|
for i, entry in enumerate(dot.body):
|
||||||
@ -367,7 +367,14 @@ class Harness:
|
|||||||
keyword = match and match[2]
|
keyword = match and match[2]
|
||||||
if keyword in self.tweak.override.keys():
|
if keyword in self.tweak.override.keys():
|
||||||
for attr, value in self.tweak.override[keyword].items():
|
for attr, value in self.tweak.override[keyword].items():
|
||||||
# TODO?: If value is None: delete attr?
|
if value is None:
|
||||||
|
entry, n_subs = re.subn(f'( +)?{attr}=("[^"]*"|[^] ]*)(?(1)| *)', '', entry)
|
||||||
|
if n_subs < 1:
|
||||||
|
print(f'Harness.create_graph() warning: {attr} not found in {keyword}!')
|
||||||
|
elif n_subs > 1:
|
||||||
|
print(f'Harness.create_graph() warning: {attr} removed {n_subs} times in {keyword}!')
|
||||||
|
continue
|
||||||
|
|
||||||
if len(value) == 0 or ' ' in value:
|
if len(value) == 0 or ' ' in value:
|
||||||
value = value.replace('"', r'\"')
|
value = value.replace('"', r'\"')
|
||||||
value = f'"{value}"'
|
value = f'"{value}"'
|
||||||
@ -377,6 +384,7 @@ class Harness:
|
|||||||
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(f'Harness.create_graph() warning: {attr} overridden {n_subs} times in {keyword}!')
|
print(f'Harness.create_graph() warning: {attr} overridden {n_subs} times in {keyword}!')
|
||||||
|
|
||||||
dot.body[i] = entry
|
dot.body[i] = entry
|
||||||
|
|
||||||
if self.tweak.append is not None:
|
if self.tweak.append is not None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user