peek-python 1.8.4__tar.gz → 1.8.6.post0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/PKG-INFO +35 -7
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/README.md +34 -6
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/peek/peek.py +74 -41
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/peek_python.egg-info/PKG-INFO +35 -7
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/pyproject.toml +2 -3
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/tests/test_peek.py +33 -4
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/license.txt +0 -0
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/peek/__init__.py +0 -0
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/peek_python.egg-info/SOURCES.txt +0 -0
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/peek_python.egg-info/dependency_links.txt +0 -0
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/peek_python.egg-info/requires.txt +0 -0
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/peek_python.egg-info/top_level.txt +0 -0
- {peek_python-1.8.4 → peek_python-1.8.6.post0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: peek-python
|
|
3
|
-
Version: 1.8.
|
|
3
|
+
Version: 1.8.6.post0
|
|
4
4
|
Summary: peek - debugging and benchmarking made easy
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/peek
|
|
@@ -50,6 +50,8 @@ And on top of that, you get some basic benchmarking functionality.
|
|
|
50
50
|
|
|
51
51
|
* [Using level to control peek output](#Using-level-to-control-peek-output)
|
|
52
52
|
|
|
53
|
+
* [Using color to control peek output](#Using-color-to-control-peek-output)
|
|
54
|
+
|
|
53
55
|
* [Copying to the clipboard](#Copying-to-the-clipboard)
|
|
54
56
|
|
|
55
57
|
* [Speeding up disabled peek](#speeding-up-disabled-peek)
|
|
@@ -340,8 +342,8 @@ sort_dicts sdi False
|
|
|
340
342
|
underscore_numbers un False
|
|
341
343
|
enabled e True
|
|
342
344
|
line_length ll 160
|
|
343
|
-
color col ""
|
|
344
|
-
color_value colv ""
|
|
345
|
+
color col "-"
|
|
346
|
+
color_value colv "-"
|
|
345
347
|
level l 0
|
|
346
348
|
compact c False
|
|
347
349
|
indent i 1
|
|
@@ -480,6 +482,7 @@ Finally, you can specify the following strings:
|
|
|
480
482
|
```
|
|
481
483
|
"stderr" to print to stderr
|
|
482
484
|
"stdout" to print to stdout
|
|
485
|
+
"stdout_nocolor" to print to stdout without any colors
|
|
483
486
|
"null" or "" to completely ignore (dummy) output
|
|
484
487
|
"logging.debug" to use logging.debug
|
|
485
488
|
"logging.info" to use logging.info
|
|
@@ -639,9 +642,9 @@ d=
|
|
|
639
642
|
```
|
|
640
643
|
|
|
641
644
|
## color / col and color_value / colv
|
|
642
|
-
The color attribute is used to specify the
|
|
645
|
+
The color attribute is used to specify the color of the output.
|
|
643
646
|
There's a choice of black, white, red, green, blue, cyan, magenta and yellow.
|
|
644
|
-
To set the color to 'nothing', use
|
|
647
|
+
To set the color to 'nothing', use "-".
|
|
645
648
|
|
|
646
649
|
On top of that, color_value may be used to specify the value part of an output item. By specifying color_value as "" (the default), the value part will be displayed with the same color as the rest of the output.
|
|
647
650
|
|
|
@@ -665,6 +668,8 @@ Of course, color and color_value may be specified in a peek.toml file, to make a
|
|
|
665
668
|
> [!NOTE]
|
|
666
669
|
>
|
|
667
670
|
> The color and color_value attributes are only applied when using stdout as output.
|
|
671
|
+
>
|
|
672
|
+
> Colors can be ignored completely by using `peek.output = "stdout_nocolor"
|
|
668
673
|
|
|
669
674
|
## compact / c
|
|
670
675
|
This attribute is used to specify the compact parameter for `pformat` (see the pprint documentation
|
|
@@ -1098,7 +1103,30 @@ Examples:
|
|
|
1098
1103
|
|
|
1099
1104
|
This will print one line with`1` only.
|
|
1100
1105
|
|
|
1106
|
+
# Using color to control peek output
|
|
1107
|
+
|
|
1108
|
+
The method `peek.show_color()` can be used to show only peek output for certain colors.
|
|
1109
|
+
|
|
1110
|
+
For instance, with `peek.show_color("blue red")`, subsequent peek commands will print only if the color is *blue* or *red*.
|
|
1111
|
+
With `peek.show_color("-")` only not colored output will be shown.
|
|
1112
|
+
|
|
1113
|
+
It is also possible to specify which colors *not* to show. E.g. `peek.show_color("not green yellow"` will show all peeks apart from those in green or yellow. With `peek.show_color("not -")` only colored peeks will be shown.
|
|
1114
|
+
|
|
1115
|
+
With `peek.show_color()` the current value can be queried.
|
|
1116
|
+
|
|
1117
|
+
Finally, `peek.show_color()` can be used as a context manager:
|
|
1118
|
+
```
|
|
1119
|
+
with peek.show_color("blue red"):
|
|
1120
|
+
peek(1, color="blue")
|
|
1121
|
+
peek(2)
|
|
1122
|
+
peek(3)
|
|
1123
|
+
```
|
|
1124
|
+
This will print 1 and 3.
|
|
1125
|
+
|
|
1126
|
+
It is possible to use both `peek.show_level()` and `peek.show_color()` at the same time, but this might be confusing.
|
|
1127
|
+
|
|
1101
1128
|
# Copying to the clipboard
|
|
1129
|
+
|
|
1102
1130
|
It is possible to copy a value to the clipboard. There are two ways:
|
|
1103
1131
|
|
|
1104
1132
|
### With peek(*args, to_clipboard=True)
|
|
@@ -1365,11 +1393,11 @@ suppress f-strings at left hand optional no
|
|
|
1365
1393
|
indentation 4 blanks (overridable) dependent on length of prefix
|
|
1366
1394
|
forking and cloning yes no
|
|
1367
1395
|
test script pytest unittest
|
|
1368
|
-
|
|
1396
|
+
colorize ***) yes, off by default yes, on by default
|
|
1369
1397
|
-------------------------------------------------------------------------------------------
|
|
1370
1398
|
*) under Python <= 3.7, dicts are always sorted (regardless of the sort_dicts attribute
|
|
1371
1399
|
**) under Python <= 3.7, numbers are never underscored (regardless of the underscore_numnbers attribute
|
|
1372
|
-
***) peek allows selection of a
|
|
1400
|
+
***) peek allows selection of a color, whereas IceCream does coloring based on contents.
|
|
1373
1401
|
|
|
1374
1402
|
```
|
|
1375
1403
|
  
|
|
@@ -30,6 +30,8 @@ And on top of that, you get some basic benchmarking functionality.
|
|
|
30
30
|
|
|
31
31
|
* [Using level to control peek output](#Using-level-to-control-peek-output)
|
|
32
32
|
|
|
33
|
+
* [Using color to control peek output](#Using-color-to-control-peek-output)
|
|
34
|
+
|
|
33
35
|
* [Copying to the clipboard](#Copying-to-the-clipboard)
|
|
34
36
|
|
|
35
37
|
* [Speeding up disabled peek](#speeding-up-disabled-peek)
|
|
@@ -320,8 +322,8 @@ sort_dicts sdi False
|
|
|
320
322
|
underscore_numbers un False
|
|
321
323
|
enabled e True
|
|
322
324
|
line_length ll 160
|
|
323
|
-
color col ""
|
|
324
|
-
color_value colv ""
|
|
325
|
+
color col "-"
|
|
326
|
+
color_value colv "-"
|
|
325
327
|
level l 0
|
|
326
328
|
compact c False
|
|
327
329
|
indent i 1
|
|
@@ -460,6 +462,7 @@ Finally, you can specify the following strings:
|
|
|
460
462
|
```
|
|
461
463
|
"stderr" to print to stderr
|
|
462
464
|
"stdout" to print to stdout
|
|
465
|
+
"stdout_nocolor" to print to stdout without any colors
|
|
463
466
|
"null" or "" to completely ignore (dummy) output
|
|
464
467
|
"logging.debug" to use logging.debug
|
|
465
468
|
"logging.info" to use logging.info
|
|
@@ -619,9 +622,9 @@ d=
|
|
|
619
622
|
```
|
|
620
623
|
|
|
621
624
|
## color / col and color_value / colv
|
|
622
|
-
The color attribute is used to specify the
|
|
625
|
+
The color attribute is used to specify the color of the output.
|
|
623
626
|
There's a choice of black, white, red, green, blue, cyan, magenta and yellow.
|
|
624
|
-
To set the color to 'nothing', use
|
|
627
|
+
To set the color to 'nothing', use "-".
|
|
625
628
|
|
|
626
629
|
On top of that, color_value may be used to specify the value part of an output item. By specifying color_value as "" (the default), the value part will be displayed with the same color as the rest of the output.
|
|
627
630
|
|
|
@@ -645,6 +648,8 @@ Of course, color and color_value may be specified in a peek.toml file, to make a
|
|
|
645
648
|
> [!NOTE]
|
|
646
649
|
>
|
|
647
650
|
> The color and color_value attributes are only applied when using stdout as output.
|
|
651
|
+
>
|
|
652
|
+
> Colors can be ignored completely by using `peek.output = "stdout_nocolor"
|
|
648
653
|
|
|
649
654
|
## compact / c
|
|
650
655
|
This attribute is used to specify the compact parameter for `pformat` (see the pprint documentation
|
|
@@ -1078,7 +1083,30 @@ Examples:
|
|
|
1078
1083
|
|
|
1079
1084
|
This will print one line with`1` only.
|
|
1080
1085
|
|
|
1086
|
+
# Using color to control peek output
|
|
1087
|
+
|
|
1088
|
+
The method `peek.show_color()` can be used to show only peek output for certain colors.
|
|
1089
|
+
|
|
1090
|
+
For instance, with `peek.show_color("blue red")`, subsequent peek commands will print only if the color is *blue* or *red*.
|
|
1091
|
+
With `peek.show_color("-")` only not colored output will be shown.
|
|
1092
|
+
|
|
1093
|
+
It is also possible to specify which colors *not* to show. E.g. `peek.show_color("not green yellow"` will show all peeks apart from those in green or yellow. With `peek.show_color("not -")` only colored peeks will be shown.
|
|
1094
|
+
|
|
1095
|
+
With `peek.show_color()` the current value can be queried.
|
|
1096
|
+
|
|
1097
|
+
Finally, `peek.show_color()` can be used as a context manager:
|
|
1098
|
+
```
|
|
1099
|
+
with peek.show_color("blue red"):
|
|
1100
|
+
peek(1, color="blue")
|
|
1101
|
+
peek(2)
|
|
1102
|
+
peek(3)
|
|
1103
|
+
```
|
|
1104
|
+
This will print 1 and 3.
|
|
1105
|
+
|
|
1106
|
+
It is possible to use both `peek.show_level()` and `peek.show_color()` at the same time, but this might be confusing.
|
|
1107
|
+
|
|
1081
1108
|
# Copying to the clipboard
|
|
1109
|
+
|
|
1082
1110
|
It is possible to copy a value to the clipboard. There are two ways:
|
|
1083
1111
|
|
|
1084
1112
|
### With peek(*args, to_clipboard=True)
|
|
@@ -1345,11 +1373,11 @@ suppress f-strings at left hand optional no
|
|
|
1345
1373
|
indentation 4 blanks (overridable) dependent on length of prefix
|
|
1346
1374
|
forking and cloning yes no
|
|
1347
1375
|
test script pytest unittest
|
|
1348
|
-
|
|
1376
|
+
colorize ***) yes, off by default yes, on by default
|
|
1349
1377
|
-------------------------------------------------------------------------------------------
|
|
1350
1378
|
*) under Python <= 3.7, dicts are always sorted (regardless of the sort_dicts attribute
|
|
1351
1379
|
**) under Python <= 3.7, numbers are never underscored (regardless of the underscore_numnbers attribute
|
|
1352
|
-
***) peek allows selection of a
|
|
1380
|
+
***) peek allows selection of a color, whereas IceCream does coloring based on contents.
|
|
1353
1381
|
|
|
1354
1382
|
```
|
|
1355
1383
|
  
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# | .__/ \___| \___||_|\_\
|
|
5
5
|
# |_| like print, but easy.
|
|
6
6
|
|
|
7
|
-
__version__ = "1.8.
|
|
7
|
+
__version__ = "1.8.6"
|
|
8
8
|
|
|
9
9
|
"""
|
|
10
10
|
See https://github.com/salabim/peek for details
|
|
@@ -67,7 +67,7 @@ colors = dict(
|
|
|
67
67
|
cyan="\033[0;36m",
|
|
68
68
|
white="\033[0;37m",
|
|
69
69
|
)
|
|
70
|
-
colors[""] = "\033[0m"
|
|
70
|
+
colors["-"] = "\033[0m"
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
ansi_to_hexa = {
|
|
@@ -94,16 +94,12 @@ def flatten(x):
|
|
|
94
94
|
yield item
|
|
95
95
|
|
|
96
96
|
|
|
97
|
-
# def colorname_to_rgb(colorname):
|
|
98
|
-
# return tuple(int(ansito_rgb[colorname.lower()][i : i + 2], 16) / 255 for i in range(1, 7, 2))
|
|
99
|
-
|
|
100
|
-
|
|
101
97
|
def check_validity(item, value, message=""):
|
|
102
98
|
if value is None:
|
|
103
99
|
return
|
|
104
100
|
|
|
105
101
|
if item in ("color", "color_value"):
|
|
106
|
-
if
|
|
102
|
+
if isinstance(value, str) and value.lower() in colors:
|
|
107
103
|
return
|
|
108
104
|
|
|
109
105
|
elif item in ("line_length", "enforce_line_length"):
|
|
@@ -132,12 +128,12 @@ def check_validity(item, value, message=""):
|
|
|
132
128
|
|
|
133
129
|
|
|
134
130
|
class show_level:
|
|
135
|
-
def __new__(cls, *values, min=None, max=None
|
|
131
|
+
def __new__(cls, *values, min=None, max=None):
|
|
136
132
|
if len(values) == 0 and min is None and max is None:
|
|
137
133
|
return _show_level
|
|
138
134
|
return super().__new__(cls)
|
|
139
135
|
|
|
140
|
-
def __init__(self, *values, min=None, max=None
|
|
136
|
+
def __init__(self, *values, min=None, max=None):
|
|
141
137
|
result = ["False"]
|
|
142
138
|
if min is not None or max is not None:
|
|
143
139
|
if values:
|
|
@@ -178,18 +174,18 @@ class show_level:
|
|
|
178
174
|
float(part0)
|
|
179
175
|
float(part1)
|
|
180
176
|
except ValueError as e:
|
|
181
|
-
raise ValueError(f"incorrect show_level spec: {element} in {values}
|
|
177
|
+
raise ValueError(f"incorrect show_level spec: {element} in {values}") from None
|
|
182
178
|
if float(part0) > float(part1):
|
|
183
|
-
raise ValueError(f"incorrect order in show_level spec: {element} in {values}
|
|
179
|
+
raise ValueError(f"incorrect order in show_level spec: {element} in {values}")
|
|
184
180
|
result.append(f"{part0} <= level <= {part1}")
|
|
185
181
|
else:
|
|
186
182
|
try:
|
|
187
183
|
float(elementx)
|
|
188
184
|
except ValueError as e:
|
|
189
|
-
raise ValueError(f"incorrect show_level spec: {element} in {values}
|
|
185
|
+
raise ValueError(f"incorrect show_level spec: {element} in {values}") from None
|
|
190
186
|
result.append(f"level == {element}")
|
|
191
187
|
else:
|
|
192
|
-
raise ValueError(f"incorrect show_level spec: {element} in {values}
|
|
188
|
+
raise ValueError(f"incorrect show_level spec: {element} in {values}")
|
|
193
189
|
|
|
194
190
|
expression = f"level != '' and ({' or '.join(result)})"
|
|
195
191
|
|
|
@@ -209,6 +205,35 @@ class show_level:
|
|
|
209
205
|
_show_level = self.saved_show_level
|
|
210
206
|
_show_level_expression = self.saved_show_level_expression
|
|
211
207
|
|
|
208
|
+
class show_color:
|
|
209
|
+
def __new__(cls, spec=None):
|
|
210
|
+
if spec is None:
|
|
211
|
+
return _show_color
|
|
212
|
+
return super().__new__(cls)
|
|
213
|
+
|
|
214
|
+
def __init__(self, spec=None):
|
|
215
|
+
global _show_color
|
|
216
|
+
global _show_color_expression
|
|
217
|
+
|
|
218
|
+
if not isinstance(spec,str):
|
|
219
|
+
raise TypeError(f"spec should be a string not {type(spec)}")
|
|
220
|
+
self.saved_show_color = _show_color
|
|
221
|
+
self.saved_show_color_expression = _show_color_expression
|
|
222
|
+
_show_color=spec
|
|
223
|
+
if spec.lower().startswith("not"):
|
|
224
|
+
_show_color_expression = f"color.lower() not in {repr(spec.lower()[3:])}"
|
|
225
|
+
else:
|
|
226
|
+
_show_color_expression = f"color in {repr(spec.lower())}"
|
|
227
|
+
|
|
228
|
+
def __enter__(self):
|
|
229
|
+
...
|
|
230
|
+
|
|
231
|
+
def __exit__(self, exc_type, exc_value, exc_tb):
|
|
232
|
+
global _show_color
|
|
233
|
+
global _show_color_expression
|
|
234
|
+
print("exit",self.saved_show_color)
|
|
235
|
+
_show_color = self.saved_show_color
|
|
236
|
+
_show_color_expression = self.saved_show_color_expression
|
|
212
237
|
|
|
213
238
|
def peek_pformat(obj, width, compact, indent, depth, sort_dicts, underscore_numbers):
|
|
214
239
|
return pprint.pformat(obj, width=width, compact=compact, indent=indent, depth=depth, sort_dicts=sort_dicts, underscore_numbers=underscore_numbers).replace(
|
|
@@ -243,8 +268,8 @@ _fixed_perf_counter = None
|
|
|
243
268
|
_show_level = "-"
|
|
244
269
|
_show_level_expression = "True"
|
|
245
270
|
|
|
246
|
-
|
|
247
|
-
|
|
271
|
+
_show_color = "-"
|
|
272
|
+
_show_color_expression = "True"
|
|
248
273
|
|
|
249
274
|
def fix_perf_counter(val): # for tests
|
|
250
275
|
global _fixed_perf_counter
|
|
@@ -306,8 +331,8 @@ def set_defaults():
|
|
|
306
331
|
default.values_only = False
|
|
307
332
|
default.values_only_for_fstrings = False
|
|
308
333
|
default.return_none = False
|
|
309
|
-
default.color = ""
|
|
310
|
-
default.color_value = ""
|
|
334
|
+
default.color = "-"
|
|
335
|
+
default.color_value = "-"
|
|
311
336
|
default.level = 0
|
|
312
337
|
default.enforce_line_length = False
|
|
313
338
|
default.one_line_per_pairenforce_line_length = False
|
|
@@ -451,13 +476,16 @@ class _Peek:
|
|
|
451
476
|
if item == "show_level":
|
|
452
477
|
raise NameError("reassigning show_level not allowed")
|
|
453
478
|
|
|
479
|
+
if item == "show_color":
|
|
480
|
+
raise NameError("reassigning show_color not allowed")
|
|
481
|
+
|
|
454
482
|
if item in ["_attributes"]:
|
|
455
483
|
super(_Peek, self).__setattr__(item, value)
|
|
456
484
|
else:
|
|
457
485
|
self._attributes[item] = value
|
|
458
486
|
|
|
459
487
|
def do_show(self):
|
|
460
|
-
return eval(_show_level_expression, dict(level=self.level)) and self.enabled
|
|
488
|
+
return eval(_show_level_expression, dict(level=self.level)) and eval(_show_color_expression, dict(color=self.color))and self.enabled
|
|
461
489
|
|
|
462
490
|
def assign(self, shortcuts, source, func):
|
|
463
491
|
for key, value in shortcuts.items():
|
|
@@ -909,9 +937,13 @@ class _Peek:
|
|
|
909
937
|
return (self.prefix() if callable(self.prefix) else self.prefix) + context
|
|
910
938
|
|
|
911
939
|
def add_color_value(self, s):
|
|
912
|
-
|
|
940
|
+
|
|
941
|
+
if self.output != "stdout" or self.as_str:
|
|
942
|
+
return s
|
|
943
|
+
if self.color_value.lower() not in (self.color.lower(),"-"):
|
|
944
|
+
return colors[self.color_value.lower()] + s + colors[self.color.lower()]
|
|
945
|
+
else:
|
|
913
946
|
return s
|
|
914
|
-
return colors[self.color_value] + s + colors[self.color]
|
|
915
947
|
|
|
916
948
|
def do_output(self, s):
|
|
917
949
|
if self.enforce_line_length:
|
|
@@ -922,27 +954,29 @@ class _Peek:
|
|
|
922
954
|
elif self.output == "stderr":
|
|
923
955
|
print(s, file=sys.stderr)
|
|
924
956
|
elif self.output == "stdout":
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
if
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
957
|
+
if self.color!="-" or self.color_value!="-":
|
|
958
|
+
s = colors[self.color.lower()] + s + colors["-"]
|
|
959
|
+
if Pythonista:
|
|
960
|
+
while s:
|
|
961
|
+
for ansi, hexa in ansi_to_hexa.items():
|
|
962
|
+
if s.startswith(ansi):
|
|
963
|
+
if hexa == "":
|
|
964
|
+
console.set_color()
|
|
965
|
+
else:
|
|
966
|
+
rgb = tuple(int(hexa[i : i + 2], 16) / 255 for i in range(1, 7, 2))
|
|
967
|
+
console.set_color(*rgb)
|
|
968
|
+
s = s[len(ansi) :]
|
|
969
|
+
break
|
|
970
|
+
else:
|
|
971
|
+
print(s[0], end="", file=sys.stdout)
|
|
972
|
+
s = s[1:]
|
|
973
|
+
print()
|
|
974
|
+
else:
|
|
975
|
+
print(s)
|
|
941
976
|
else:
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
977
|
+
print(s)
|
|
978
|
+
elif self.output=="stdout_nocolor":
|
|
979
|
+
print(s)
|
|
946
980
|
elif self.output == "logging.debug":
|
|
947
981
|
logging.debug(s)
|
|
948
982
|
elif self.output == "logging.info":
|
|
@@ -961,7 +995,6 @@ class _Peek:
|
|
|
961
995
|
elif isinstance(self.output, Path):
|
|
962
996
|
with self.output.open("a+", encoding="utf-8") as f:
|
|
963
997
|
print(s, file=f)
|
|
964
|
-
|
|
965
998
|
else:
|
|
966
999
|
print(s, file=self.output)
|
|
967
1000
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: peek-python
|
|
3
|
-
Version: 1.8.
|
|
3
|
+
Version: 1.8.6.post0
|
|
4
4
|
Summary: peek - debugging and benchmarking made easy
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/peek
|
|
@@ -50,6 +50,8 @@ And on top of that, you get some basic benchmarking functionality.
|
|
|
50
50
|
|
|
51
51
|
* [Using level to control peek output](#Using-level-to-control-peek-output)
|
|
52
52
|
|
|
53
|
+
* [Using color to control peek output](#Using-color-to-control-peek-output)
|
|
54
|
+
|
|
53
55
|
* [Copying to the clipboard](#Copying-to-the-clipboard)
|
|
54
56
|
|
|
55
57
|
* [Speeding up disabled peek](#speeding-up-disabled-peek)
|
|
@@ -340,8 +342,8 @@ sort_dicts sdi False
|
|
|
340
342
|
underscore_numbers un False
|
|
341
343
|
enabled e True
|
|
342
344
|
line_length ll 160
|
|
343
|
-
color col ""
|
|
344
|
-
color_value colv ""
|
|
345
|
+
color col "-"
|
|
346
|
+
color_value colv "-"
|
|
345
347
|
level l 0
|
|
346
348
|
compact c False
|
|
347
349
|
indent i 1
|
|
@@ -480,6 +482,7 @@ Finally, you can specify the following strings:
|
|
|
480
482
|
```
|
|
481
483
|
"stderr" to print to stderr
|
|
482
484
|
"stdout" to print to stdout
|
|
485
|
+
"stdout_nocolor" to print to stdout without any colors
|
|
483
486
|
"null" or "" to completely ignore (dummy) output
|
|
484
487
|
"logging.debug" to use logging.debug
|
|
485
488
|
"logging.info" to use logging.info
|
|
@@ -639,9 +642,9 @@ d=
|
|
|
639
642
|
```
|
|
640
643
|
|
|
641
644
|
## color / col and color_value / colv
|
|
642
|
-
The color attribute is used to specify the
|
|
645
|
+
The color attribute is used to specify the color of the output.
|
|
643
646
|
There's a choice of black, white, red, green, blue, cyan, magenta and yellow.
|
|
644
|
-
To set the color to 'nothing', use
|
|
647
|
+
To set the color to 'nothing', use "-".
|
|
645
648
|
|
|
646
649
|
On top of that, color_value may be used to specify the value part of an output item. By specifying color_value as "" (the default), the value part will be displayed with the same color as the rest of the output.
|
|
647
650
|
|
|
@@ -665,6 +668,8 @@ Of course, color and color_value may be specified in a peek.toml file, to make a
|
|
|
665
668
|
> [!NOTE]
|
|
666
669
|
>
|
|
667
670
|
> The color and color_value attributes are only applied when using stdout as output.
|
|
671
|
+
>
|
|
672
|
+
> Colors can be ignored completely by using `peek.output = "stdout_nocolor"
|
|
668
673
|
|
|
669
674
|
## compact / c
|
|
670
675
|
This attribute is used to specify the compact parameter for `pformat` (see the pprint documentation
|
|
@@ -1098,7 +1103,30 @@ Examples:
|
|
|
1098
1103
|
|
|
1099
1104
|
This will print one line with`1` only.
|
|
1100
1105
|
|
|
1106
|
+
# Using color to control peek output
|
|
1107
|
+
|
|
1108
|
+
The method `peek.show_color()` can be used to show only peek output for certain colors.
|
|
1109
|
+
|
|
1110
|
+
For instance, with `peek.show_color("blue red")`, subsequent peek commands will print only if the color is *blue* or *red*.
|
|
1111
|
+
With `peek.show_color("-")` only not colored output will be shown.
|
|
1112
|
+
|
|
1113
|
+
It is also possible to specify which colors *not* to show. E.g. `peek.show_color("not green yellow"` will show all peeks apart from those in green or yellow. With `peek.show_color("not -")` only colored peeks will be shown.
|
|
1114
|
+
|
|
1115
|
+
With `peek.show_color()` the current value can be queried.
|
|
1116
|
+
|
|
1117
|
+
Finally, `peek.show_color()` can be used as a context manager:
|
|
1118
|
+
```
|
|
1119
|
+
with peek.show_color("blue red"):
|
|
1120
|
+
peek(1, color="blue")
|
|
1121
|
+
peek(2)
|
|
1122
|
+
peek(3)
|
|
1123
|
+
```
|
|
1124
|
+
This will print 1 and 3.
|
|
1125
|
+
|
|
1126
|
+
It is possible to use both `peek.show_level()` and `peek.show_color()` at the same time, but this might be confusing.
|
|
1127
|
+
|
|
1101
1128
|
# Copying to the clipboard
|
|
1129
|
+
|
|
1102
1130
|
It is possible to copy a value to the clipboard. There are two ways:
|
|
1103
1131
|
|
|
1104
1132
|
### With peek(*args, to_clipboard=True)
|
|
@@ -1365,11 +1393,11 @@ suppress f-strings at left hand optional no
|
|
|
1365
1393
|
indentation 4 blanks (overridable) dependent on length of prefix
|
|
1366
1394
|
forking and cloning yes no
|
|
1367
1395
|
test script pytest unittest
|
|
1368
|
-
|
|
1396
|
+
colorize ***) yes, off by default yes, on by default
|
|
1369
1397
|
-------------------------------------------------------------------------------------------
|
|
1370
1398
|
*) under Python <= 3.7, dicts are always sorted (regardless of the sort_dicts attribute
|
|
1371
1399
|
**) under Python <= 3.7, numbers are never underscored (regardless of the underscore_numnbers attribute
|
|
1372
|
-
***) peek allows selection of a
|
|
1400
|
+
***) peek allows selection of a color, whereas IceCream does coloring based on contents.
|
|
1373
1401
|
|
|
1374
1402
|
```
|
|
1375
1403
|
  
|
|
@@ -8,7 +8,7 @@ authors = [
|
|
|
8
8
|
{name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com"}
|
|
9
9
|
]
|
|
10
10
|
description = "peek - debugging and benchmarking made easy"
|
|
11
|
-
version = "1.8.
|
|
11
|
+
version = "1.8.6-0"
|
|
12
12
|
readme = "README.md"
|
|
13
13
|
requires-python = ">=3.6"
|
|
14
14
|
dependencies = [
|
|
@@ -33,5 +33,4 @@ Repository = "https://github.com/salabim/peek"
|
|
|
33
33
|
packages = ["peek"]
|
|
34
34
|
|
|
35
35
|
[tool.setuptools.package-data]
|
|
36
|
-
"*" = ["*.json"]
|
|
37
|
-
|
|
36
|
+
"*" = ["*.json"]
|
|
@@ -449,7 +449,7 @@ def test_read_toml1():
|
|
|
449
449
|
peek.set_defaults()
|
|
450
450
|
assert peek.default.line_length == 80
|
|
451
451
|
assert peek.default.show_line_number == False
|
|
452
|
-
assert peek.default.color == ""
|
|
452
|
+
assert peek.default.color == "-"
|
|
453
453
|
|
|
454
454
|
with open(toml_filename0, "w") as f:
|
|
455
455
|
print("error = 0", file=f)
|
|
@@ -1096,13 +1096,42 @@ a = 12, b = ['test', 'test', 'test', 'test']
|
|
|
1096
1096
|
)
|
|
1097
1097
|
|
|
1098
1098
|
|
|
1099
|
-
def test_color():
|
|
1100
|
-
assert peek.color==""
|
|
1099
|
+
def test_color(capsys):
|
|
1100
|
+
assert peek.color=="-"
|
|
1101
1101
|
peek.color="red"
|
|
1102
1102
|
assert peek.color=="red"
|
|
1103
1103
|
with pytest.raises(ValueError):
|
|
1104
1104
|
peek.color="wrong"
|
|
1105
|
-
|
|
1105
|
+
|
|
1106
|
+
peek.color="-"
|
|
1107
|
+
peek.output="stdout_nocolor"
|
|
1108
|
+
peek.show_color("- blue yellow black white")
|
|
1109
|
+
peek(peek.show_color())
|
|
1110
|
+
|
|
1111
|
+
for i,color in enumerate("black white red blue green cyan magenta yellow".split()):
|
|
1112
|
+
peek(i, i*i, color=color)
|
|
1113
|
+
|
|
1114
|
+
with peek.show_color("not - blue yellow black white"):
|
|
1115
|
+
peek(peek.show_color())
|
|
1116
|
+
for i,color in enumerate("black white red blue green cyan magenta yellow".split()):
|
|
1117
|
+
peek(i, i*i, color=color)
|
|
1118
|
+
peek.output="stdout"
|
|
1119
|
+
|
|
1120
|
+
out, err = capsys.readouterr()
|
|
1121
|
+
assert out=="""\
|
|
1122
|
+
peek.show_color()='- blue yellow black white'
|
|
1123
|
+
i=0, i*i=0
|
|
1124
|
+
i=1, i*i=1
|
|
1125
|
+
i=3, i*i=9
|
|
1126
|
+
i=7, i*i=49
|
|
1127
|
+
i=2, i*i=4
|
|
1128
|
+
i=4, i*i=16
|
|
1129
|
+
i=5, i*i=25
|
|
1130
|
+
i=6, i*i=36
|
|
1131
|
+
exit - blue yellow black white
|
|
1132
|
+
"""
|
|
1133
|
+
peek.color="-"
|
|
1134
|
+
|
|
1106
1135
|
|
|
1107
1136
|
|
|
1108
1137
|
def test_context_separator(capsys):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|