peek-python 25.0.6__tar.gz → 25.0.7__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-25.0.6 → peek_python-25.0.7}/PKG-INFO +33 -20
- {peek_python-25.0.6 → peek_python-25.0.7}/README.md +32 -19
- {peek_python-25.0.6 → peek_python-25.0.7}/peek/peek.py +45 -57
- {peek_python-25.0.6 → peek_python-25.0.7}/peek_python.egg-info/PKG-INFO +33 -20
- {peek_python-25.0.6 → peek_python-25.0.7}/pyproject.toml +1 -1
- {peek_python-25.0.6 → peek_python-25.0.7}/tests/test_peek.py +74 -49
- {peek_python-25.0.6 → peek_python-25.0.7}/license.txt +0 -0
- {peek_python-25.0.6 → peek_python-25.0.7}/peek/__init__.py +0 -0
- {peek_python-25.0.6 → peek_python-25.0.7}/peek_python.egg-info/SOURCES.txt +0 -0
- {peek_python-25.0.6 → peek_python-25.0.7}/peek_python.egg-info/dependency_links.txt +0 -0
- {peek_python-25.0.6 → peek_python-25.0.7}/peek_python.egg-info/requires.txt +0 -0
- {peek_python-25.0.6 → peek_python-25.0.7}/peek_python.egg-info/top_level.txt +0 -0
- {peek_python-25.0.6 → peek_python-25.0.7}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: peek-python
|
|
3
|
-
Version: 25.0.
|
|
3
|
+
Version: 25.0.7
|
|
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
|
|
@@ -343,7 +343,7 @@ a number of configuration attributes:
|
|
|
343
343
|
attribute alternative default
|
|
344
344
|
------------------------------------------------------
|
|
345
345
|
color col "-"
|
|
346
|
-
color_value col_val "
|
|
346
|
+
color_value col_val ""
|
|
347
347
|
compact - False
|
|
348
348
|
context_separator cs " ==> "
|
|
349
349
|
depth - 1000000
|
|
@@ -372,7 +372,8 @@ show_time st False
|
|
|
372
372
|
show_traceback - False
|
|
373
373
|
sort_dicts - False
|
|
374
374
|
to_clipboard clip False
|
|
375
|
-
underscore_numbers un False
|
|
375
|
+
underscore_numbers un False
|
|
376
|
+
use_color - True
|
|
376
377
|
values_only vo False
|
|
377
378
|
value_only_for_fstrings voff False
|
|
378
379
|
wrap_indent - " "
|
|
@@ -691,11 +692,6 @@ will result in:
|
|
|
691
692
|
|
|
692
693
|
Of course, color and color_value may be specified in a peek.toml file, to make all peek output in a specified color.
|
|
693
694
|
|
|
694
|
-
> [!NOTE]
|
|
695
|
-
>
|
|
696
|
-
> The color and color_value attributes are only applied when using stdout as output.
|
|
697
|
-
>
|
|
698
|
-
> Colors can be ignored completely by using `peek.output = "stdout_nocolor"`.
|
|
699
695
|
|
|
700
696
|
------
|
|
701
697
|
|
|
@@ -717,8 +713,24 @@ repr(peek.ANSI.red)='\x1b[1;31m'
|
|
|
717
713
|
|
|
718
714
|
------
|
|
719
715
|
|
|
716
|
+
## use_color
|
|
717
|
+
|
|
718
|
+
Colors can be ignored completely by using `peek.use_color = False`.
|
|
719
|
+
|
|
720
|
+
So,
|
|
721
|
+
|
|
722
|
+
```
|
|
723
|
+
peek(hello, color="red")
|
|
724
|
+
peek.use_color = False
|
|
725
|
+
peek(hello, color="red")
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
will print `hello=world` once in red and once without color.
|
|
729
|
+
|
|
730
|
+
Of course, `use_color` can be specified in a peek.toml file.
|
|
720
731
|
|
|
721
732
|
## compact
|
|
733
|
+
|
|
722
734
|
This attribute is used to specify the compact parameter for `pformat` (see the pprint documentation
|
|
723
735
|
for details). `compact` is False by default.
|
|
724
736
|
|
|
@@ -1025,7 +1037,9 @@ for i in range(50):
|
|
|
1025
1037
|
time.sleep(0.1)
|
|
1026
1038
|
peek('')
|
|
1027
1039
|
```
|
|
1028
|
-
|
|
1040
|
+
> [!NOTE]
|
|
1041
|
+
>
|
|
1042
|
+
> The `end` parameter will not be only applied when output is "logging.debug", "logging.info", "logging.warning", "logging.error" or "logging.critical".
|
|
1029
1043
|
|
|
1030
1044
|
> [!NOTE]
|
|
1031
1045
|
>
|
|
@@ -1077,7 +1091,7 @@ You can also use peek.print (see below).
|
|
|
1077
1091
|
|
|
1078
1092
|
> [!TIP]
|
|
1079
1093
|
>
|
|
1080
|
-
> Of course,
|
|
1094
|
+
> Of course, `print_like` can be put in a **peek.toml** file.
|
|
1081
1095
|
|
|
1082
1096
|
# Use peek.print to use peek like print with extras
|
|
1083
1097
|
The method `peek.print` allows peek to be used as alternative to print. Note that `peek.print` applies the `color`, `context_separator`, `enabled`, `end`, `filter` and `output`, `separator_print`, `show_delta` and `show_time`. It is also possible to redirect the output to a string with `as_str`.
|
|
@@ -1173,23 +1187,22 @@ hello='world'
|
|
|
1173
1187
|
|
|
1174
1188
|
Note that if enabled=False, the call will return the null string (`""`).
|
|
1175
1189
|
|
|
1176
|
-
|
|
1190
|
+
By default, a string will contain embedded ANSI color escape strings if either `color` or `color_value` specifies a color. By setting `use_color` to False, these escape sequences will be suppressed.
|
|
1191
|
+
|
|
1177
1192
|
```
|
|
1178
1193
|
hello = "world"
|
|
1179
|
-
s = peek(hello, color="red", color_value="green",
|
|
1180
|
-
print(repr(s)
|
|
1194
|
+
s = peek(hello, color="red", color_value="green", as_str=True)
|
|
1195
|
+
print(repr(s))
|
|
1196
|
+
peek.use_color = False
|
|
1197
|
+
s = peek(hello, color="red", color_value="green", as_str=True)
|
|
1198
|
+
print(repr(s))
|
|
1181
1199
|
```
|
|
1182
1200
|
prints
|
|
1183
1201
|
```
|
|
1184
|
-
|
|
1202
|
+
'\x1b[1;31mhello=\x1b[1;32mworld\x1b[1;31m\x1b[0m\n'
|
|
1203
|
+
'hello=world\n'
|
|
1185
1204
|
```
|
|
1186
1205
|
|
|
1187
|
-
> [!NOTE]
|
|
1188
|
-
>
|
|
1189
|
-
> Specifying both `as_str` and `as_colored_str` is not allowed.
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
1206
|
# Disabling peek's output
|
|
1194
1207
|
|
|
1195
1208
|
```
|
|
@@ -323,7 +323,7 @@ a number of configuration attributes:
|
|
|
323
323
|
attribute alternative default
|
|
324
324
|
------------------------------------------------------
|
|
325
325
|
color col "-"
|
|
326
|
-
color_value col_val "
|
|
326
|
+
color_value col_val ""
|
|
327
327
|
compact - False
|
|
328
328
|
context_separator cs " ==> "
|
|
329
329
|
depth - 1000000
|
|
@@ -352,7 +352,8 @@ show_time st False
|
|
|
352
352
|
show_traceback - False
|
|
353
353
|
sort_dicts - False
|
|
354
354
|
to_clipboard clip False
|
|
355
|
-
underscore_numbers un False
|
|
355
|
+
underscore_numbers un False
|
|
356
|
+
use_color - True
|
|
356
357
|
values_only vo False
|
|
357
358
|
value_only_for_fstrings voff False
|
|
358
359
|
wrap_indent - " "
|
|
@@ -671,11 +672,6 @@ will result in:
|
|
|
671
672
|
|
|
672
673
|
Of course, color and color_value may be specified in a peek.toml file, to make all peek output in a specified color.
|
|
673
674
|
|
|
674
|
-
> [!NOTE]
|
|
675
|
-
>
|
|
676
|
-
> The color and color_value attributes are only applied when using stdout as output.
|
|
677
|
-
>
|
|
678
|
-
> Colors can be ignored completely by using `peek.output = "stdout_nocolor"`.
|
|
679
675
|
|
|
680
676
|
------
|
|
681
677
|
|
|
@@ -697,8 +693,24 @@ repr(peek.ANSI.red)='\x1b[1;31m'
|
|
|
697
693
|
|
|
698
694
|
------
|
|
699
695
|
|
|
696
|
+
## use_color
|
|
697
|
+
|
|
698
|
+
Colors can be ignored completely by using `peek.use_color = False`.
|
|
699
|
+
|
|
700
|
+
So,
|
|
701
|
+
|
|
702
|
+
```
|
|
703
|
+
peek(hello, color="red")
|
|
704
|
+
peek.use_color = False
|
|
705
|
+
peek(hello, color="red")
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
will print `hello=world` once in red and once without color.
|
|
709
|
+
|
|
710
|
+
Of course, `use_color` can be specified in a peek.toml file.
|
|
700
711
|
|
|
701
712
|
## compact
|
|
713
|
+
|
|
702
714
|
This attribute is used to specify the compact parameter for `pformat` (see the pprint documentation
|
|
703
715
|
for details). `compact` is False by default.
|
|
704
716
|
|
|
@@ -1005,7 +1017,9 @@ for i in range(50):
|
|
|
1005
1017
|
time.sleep(0.1)
|
|
1006
1018
|
peek('')
|
|
1007
1019
|
```
|
|
1008
|
-
|
|
1020
|
+
> [!NOTE]
|
|
1021
|
+
>
|
|
1022
|
+
> The `end` parameter will not be only applied when output is "logging.debug", "logging.info", "logging.warning", "logging.error" or "logging.critical".
|
|
1009
1023
|
|
|
1010
1024
|
> [!NOTE]
|
|
1011
1025
|
>
|
|
@@ -1057,7 +1071,7 @@ You can also use peek.print (see below).
|
|
|
1057
1071
|
|
|
1058
1072
|
> [!TIP]
|
|
1059
1073
|
>
|
|
1060
|
-
> Of course,
|
|
1074
|
+
> Of course, `print_like` can be put in a **peek.toml** file.
|
|
1061
1075
|
|
|
1062
1076
|
# Use peek.print to use peek like print with extras
|
|
1063
1077
|
The method `peek.print` allows peek to be used as alternative to print. Note that `peek.print` applies the `color`, `context_separator`, `enabled`, `end`, `filter` and `output`, `separator_print`, `show_delta` and `show_time`. It is also possible to redirect the output to a string with `as_str`.
|
|
@@ -1153,23 +1167,22 @@ hello='world'
|
|
|
1153
1167
|
|
|
1154
1168
|
Note that if enabled=False, the call will return the null string (`""`).
|
|
1155
1169
|
|
|
1156
|
-
|
|
1170
|
+
By default, a string will contain embedded ANSI color escape strings if either `color` or `color_value` specifies a color. By setting `use_color` to False, these escape sequences will be suppressed.
|
|
1171
|
+
|
|
1157
1172
|
```
|
|
1158
1173
|
hello = "world"
|
|
1159
|
-
s = peek(hello, color="red", color_value="green",
|
|
1160
|
-
print(repr(s)
|
|
1174
|
+
s = peek(hello, color="red", color_value="green", as_str=True)
|
|
1175
|
+
print(repr(s))
|
|
1176
|
+
peek.use_color = False
|
|
1177
|
+
s = peek(hello, color="red", color_value="green", as_str=True)
|
|
1178
|
+
print(repr(s))
|
|
1161
1179
|
```
|
|
1162
1180
|
prints
|
|
1163
1181
|
```
|
|
1164
|
-
|
|
1182
|
+
'\x1b[1;31mhello=\x1b[1;32mworld\x1b[1;31m\x1b[0m\n'
|
|
1183
|
+
'hello=world\n'
|
|
1165
1184
|
```
|
|
1166
1185
|
|
|
1167
|
-
> [!NOTE]
|
|
1168
|
-
>
|
|
1169
|
-
> Specifying both `as_str` and `as_colored_str` is not allowed.
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
1186
|
# Disabling peek's output
|
|
1174
1187
|
|
|
1175
1188
|
```
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# | .__/ \___| \___||_|\_\
|
|
5
5
|
# |_| like print, but easy.
|
|
6
6
|
|
|
7
|
-
__version__ = "25.0.
|
|
7
|
+
__version__ = "25.0.7"
|
|
8
8
|
|
|
9
9
|
"""
|
|
10
10
|
See https://github.com/salabim/peek for details
|
|
@@ -86,6 +86,7 @@ class _Peek:
|
|
|
86
86
|
("sort_dicts", "", False),
|
|
87
87
|
("to_clipboard", "clip", False),
|
|
88
88
|
("underscore_numbers", "un", False),
|
|
89
|
+
("use_color", "", True),
|
|
89
90
|
("values_only", "vo", False),
|
|
90
91
|
("values_only_for_fstrings", "voff", False),
|
|
91
92
|
("wrap_indent", "", " "),
|
|
@@ -94,7 +95,7 @@ class _Peek:
|
|
|
94
95
|
name_alias = {name: alias for (name, alias, default) in name_alias_default}
|
|
95
96
|
name_default = {name: default for (name, alias, default) in name_alias_default}
|
|
96
97
|
alias_default = {alias: default for (name, alias, default) in name_alias_default if alias}
|
|
97
|
-
name_and_alias_default =
|
|
98
|
+
name_and_alias_default = name_default | alias_default
|
|
98
99
|
|
|
99
100
|
_fixed_perf_counter = None
|
|
100
101
|
|
|
@@ -140,7 +141,7 @@ class _Peek:
|
|
|
140
141
|
"\033[0m": (),
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
ANSI=types.SimpleNamespace(**_color_name_to_ANSI)
|
|
144
|
+
ANSI = types.SimpleNamespace(**_color_name_to_ANSI)
|
|
144
145
|
|
|
145
146
|
codes = {}
|
|
146
147
|
|
|
@@ -174,7 +175,7 @@ class _Peek:
|
|
|
174
175
|
return
|
|
175
176
|
|
|
176
177
|
if name in ("color", "color_value"):
|
|
177
|
-
if isinstance(value, str) and value
|
|
178
|
+
if isinstance(value, str) and value in _Peek._color_name_to_ANSI:
|
|
178
179
|
return
|
|
179
180
|
|
|
180
181
|
elif name == "delta":
|
|
@@ -249,7 +250,7 @@ class _Peek:
|
|
|
249
250
|
return {}
|
|
250
251
|
|
|
251
252
|
@staticmethod
|
|
252
|
-
def print_pythonista_color(s, end="\n"):
|
|
253
|
+
def print_pythonista_color(s, end="\n", file=sys.stdout):
|
|
253
254
|
while s:
|
|
254
255
|
for ansi, rgb in _Peek._ANSI_to_rgb.items():
|
|
255
256
|
if s.startswith(ansi):
|
|
@@ -257,9 +258,9 @@ class _Peek:
|
|
|
257
258
|
s = s[len(ansi) :]
|
|
258
259
|
break
|
|
259
260
|
else:
|
|
260
|
-
print(s[0], end="")
|
|
261
|
+
print(s[0], end="", file=file)
|
|
261
262
|
s = s[1:]
|
|
262
|
-
print("", end=end)
|
|
263
|
+
print("", end=end, file=file)
|
|
263
264
|
|
|
264
265
|
@staticmethod
|
|
265
266
|
def return_args(args, return_none):
|
|
@@ -290,7 +291,7 @@ class _Peek:
|
|
|
290
291
|
|
|
291
292
|
def clone(self, **kwargs):
|
|
292
293
|
clone = _Peek(parent=self._parent)
|
|
293
|
-
clone._attributes =
|
|
294
|
+
clone._attributes = self._attributes | _Peek.spec_to_attributes(**kwargs)
|
|
294
295
|
return clone
|
|
295
296
|
|
|
296
297
|
def configure(self, **kwargs):
|
|
@@ -315,16 +316,7 @@ class _Peek:
|
|
|
315
316
|
return self.__getattribute__(item)
|
|
316
317
|
|
|
317
318
|
def __setattr__(self, item, value):
|
|
318
|
-
if item in (
|
|
319
|
-
"_parent",
|
|
320
|
-
"_is_context_manager",
|
|
321
|
-
"_line_number_with_filename_and_parent",
|
|
322
|
-
"_save_traceback",
|
|
323
|
-
"_enter_time",
|
|
324
|
-
"_as_str",
|
|
325
|
-
"_as_colored_str",
|
|
326
|
-
"_attributes",
|
|
327
|
-
):
|
|
319
|
+
if item in ("_parent", "_is_context_manager", "_line_number_with_filename_and_parent", "_save_traceback", "_enter_time", "_as_str", "_attributes"):
|
|
328
320
|
return super().__setattr__(item, value)
|
|
329
321
|
self._attributes.update(_Peek.spec_to_attributes(**{item: value}))
|
|
330
322
|
|
|
@@ -338,6 +330,7 @@ class _Peek:
|
|
|
338
330
|
pairs = [
|
|
339
331
|
str(name) + "=" + repr(getattr(self, "delta1") if name == "delta" else getattr(self, name)) for name in _Peek.name_default if name != "serialize"
|
|
340
332
|
]
|
|
333
|
+
|
|
341
334
|
return "peek with attributes:\n " + "\n ".join(pairs) + ")"
|
|
342
335
|
|
|
343
336
|
def fix_perf_counter(self, val): # for tests
|
|
@@ -349,14 +342,14 @@ class _Peek:
|
|
|
349
342
|
return False
|
|
350
343
|
return self.enabled
|
|
351
344
|
|
|
352
|
-
def print(self, *args, as_str=False,
|
|
345
|
+
def print(self, *args, as_str=False, **kwargs):
|
|
353
346
|
if "print" in kwargs and "print_like" in kwargs:
|
|
354
347
|
raise AttributeError("both print_like and print specified")
|
|
355
348
|
if not "print" in kwargs and not "print_like" in kwargs:
|
|
356
349
|
kwargs["print_like"] = True
|
|
357
|
-
return self(*args, as_str=as_str,
|
|
350
|
+
return self(*args, as_str=as_str, **kwargs)
|
|
358
351
|
|
|
359
|
-
def __call__(self, *args, as_str=False,
|
|
352
|
+
def __call__(self, *args, as_str=False, _via_module=False, **kwargs):
|
|
360
353
|
def add_to_pairs(pairs, left, right):
|
|
361
354
|
if right in (locals, globals, vars):
|
|
362
355
|
frame = inspect.currentframe().f_back.f_back
|
|
@@ -371,11 +364,7 @@ class _Peek:
|
|
|
371
364
|
any_args = bool(args)
|
|
372
365
|
this = self.fork(**kwargs)
|
|
373
366
|
|
|
374
|
-
if as_str and as_colored_str:
|
|
375
|
-
raise ValueError("not allowed to use both as_str and as_colored_str")
|
|
376
|
-
|
|
377
367
|
this._as_str = as_str
|
|
378
|
-
this._as_colored_str = as_colored_str
|
|
379
368
|
|
|
380
369
|
if this.print_like:
|
|
381
370
|
seps = [name for name in ("sep", "separator") if name in kwargs]
|
|
@@ -394,7 +383,7 @@ class _Peek:
|
|
|
394
383
|
args = [this.separator_print.join(map(str, args))]
|
|
395
384
|
|
|
396
385
|
if len(args) != 0 and not this.do_show():
|
|
397
|
-
if as_str
|
|
386
|
+
if as_str:
|
|
398
387
|
return ""
|
|
399
388
|
else:
|
|
400
389
|
return _Peek.return_args(args, this.return_none)
|
|
@@ -463,8 +452,8 @@ class _Peek:
|
|
|
463
452
|
else:
|
|
464
453
|
this_line_prev = ""
|
|
465
454
|
if this_line.startswith("@") or this_line_prev.startswith("@"):
|
|
466
|
-
if as_str
|
|
467
|
-
raise TypeError("as_str
|
|
455
|
+
if as_str:
|
|
456
|
+
raise TypeError("as_str may not be True when peek used as decorator")
|
|
468
457
|
if any_args:
|
|
469
458
|
raise TypeError("non-keyword arguments are not allowed when peek used as decorator")
|
|
470
459
|
|
|
@@ -513,8 +502,8 @@ class _Peek:
|
|
|
513
502
|
this._line_number_with_filename_and_parent = f"#{line_number}{filename_name}{parent_function}"
|
|
514
503
|
|
|
515
504
|
if this_line.startswith("with ") or this_line.startswith("with\t"):
|
|
516
|
-
if as_str
|
|
517
|
-
raise TypeError("as_str
|
|
505
|
+
if as_str:
|
|
506
|
+
raise TypeError("as_str may not be True when peek used as context manager")
|
|
518
507
|
if any_args:
|
|
519
508
|
raise TypeError("non-keyword arguments are not allowed when peek used as context manager")
|
|
520
509
|
|
|
@@ -522,7 +511,7 @@ class _Peek:
|
|
|
522
511
|
return this
|
|
523
512
|
|
|
524
513
|
if not this.do_show():
|
|
525
|
-
if as_str
|
|
514
|
+
if as_str:
|
|
526
515
|
return ""
|
|
527
516
|
else:
|
|
528
517
|
return _Peek.return_args(args, this.return_none)
|
|
@@ -560,12 +549,17 @@ class _Peek:
|
|
|
560
549
|
add_to_pairs(pairs, left, right)
|
|
561
550
|
|
|
562
551
|
just_one_line = False
|
|
552
|
+
if (not this.use_color) or this.color in ("", "-"):
|
|
553
|
+
out = ""
|
|
554
|
+
else:
|
|
555
|
+
out = _Peek._color_name_to_ANSI[this.color.lower()]
|
|
556
|
+
|
|
563
557
|
if not (len(pairs) > 1 and this.separator == ""):
|
|
564
558
|
if not any("\n" in pair.left for pair in pairs):
|
|
565
559
|
as_one_line = context + this.separator.join(pair.left + this.serialize_kwargs(obj=pair.right, width=10000) for pair in pairs)
|
|
566
560
|
# as_one_line = context + this.separator.join(pair.left + (this.serialize_kwargs(obj=pair.right, width=10000)) for pair in pairs)
|
|
567
561
|
if len(as_one_line) <= this.line_length and "\n" not in as_one_line:
|
|
568
|
-
out
|
|
562
|
+
out += as_one_line
|
|
569
563
|
just_one_line = True
|
|
570
564
|
|
|
571
565
|
if not just_one_line:
|
|
@@ -609,7 +603,7 @@ class _Peek:
|
|
|
609
603
|
for s in line.splitlines():
|
|
610
604
|
lines.append(indent2 + s)
|
|
611
605
|
|
|
612
|
-
out
|
|
606
|
+
out += "\n".join(line.rstrip() for line in lines)
|
|
613
607
|
|
|
614
608
|
else:
|
|
615
609
|
if not this.show_line_number: # if "n" or "no parent", keep that info
|
|
@@ -619,18 +613,15 @@ class _Peek:
|
|
|
619
613
|
if this.show_traceback:
|
|
620
614
|
out += this.traceback()
|
|
621
615
|
|
|
616
|
+
if this.use_color and this.color not in ("", "-"):
|
|
617
|
+
out += _Peek._color_name_to_ANSI["-"]
|
|
618
|
+
|
|
622
619
|
if as_str:
|
|
623
620
|
if this.do_show():
|
|
624
621
|
return out + this.end
|
|
625
622
|
else:
|
|
626
623
|
return ""
|
|
627
624
|
|
|
628
|
-
if as_colored_str:
|
|
629
|
-
if this.do_show():
|
|
630
|
-
return this._color_name_to_ANSI[this.color.lower()] + out + this.end + this._color_name_to_ANSI["-"]
|
|
631
|
-
else:
|
|
632
|
-
return ""
|
|
633
|
-
|
|
634
625
|
if this.to_clipboard:
|
|
635
626
|
peek.copy_to_clipboard(pairs[-1].right if "pairs" in locals() else "", confirm=False)
|
|
636
627
|
this.do_output(out)
|
|
@@ -678,12 +669,17 @@ class _Peek:
|
|
|
678
669
|
return self.prefix + context
|
|
679
670
|
|
|
680
671
|
def add_color_value(self, s):
|
|
681
|
-
if
|
|
672
|
+
if not self.use_color:
|
|
682
673
|
return s
|
|
683
|
-
if self.color_value
|
|
684
|
-
|
|
674
|
+
if self.color_value == "":
|
|
675
|
+
...
|
|
676
|
+
elif self.color_value == "-":
|
|
677
|
+
if self.color not in ("", "-"):
|
|
678
|
+
s = _Peek._color_name_to_ANSI["-"] + s + _Peek._color_name_to_ANSI[self.color]
|
|
685
679
|
else:
|
|
686
|
-
|
|
680
|
+
if self.color_value != self.color:
|
|
681
|
+
s = _Peek._color_name_to_ANSI[self.color_value] + s + _Peek._color_name_to_ANSI[self.color]
|
|
682
|
+
return s
|
|
687
683
|
|
|
688
684
|
def do_output(self, s):
|
|
689
685
|
if self.do_show():
|
|
@@ -693,19 +689,12 @@ class _Peek:
|
|
|
693
689
|
self.output(s, end=self.end)
|
|
694
690
|
else:
|
|
695
691
|
self.output(s + self.end)
|
|
696
|
-
elif self.output
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
s = self._color_name_to_ANSI[self.color.lower()] + s + self.end + self._color_name_to_ANSI["-"]
|
|
701
|
-
if Pythonista:
|
|
702
|
-
_Peek.print_pythonista_color(s, end="")
|
|
703
|
-
else:
|
|
704
|
-
print(s, end="")
|
|
692
|
+
elif self.output in ("stdout", "stderr"):
|
|
693
|
+
file = sys.stdout if self.output == "stdout" else sys.stderr
|
|
694
|
+
if Pythonista:
|
|
695
|
+
_Peek.print_pythonista_color(s, end=self.end, file=file)
|
|
705
696
|
else:
|
|
706
|
-
print(s, end=self.end)
|
|
707
|
-
elif self.output == "stdout_nocolor":
|
|
708
|
-
print(s, end=self.end)
|
|
697
|
+
print(s, end=self.end, file=file)
|
|
709
698
|
elif self.output == "logging.debug":
|
|
710
699
|
logging.debug(s)
|
|
711
700
|
elif self.output == "logging.info":
|
|
@@ -779,7 +768,7 @@ class _Peek:
|
|
|
779
768
|
|
|
780
769
|
_Peek.in_read_toml_message = ""
|
|
781
770
|
_peek_no_toml = _Peek(**_Peek.name_default)
|
|
782
|
-
_peek_toml = _Peek(**
|
|
771
|
+
_peek_toml = _Peek(**(_Peek.name_default | _Peek.read_toml()))
|
|
783
772
|
_Peek.in_read_toml_message = ""
|
|
784
773
|
peek = _peek_toml.new()
|
|
785
774
|
builtins.peek = peek
|
|
@@ -804,4 +793,3 @@ class _PeekModule(types.ModuleType):
|
|
|
804
793
|
|
|
805
794
|
if __name__ != "__main__":
|
|
806
795
|
sys.modules["peek"].__class__ = _PeekModule
|
|
807
|
-
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: peek-python
|
|
3
|
-
Version: 25.0.
|
|
3
|
+
Version: 25.0.7
|
|
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
|
|
@@ -343,7 +343,7 @@ a number of configuration attributes:
|
|
|
343
343
|
attribute alternative default
|
|
344
344
|
------------------------------------------------------
|
|
345
345
|
color col "-"
|
|
346
|
-
color_value col_val "
|
|
346
|
+
color_value col_val ""
|
|
347
347
|
compact - False
|
|
348
348
|
context_separator cs " ==> "
|
|
349
349
|
depth - 1000000
|
|
@@ -372,7 +372,8 @@ show_time st False
|
|
|
372
372
|
show_traceback - False
|
|
373
373
|
sort_dicts - False
|
|
374
374
|
to_clipboard clip False
|
|
375
|
-
underscore_numbers un False
|
|
375
|
+
underscore_numbers un False
|
|
376
|
+
use_color - True
|
|
376
377
|
values_only vo False
|
|
377
378
|
value_only_for_fstrings voff False
|
|
378
379
|
wrap_indent - " "
|
|
@@ -691,11 +692,6 @@ will result in:
|
|
|
691
692
|
|
|
692
693
|
Of course, color and color_value may be specified in a peek.toml file, to make all peek output in a specified color.
|
|
693
694
|
|
|
694
|
-
> [!NOTE]
|
|
695
|
-
>
|
|
696
|
-
> The color and color_value attributes are only applied when using stdout as output.
|
|
697
|
-
>
|
|
698
|
-
> Colors can be ignored completely by using `peek.output = "stdout_nocolor"`.
|
|
699
695
|
|
|
700
696
|
------
|
|
701
697
|
|
|
@@ -717,8 +713,24 @@ repr(peek.ANSI.red)='\x1b[1;31m'
|
|
|
717
713
|
|
|
718
714
|
------
|
|
719
715
|
|
|
716
|
+
## use_color
|
|
717
|
+
|
|
718
|
+
Colors can be ignored completely by using `peek.use_color = False`.
|
|
719
|
+
|
|
720
|
+
So,
|
|
721
|
+
|
|
722
|
+
```
|
|
723
|
+
peek(hello, color="red")
|
|
724
|
+
peek.use_color = False
|
|
725
|
+
peek(hello, color="red")
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
will print `hello=world` once in red and once without color.
|
|
729
|
+
|
|
730
|
+
Of course, `use_color` can be specified in a peek.toml file.
|
|
720
731
|
|
|
721
732
|
## compact
|
|
733
|
+
|
|
722
734
|
This attribute is used to specify the compact parameter for `pformat` (see the pprint documentation
|
|
723
735
|
for details). `compact` is False by default.
|
|
724
736
|
|
|
@@ -1025,7 +1037,9 @@ for i in range(50):
|
|
|
1025
1037
|
time.sleep(0.1)
|
|
1026
1038
|
peek('')
|
|
1027
1039
|
```
|
|
1028
|
-
|
|
1040
|
+
> [!NOTE]
|
|
1041
|
+
>
|
|
1042
|
+
> The `end` parameter will not be only applied when output is "logging.debug", "logging.info", "logging.warning", "logging.error" or "logging.critical".
|
|
1029
1043
|
|
|
1030
1044
|
> [!NOTE]
|
|
1031
1045
|
>
|
|
@@ -1077,7 +1091,7 @@ You can also use peek.print (see below).
|
|
|
1077
1091
|
|
|
1078
1092
|
> [!TIP]
|
|
1079
1093
|
>
|
|
1080
|
-
> Of course,
|
|
1094
|
+
> Of course, `print_like` can be put in a **peek.toml** file.
|
|
1081
1095
|
|
|
1082
1096
|
# Use peek.print to use peek like print with extras
|
|
1083
1097
|
The method `peek.print` allows peek to be used as alternative to print. Note that `peek.print` applies the `color`, `context_separator`, `enabled`, `end`, `filter` and `output`, `separator_print`, `show_delta` and `show_time`. It is also possible to redirect the output to a string with `as_str`.
|
|
@@ -1173,23 +1187,22 @@ hello='world'
|
|
|
1173
1187
|
|
|
1174
1188
|
Note that if enabled=False, the call will return the null string (`""`).
|
|
1175
1189
|
|
|
1176
|
-
|
|
1190
|
+
By default, a string will contain embedded ANSI color escape strings if either `color` or `color_value` specifies a color. By setting `use_color` to False, these escape sequences will be suppressed.
|
|
1191
|
+
|
|
1177
1192
|
```
|
|
1178
1193
|
hello = "world"
|
|
1179
|
-
s = peek(hello, color="red", color_value="green",
|
|
1180
|
-
print(repr(s)
|
|
1194
|
+
s = peek(hello, color="red", color_value="green", as_str=True)
|
|
1195
|
+
print(repr(s))
|
|
1196
|
+
peek.use_color = False
|
|
1197
|
+
s = peek(hello, color="red", color_value="green", as_str=True)
|
|
1198
|
+
print(repr(s))
|
|
1181
1199
|
```
|
|
1182
1200
|
prints
|
|
1183
1201
|
```
|
|
1184
|
-
|
|
1202
|
+
'\x1b[1;31mhello=\x1b[1;32mworld\x1b[1;31m\x1b[0m\n'
|
|
1203
|
+
'hello=world\n'
|
|
1185
1204
|
```
|
|
1186
1205
|
|
|
1187
|
-
> [!NOTE]
|
|
1188
|
-
>
|
|
1189
|
-
> Specifying both `as_str` and `as_colored_str` is not allowed.
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
1206
|
# Disabling peek's output
|
|
1194
1207
|
|
|
1195
1208
|
```
|
|
@@ -10,7 +10,7 @@ authors = [
|
|
|
10
10
|
{ name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com" },
|
|
11
11
|
]
|
|
12
12
|
description = "peek - debugging and benchmarking made easy"
|
|
13
|
-
version = "25.0.
|
|
13
|
+
version = "25.0.7"
|
|
14
14
|
readme = "README.md"
|
|
15
15
|
requires-python = ">=3.7"
|
|
16
16
|
dependencies = [
|
|
@@ -15,7 +15,9 @@ sys.path.insert(0, file_folder + "/../peek")
|
|
|
15
15
|
|
|
16
16
|
import peek
|
|
17
17
|
|
|
18
|
-
peek = peek.new(ignore_toml=True
|
|
18
|
+
peek = peek.new(ignore_toml=True)
|
|
19
|
+
|
|
20
|
+
globals().update(peek.ANSI.__dict__) # put white, red, ..., dark_yellow in globals
|
|
19
21
|
|
|
20
22
|
|
|
21
23
|
class g:
|
|
@@ -121,7 +123,6 @@ def test_time_delta():
|
|
|
121
123
|
time.sleep(0.1)
|
|
122
124
|
assert 10.05 < peek.delta < 11
|
|
123
125
|
|
|
124
|
-
|
|
125
126
|
|
|
126
127
|
def test_dynamic_prefix(capsys):
|
|
127
128
|
g.i = 0
|
|
@@ -144,24 +145,26 @@ def test_values_only():
|
|
|
144
145
|
s = peek(hello, as_str=True)
|
|
145
146
|
assert s == "'world'\n"
|
|
146
147
|
|
|
148
|
+
|
|
147
149
|
def test_locals(capsys):
|
|
148
150
|
def square(x):
|
|
149
|
-
result = x
|
|
151
|
+
result = x**2
|
|
150
152
|
peek(locals)
|
|
151
|
-
|
|
153
|
+
|
|
152
154
|
square(10)
|
|
153
155
|
out, err = capsys.readouterr()
|
|
154
|
-
assert out==
|
|
155
|
-
|
|
156
|
+
assert out == "x=10, result=100\n"
|
|
157
|
+
|
|
156
158
|
|
|
157
159
|
def test_globals(capsys):
|
|
158
160
|
def square(x):
|
|
159
|
-
result = x
|
|
161
|
+
result = x**2
|
|
160
162
|
peek(globals)
|
|
161
|
-
|
|
163
|
+
|
|
162
164
|
square(10)
|
|
163
165
|
out, err = capsys.readouterr()
|
|
164
|
-
assert
|
|
166
|
+
assert "pytest=<module" in out
|
|
167
|
+
|
|
165
168
|
|
|
166
169
|
def test_calls():
|
|
167
170
|
with pytest.raises(AttributeError):
|
|
@@ -187,6 +190,7 @@ def test_repr_and_str(capsys):
|
|
|
187
190
|
assert out.startswith("peek.new(")
|
|
188
191
|
assert out.endswith(")\n")
|
|
189
192
|
|
|
193
|
+
|
|
190
194
|
def test_output(capsys, tmpdir):
|
|
191
195
|
g.result = ""
|
|
192
196
|
|
|
@@ -202,10 +206,6 @@ def test_output(capsys, tmpdir):
|
|
|
202
206
|
out, err = capsys.readouterr()
|
|
203
207
|
assert out == "hello='world'\n"
|
|
204
208
|
|
|
205
|
-
peek(hello, output="stdout_nocolor")
|
|
206
|
-
out, err = capsys.readouterr()
|
|
207
|
-
assert out == "hello='world'\n"
|
|
208
|
-
|
|
209
209
|
peek(hello, output="")
|
|
210
210
|
out, err = capsys.readouterr()
|
|
211
211
|
assert out == ""
|
|
@@ -284,8 +284,8 @@ def test_show_delta(capsys):
|
|
|
284
284
|
|
|
285
285
|
def test_as_str(capsys):
|
|
286
286
|
hello = "world"
|
|
287
|
-
s = peek(hello, as_str=True)
|
|
288
|
-
peek(hello)
|
|
287
|
+
s = peek(hello, as_str=True, color="red")
|
|
288
|
+
peek(hello, color="red")
|
|
289
289
|
out, err = capsys.readouterr()
|
|
290
290
|
assert out == s
|
|
291
291
|
|
|
@@ -299,14 +299,12 @@ def test_as_str(capsys):
|
|
|
299
299
|
with peek(as_str=True):
|
|
300
300
|
pass
|
|
301
301
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
s=peek(hello, as_str=True, as_colored_str=True)
|
|
309
|
-
|
|
302
|
+
with peek.preserve():
|
|
303
|
+
peek.use_color = False
|
|
304
|
+
s = peek(hello, as_str=True, color="red")
|
|
305
|
+
assert s == "hello='world'\n"
|
|
306
|
+
|
|
307
|
+
|
|
310
308
|
@pytest.mark.skipif(Pythonista, reason="Pythonista problem")
|
|
311
309
|
def test_print(capsys):
|
|
312
310
|
peek.print(*range(4))
|
|
@@ -327,16 +325,16 @@ def test_print(capsys):
|
|
|
327
325
|
2
|
|
328
326
|
"""
|
|
329
327
|
)
|
|
330
|
-
result=peek.print(1,2,as_str=True)
|
|
331
|
-
assert result=="1 2\n"
|
|
328
|
+
result = peek.print(1, 2, as_str=True)
|
|
329
|
+
assert result == "1 2\n"
|
|
332
330
|
|
|
333
|
-
result=peek.print(1,2)
|
|
331
|
+
result = peek.print(1, 2)
|
|
334
332
|
assert result is None
|
|
335
333
|
out, err = capsys.readouterr()
|
|
336
334
|
assert out == "1 2\n"
|
|
337
335
|
|
|
338
336
|
with pytest.raises(AttributeError):
|
|
339
|
-
peek.print(sep="|", sepp="/")
|
|
337
|
+
peek.print(sep="|", sepp="/")
|
|
340
338
|
|
|
341
339
|
|
|
342
340
|
def test_clone():
|
|
@@ -430,34 +428,61 @@ def test_filter(capsys):
|
|
|
430
428
|
out, err = capsys.readouterr()
|
|
431
429
|
assert (
|
|
432
430
|
out
|
|
433
|
-
== """\
|
|
431
|
+
== f"""\
|
|
434
432
|
level=0
|
|
435
|
-
level=1
|
|
436
|
-
level=2
|
|
437
|
-
level=3
|
|
438
|
-
level=4
|
|
439
|
-
level=2
|
|
440
|
-
level=3
|
|
441
|
-
level=4
|
|
442
|
-
level=2
|
|
443
|
-
level=3
|
|
444
|
-
level=4
|
|
445
|
-
level=4
|
|
433
|
+
{blue}level=1{reset}
|
|
434
|
+
{red}level=2{reset}
|
|
435
|
+
{green}level=3{reset}
|
|
436
|
+
{blue}level=4{reset}
|
|
437
|
+
{red}level=2{reset}
|
|
438
|
+
{green}level=3{reset}
|
|
439
|
+
{blue}level=4{reset}
|
|
440
|
+
{red}level=2{reset}
|
|
441
|
+
{green}level=3{reset}
|
|
442
|
+
{blue}level=4{reset}
|
|
443
|
+
{blue}level=4{reset}
|
|
446
444
|
level=0
|
|
447
|
-
level=1
|
|
448
|
-
level=2
|
|
449
|
-
level=3
|
|
450
|
-
level=4
|
|
445
|
+
{blue}level=1{reset}
|
|
446
|
+
{red}level=2{reset}
|
|
447
|
+
{green}level=3{reset}
|
|
448
|
+
{blue}level=4{reset}
|
|
451
449
|
"""
|
|
452
450
|
)
|
|
453
451
|
|
|
454
452
|
|
|
455
|
-
@pytest.mark.skipif(Pythonista, reason="Pythonista does not generate ansi codes")
|
|
456
453
|
def test_color(capsys):
|
|
457
|
-
peek(
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
454
|
+
with peek.preserve():
|
|
455
|
+
hello = "world"
|
|
456
|
+
s = peek(hello, as_str=True)
|
|
457
|
+
assert s == f"hello='world'\n"
|
|
458
|
+
s = peek(hello, as_str=True, color="")
|
|
459
|
+
assert s == f"hello='world'\n"
|
|
460
|
+
s = peek(hello, as_str=True, color="-")
|
|
461
|
+
assert s == f"hello='world'\n"
|
|
462
|
+
s = peek(hello, as_str=True, color="red")
|
|
463
|
+
assert s == f"{red}hello='world'{reset}\n"
|
|
464
|
+
|
|
465
|
+
peek.color_value = "-"
|
|
466
|
+
s = peek(hello, as_str=True)
|
|
467
|
+
assert s == f"hello='world'\n"
|
|
468
|
+
s = peek(hello, as_str=True, color="")
|
|
469
|
+
assert s == f"hello='world'\n"
|
|
470
|
+
s = peek(hello, as_str=True, color="-")
|
|
471
|
+
assert s == f"hello='world'\n"
|
|
472
|
+
s = peek(hello, as_str=True, color="red")
|
|
473
|
+
assert s == f"{red}hello={reset}'world'{red}{reset}\n"
|
|
474
|
+
|
|
475
|
+
peek.color_value = "blue"
|
|
476
|
+
s = peek(hello, as_str=True)
|
|
477
|
+
assert s == f"hello={blue}'world'{reset}\n"
|
|
478
|
+
s = peek(hello, as_str=True, color="")
|
|
479
|
+
assert s == f"hello={blue}'world'{reset}\n"
|
|
480
|
+
s = peek(hello, as_str=True, color="-")
|
|
481
|
+
assert s == f"hello={blue}'world'{reset}\n"
|
|
482
|
+
s = peek(hello, as_str=True, color="red")
|
|
483
|
+
assert s == f"{red}hello={blue}'world'{red}{reset}\n"
|
|
484
|
+
s = peek(hello, as_str=True, color="blue")
|
|
485
|
+
assert s == f"{blue}hello='world'{reset}\n"
|
|
461
486
|
|
|
462
487
|
|
|
463
488
|
def test_incorrect_filter():
|
|
@@ -860,7 +885,7 @@ def test_check_output(capsys, tmpdir):
|
|
|
860
885
|
def check_output():
|
|
861
886
|
import x2
|
|
862
887
|
|
|
863
|
-
peek.configure(show_line_number=True, show_exit= False,
|
|
888
|
+
peek.configure(show_line_number=True, show_exit= False,use_color=False)
|
|
864
889
|
x2.test()
|
|
865
890
|
peek(1)
|
|
866
891
|
peek(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|