[scripts/pyprint] update maxlen selection
- consider only values smaller than 'lmax' instead of taking the max of all lengths and trimming that - remove 'lmin'
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
def pyprint(obj, indent=0, lmin=9, lmax=16):
|
def pyprint(obj, indent=0, lmax=16):
|
||||||
|
|
||||||
if isinstance(obj, str):
|
if isinstance(obj, str):
|
||||||
if obj.startswith("lit:"):
|
if obj.startswith("lit:"):
|
||||||
@@ -49,13 +49,7 @@ def pyprint(obj, indent=0, lmin=9, lmax=16):
|
|||||||
|
|
||||||
if len(obj) >= 2 or not indent:
|
if len(obj) >= 2 or not indent:
|
||||||
ws = " " * indent
|
ws = " " * indent
|
||||||
|
key_maxlen = max(kl for kl in map(len, obj) if kl <= lmax)
|
||||||
lkey = max(map(len, obj))
|
|
||||||
if not indent:
|
|
||||||
if lkey < lmin:
|
|
||||||
lkey = lmin
|
|
||||||
elif lkey > lmax:
|
|
||||||
lkey = lmax
|
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
lines.append("{")
|
lines.append("{")
|
||||||
@@ -65,7 +59,7 @@ def pyprint(obj, indent=0, lmin=9, lmax=16):
|
|||||||
else:
|
else:
|
||||||
lines.append(
|
lines.append(
|
||||||
f'''{ws} "{key}"'''
|
f'''{ws} "{key}"'''
|
||||||
f'''{' '*(lkey - len(key))}: '''
|
f'''{' '*(key_maxlen - len(key))}: '''
|
||||||
f'''{pyprint(value, indent+4)},'''
|
f'''{pyprint(value, indent+4)},'''
|
||||||
)
|
)
|
||||||
lines.append(f'''{ws}}}''')
|
lines.append(f'''{ws}}}''')
|
||||||
|
|||||||
Reference in New Issue
Block a user