Skip to content

Commit e90adc7

Browse files
committed
Add linewrap arg in top-level docstring and allow disabling by False
1 parent 0961089 commit e90adc7

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

demo_complex.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
Hovercraft().eels()
77
except:
88
# raise
9-
stackprinter.show(style='darkbg2', reverse=False, suppressed_paths=[r"lib/python.*/site-packages/numpy"])
9+
stackprinter.show(style='darkbg2',
10+
line_wrap=40,
11+
reverse=False,
12+
suppressed_paths=[r"lib/python.*/site-packages/numpy"])

stackprinter/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ def format(thing=None, **kwargs):
106106
Maximum number of characters to be used for each variable value.
107107
Default: 500
108108
109+
line_wrap: int (default 60)
110+
Limit how many columns are available to print each variable
111+
(excluding its name). Set to 0 or False to disable wrapping.
112+
109113
suppressed_paths: list of regex patterns
110114
Set less verbose formatting for frames whose code lives in certain paths
111115
(e.g. library code). Files whose path matches any of the given regex

stackprinter/frame_formatting.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class FrameFormatter():
2222
val_tpl = ' ' * var_indent + "%s = %s\n"
2323

2424
def __init__(self, source_lines=5, source_lines_after=1,
25-
show_signature=True, show_vals='like_source', truncate_vals=500, line_wrap: int = 60,
25+
show_signature=True, show_vals='like_source',
26+
truncate_vals=500, line_wrap: int = 60,
2627
suppressed_paths=None):
2728
"""
2829
Formatter for single frames.
@@ -56,7 +57,8 @@ def __init__(self, source_lines=5, source_lines_after=1,
5657
Maximum number of characters to be used for each variable value
5758
5859
line_wrap: int (default 60)
59-
insert linebreaks after this nr of characters, use 0 to never insert a linebreak
60+
insert linebreaks after this nr of characters, use 0 to never insert
61+
a linebreak
6062
6163
suppressed_paths: list of regex patterns
6264
Set less verbose formatting for frames whose code lives in certain paths
@@ -86,7 +88,7 @@ def __init__(self, source_lines=5, source_lines_after=1,
8688
self.show_vals = show_vals
8789
self.truncate_vals = truncate_vals
8890
self.line_wrap = line_wrap
89-
self.suppressed_paths = suppressed_paths # already compile regexes and make a `match` callable?
91+
self.suppressed_paths = suppressed_paths
9092

9193
def __call__(self, frame, lineno=None):
9294
"""
@@ -178,7 +180,8 @@ def _format_assignments(self, assignments):
178180
for name, value in assignments.items():
179181
val_str = format_value(value,
180182
indent=len(name) + self.var_indent + 3,
181-
truncation=self.truncate_vals, wrap=self.line_wrap)
183+
truncation=self.truncate_vals,
184+
wrap=self.line_wrap)
182185
assign_str = self.val_tpl % (name, val_str)
183186
msgs.append(assign_str)
184187
if len(msgs) > 0:
@@ -333,7 +336,8 @@ def _format_assignments(self, assignments, colormap):
333336
for name, value in assignments.items():
334337
val_str = format_value(value,
335338
indent=len(name) + self.var_indent + 3,
336-
truncation=self.truncate_vals, wrap=self.line_wrap)
339+
truncation=self.truncate_vals,
340+
wrap=self.line_wrap)
337341
assign_str = self.val_tpl % (name, val_str)
338342
hue, sat, val, bold = colormap.get(name, self.colors['var_invisible'])
339343
clr_str = get_ansi_tpl(hue, sat, val, bold) % assign_str

stackprinter/prettyprinting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def truncate(string, n):
241241

242242

243243
def wrap_lines(string, max_width=80):
244-
if max_width <= 0:
244+
if not max_width or max_width <= 0:
245245
return string
246246

247247
def wrap(lines):

0 commit comments

Comments
 (0)