peek-python 24.0.4__tar.gz → 24.0.5__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-24.0.4 → peek_python-24.0.5}/PKG-INFO +36 -15
- {peek_python-24.0.4 → peek_python-24.0.5}/README.md +35 -14
- {peek_python-24.0.4 → peek_python-24.0.5}/peek/peek.py +30 -26
- {peek_python-24.0.4 → peek_python-24.0.5}/peek_python.egg-info/PKG-INFO +36 -15
- {peek_python-24.0.4 → peek_python-24.0.5}/pyproject.toml +1 -1
- {peek_python-24.0.4 → peek_python-24.0.5}/tests/test_peek.py +14 -0
- {peek_python-24.0.4 → peek_python-24.0.5}/license.txt +0 -0
- {peek_python-24.0.4 → peek_python-24.0.5}/peek/__init__.py +0 -0
- {peek_python-24.0.4 → peek_python-24.0.5}/peek_python.egg-info/SOURCES.txt +0 -0
- {peek_python-24.0.4 → peek_python-24.0.5}/peek_python.egg-info/dependency_links.txt +0 -0
- {peek_python-24.0.4 → peek_python-24.0.5}/peek_python.egg-info/requires.txt +0 -0
- {peek_python-24.0.4 → peek_python-24.0.5}/peek_python.egg-info/top_level.txt +0 -0
- {peek_python-24.0.4 → peek_python-24.0.5}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: peek-python
|
|
3
|
-
Version: 24.0.
|
|
3
|
+
Version: 24.0.5
|
|
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
|
|
@@ -44,7 +44,7 @@ And on top of that, you get some basic benchmarking functionality.
|
|
|
44
44
|
|
|
45
45
|
* [Configuration](#configuration)
|
|
46
46
|
|
|
47
|
-
* [Use peek.print to
|
|
47
|
+
* [Use peek.print to use peek like print with extras](#use-peek.print-to-to use peek like-with-extras)
|
|
48
48
|
|
|
49
49
|
* [Return a string instead of sending to output](#return-a-string-instead-of-sending-to-output)
|
|
50
50
|
|
|
@@ -335,6 +335,7 @@ level lvl 0
|
|
|
335
335
|
line_length ll 80
|
|
336
336
|
output - "stdout"
|
|
337
337
|
prefix pr ""
|
|
338
|
+
print_like print False
|
|
338
339
|
quote_string qs True
|
|
339
340
|
return_none - False
|
|
340
341
|
separator sep ", "
|
|
@@ -921,7 +922,9 @@ x=1.230e+01
|
|
|
921
922
|
```
|
|
922
923
|
Note that if `values_only` is True, f-string will be suppressed, regardless of `values_only_for_fstrings`.
|
|
923
924
|
|
|
925
|
+
|
|
924
926
|
## end
|
|
927
|
+
|
|
925
928
|
The `end` attribute works like the end parameter of print. By default, `end` is "\n".
|
|
926
929
|
This can be useful to have several peek outputs on one line, like:
|
|
927
930
|
|
|
@@ -972,16 +975,35 @@ print(peek.delta)
|
|
|
972
975
|
```
|
|
973
976
|
prints a value that id slightly more than 0.
|
|
974
977
|
|
|
975
|
-
|
|
976
|
-
|
|
978
|
+
## print_like / print
|
|
979
|
+
When print_like (or print) is False, peek will work by expanding the arguments to description/serialized value pairs.
|
|
980
|
+
But, when print_like is True, peek becomes a kind of supercharged print:
|
|
981
|
+
|
|
982
|
+
```
|
|
983
|
+
peek.print_like = True
|
|
984
|
+
peek(12, f"{min(1, 2)=}", list(range(4), color="yellow")
|
|
985
|
+
```
|
|
986
|
+
will print
|
|
987
|
+
```
|
|
988
|
+
12 min(1, 2)=1 [0, 1, 2, 3]
|
|
989
|
+
```
|
|
990
|
+
in yellow, but only if peek.enabled is False, nothing will be printed.
|
|
991
|
+
|
|
992
|
+
You can also use peek.print (see below).
|
|
993
|
+
|
|
994
|
+
> [!TIP]
|
|
995
|
+
>
|
|
996
|
+
> Of course, print_only can be put in a **peek.toml** file.
|
|
997
|
+
|
|
998
|
+
# Use peek.print to use peek like print with extras
|
|
999
|
+
The method `peek.print` allows peek to be used as alternative to print. Note that `peek.print` applies the `color`, `context_separator`, `enabled`, `filter` and `output`, `show_delta` and `show_time`. It is also possible to redirect the output to as string with `as_str`.
|
|
977
1000
|
|
|
978
1001
|
So,
|
|
979
1002
|
|
|
980
1003
|
```
|
|
981
|
-
peek.color = "red"
|
|
982
1004
|
peek.filter = "level==1"
|
|
983
|
-
peek.print(f"{max(1, 2)=}") # default level is 0, so this will be suppressed
|
|
984
|
-
peek.print(f"{min(1, 2)=}", level=1)
|
|
1005
|
+
peek.print(f"{max(1, 2)=}", color="blue") # default level is 0, so this will be suppressed
|
|
1006
|
+
peek.print(f"{min(1, 2)=}", color="red",level=1)
|
|
985
1007
|
```
|
|
986
1008
|
|
|
987
1009
|
will print
|
|
@@ -990,9 +1012,9 @@ will print
|
|
|
990
1012
|
min(1, 2)=1
|
|
991
1013
|
```
|
|
992
1014
|
|
|
993
|
-
in red.
|
|
1015
|
+
in red, but only if peek.enabled is True (which is the default).
|
|
994
1016
|
|
|
995
|
-
The `peek.print`() method applies the prefix
|
|
1017
|
+
The `peek.print`() method applies the prefix, show_delta, show_line_number, show_time, show_ end attributes to the output.
|
|
996
1018
|
|
|
997
1019
|
In order to behave similar to print, `peek` has an extra attribute, `separator_print` (alias: `sepp`). This attribute (default " ") will be used when `peek.printing`.
|
|
998
1020
|
When calling `peek.print`, `sep` may be used instead. So
|
|
@@ -1019,10 +1041,9 @@ but not the same as
|
|
|
1019
1041
|
```
|
|
1020
1042
|
peek.sep = "|" # sets the 'normal' peek separator
|
|
1021
1043
|
```
|
|
1022
|
-
|
|
1023
1044
|
> [!NOTE]
|
|
1024
1045
|
>
|
|
1025
|
-
>
|
|
1046
|
+
> `peek.print` does not obey the line length and will always return None (unless as_str is True).
|
|
1026
1047
|
|
|
1027
1048
|
# Return a string instead of sending to output
|
|
1028
1049
|
|
|
@@ -1087,7 +1108,7 @@ It is possible to use more than one attribute, like
|
|
|
1087
1108
|
```
|
|
1088
1109
|
peek.filter = "color == 'blue' and delta > 5"
|
|
1089
1110
|
```
|
|
1090
|
-
As an alternative to `enabled` we can
|
|
1111
|
+
As an alternative to `enabled` we can also say
|
|
1091
1112
|
```
|
|
1092
1113
|
peek.filter = "False"
|
|
1093
1114
|
```
|
|
@@ -1209,14 +1230,14 @@ Normally, only the `peek` object is used.
|
|
|
1209
1230
|
It can be useful to have multiple instances, e.g. when some of the debugging has to be done with context information
|
|
1210
1231
|
and others requires an alternative prefix.
|
|
1211
1232
|
|
|
1212
|
-
|
|
1233
|
+
There are several ways to obtain a new instance of peek:
|
|
1213
1234
|
|
|
1214
1235
|
* by using `peek.new()`
|
|
1215
1236
|
|
|
1216
1237
|
With this a new peek object is created with the default attributes
|
|
1217
1238
|
* by using `peek.new(ignore_toml=True)`
|
|
1218
1239
|
|
|
1219
|
-
With this a new peekobject is created with the default
|
|
1240
|
+
With this a new peekobject is created with the default attributes. Any peek.toml files are ignored.
|
|
1220
1241
|
* by using `peek.fork()`
|
|
1221
1242
|
|
|
1222
1243
|
With this a new peek object is created with the same attributes as the object it is created ('the parent') from. Note that any non set attributes are copied (propagated) from the parent.
|
|
@@ -1346,7 +1367,7 @@ usable without installation yes no
|
|
|
1346
1367
|
can be used as a decorator yes no
|
|
1347
1368
|
can be used as a context manager yes no
|
|
1348
1369
|
can show traceback yes no
|
|
1349
|
-
|
|
1370
|
+
can be used like print w/extras yes (with peek.print) no
|
|
1350
1371
|
allows non linefeed printing yes (via end parameter) requires patching
|
|
1351
1372
|
PEP8 (Pythonic) API yes no
|
|
1352
1373
|
sorts dicts no by default, optional *) yes
|
|
@@ -24,7 +24,7 @@ And on top of that, you get some basic benchmarking functionality.
|
|
|
24
24
|
|
|
25
25
|
* [Configuration](#configuration)
|
|
26
26
|
|
|
27
|
-
* [Use peek.print to
|
|
27
|
+
* [Use peek.print to use peek like print with extras](#use-peek.print-to-to use peek like-with-extras)
|
|
28
28
|
|
|
29
29
|
* [Return a string instead of sending to output](#return-a-string-instead-of-sending-to-output)
|
|
30
30
|
|
|
@@ -315,6 +315,7 @@ level lvl 0
|
|
|
315
315
|
line_length ll 80
|
|
316
316
|
output - "stdout"
|
|
317
317
|
prefix pr ""
|
|
318
|
+
print_like print False
|
|
318
319
|
quote_string qs True
|
|
319
320
|
return_none - False
|
|
320
321
|
separator sep ", "
|
|
@@ -901,7 +902,9 @@ x=1.230e+01
|
|
|
901
902
|
```
|
|
902
903
|
Note that if `values_only` is True, f-string will be suppressed, regardless of `values_only_for_fstrings`.
|
|
903
904
|
|
|
905
|
+
|
|
904
906
|
## end
|
|
907
|
+
|
|
905
908
|
The `end` attribute works like the end parameter of print. By default, `end` is "\n".
|
|
906
909
|
This can be useful to have several peek outputs on one line, like:
|
|
907
910
|
|
|
@@ -952,16 +955,35 @@ print(peek.delta)
|
|
|
952
955
|
```
|
|
953
956
|
prints a value that id slightly more than 0.
|
|
954
957
|
|
|
955
|
-
|
|
956
|
-
|
|
958
|
+
## print_like / print
|
|
959
|
+
When print_like (or print) is False, peek will work by expanding the arguments to description/serialized value pairs.
|
|
960
|
+
But, when print_like is True, peek becomes a kind of supercharged print:
|
|
961
|
+
|
|
962
|
+
```
|
|
963
|
+
peek.print_like = True
|
|
964
|
+
peek(12, f"{min(1, 2)=}", list(range(4), color="yellow")
|
|
965
|
+
```
|
|
966
|
+
will print
|
|
967
|
+
```
|
|
968
|
+
12 min(1, 2)=1 [0, 1, 2, 3]
|
|
969
|
+
```
|
|
970
|
+
in yellow, but only if peek.enabled is False, nothing will be printed.
|
|
971
|
+
|
|
972
|
+
You can also use peek.print (see below).
|
|
973
|
+
|
|
974
|
+
> [!TIP]
|
|
975
|
+
>
|
|
976
|
+
> Of course, print_only can be put in a **peek.toml** file.
|
|
977
|
+
|
|
978
|
+
# Use peek.print to use peek like print with extras
|
|
979
|
+
The method `peek.print` allows peek to be used as alternative to print. Note that `peek.print` applies the `color`, `context_separator`, `enabled`, `filter` and `output`, `show_delta` and `show_time`. It is also possible to redirect the output to as string with `as_str`.
|
|
957
980
|
|
|
958
981
|
So,
|
|
959
982
|
|
|
960
983
|
```
|
|
961
|
-
peek.color = "red"
|
|
962
984
|
peek.filter = "level==1"
|
|
963
|
-
peek.print(f"{max(1, 2)=}") # default level is 0, so this will be suppressed
|
|
964
|
-
peek.print(f"{min(1, 2)=}", level=1)
|
|
985
|
+
peek.print(f"{max(1, 2)=}", color="blue") # default level is 0, so this will be suppressed
|
|
986
|
+
peek.print(f"{min(1, 2)=}", color="red",level=1)
|
|
965
987
|
```
|
|
966
988
|
|
|
967
989
|
will print
|
|
@@ -970,9 +992,9 @@ will print
|
|
|
970
992
|
min(1, 2)=1
|
|
971
993
|
```
|
|
972
994
|
|
|
973
|
-
in red.
|
|
995
|
+
in red, but only if peek.enabled is True (which is the default).
|
|
974
996
|
|
|
975
|
-
The `peek.print`() method applies the prefix
|
|
997
|
+
The `peek.print`() method applies the prefix, show_delta, show_line_number, show_time, show_ end attributes to the output.
|
|
976
998
|
|
|
977
999
|
In order to behave similar to print, `peek` has an extra attribute, `separator_print` (alias: `sepp`). This attribute (default " ") will be used when `peek.printing`.
|
|
978
1000
|
When calling `peek.print`, `sep` may be used instead. So
|
|
@@ -999,10 +1021,9 @@ but not the same as
|
|
|
999
1021
|
```
|
|
1000
1022
|
peek.sep = "|" # sets the 'normal' peek separator
|
|
1001
1023
|
```
|
|
1002
|
-
|
|
1003
1024
|
> [!NOTE]
|
|
1004
1025
|
>
|
|
1005
|
-
>
|
|
1026
|
+
> `peek.print` does not obey the line length and will always return None (unless as_str is True).
|
|
1006
1027
|
|
|
1007
1028
|
# Return a string instead of sending to output
|
|
1008
1029
|
|
|
@@ -1067,7 +1088,7 @@ It is possible to use more than one attribute, like
|
|
|
1067
1088
|
```
|
|
1068
1089
|
peek.filter = "color == 'blue' and delta > 5"
|
|
1069
1090
|
```
|
|
1070
|
-
As an alternative to `enabled` we can
|
|
1091
|
+
As an alternative to `enabled` we can also say
|
|
1071
1092
|
```
|
|
1072
1093
|
peek.filter = "False"
|
|
1073
1094
|
```
|
|
@@ -1189,14 +1210,14 @@ Normally, only the `peek` object is used.
|
|
|
1189
1210
|
It can be useful to have multiple instances, e.g. when some of the debugging has to be done with context information
|
|
1190
1211
|
and others requires an alternative prefix.
|
|
1191
1212
|
|
|
1192
|
-
|
|
1213
|
+
There are several ways to obtain a new instance of peek:
|
|
1193
1214
|
|
|
1194
1215
|
* by using `peek.new()`
|
|
1195
1216
|
|
|
1196
1217
|
With this a new peek object is created with the default attributes
|
|
1197
1218
|
* by using `peek.new(ignore_toml=True)`
|
|
1198
1219
|
|
|
1199
|
-
With this a new peekobject is created with the default
|
|
1220
|
+
With this a new peekobject is created with the default attributes. Any peek.toml files are ignored.
|
|
1200
1221
|
* by using `peek.fork()`
|
|
1201
1222
|
|
|
1202
1223
|
With this a new peek object is created with the same attributes as the object it is created ('the parent') from. Note that any non set attributes are copied (propagated) from the parent.
|
|
@@ -1326,7 +1347,7 @@ usable without installation yes no
|
|
|
1326
1347
|
can be used as a decorator yes no
|
|
1327
1348
|
can be used as a context manager yes no
|
|
1328
1349
|
can show traceback yes no
|
|
1329
|
-
|
|
1350
|
+
can be used like print w/extras yes (with peek.print) no
|
|
1330
1351
|
allows non linefeed printing yes (via end parameter) requires patching
|
|
1331
1352
|
PEP8 (Pythonic) API yes no
|
|
1332
1353
|
sorts dicts no by default, optional *) yes
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# | .__/ \___| \___||_|\_\
|
|
5
5
|
# |_| like print, but easy.
|
|
6
6
|
|
|
7
|
-
__version__ = "24.0.
|
|
7
|
+
__version__ = "24.0.5"
|
|
8
8
|
|
|
9
9
|
"""
|
|
10
10
|
See https://github.com/salabim/peek for details
|
|
@@ -284,33 +284,33 @@ class _Peek:
|
|
|
284
284
|
return self.enabled
|
|
285
285
|
|
|
286
286
|
def print(self, *args, as_str=False, **kwargs):
|
|
287
|
-
|
|
288
|
-
if
|
|
289
|
-
raise AttributeError(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
287
|
+
print_like=True
|
|
288
|
+
if "print" in kwargs and "print_like" in kwargs:
|
|
289
|
+
raise AttributeError("both print_like and print specified")
|
|
290
|
+
print_like=kwargs.get["print_like", print_like]
|
|
291
|
+
print_like=kwargs.get["print", print_like]
|
|
292
|
+
kwargs["print_like"]=print_like
|
|
293
|
+
return self(*args, as_str=as_str, **kwargs)
|
|
294
294
|
|
|
295
|
+
def __call__(self, *args, as_str=False, **kwargs):
|
|
295
296
|
this = self.fork(**kwargs)
|
|
296
297
|
|
|
297
|
-
|
|
298
|
-
if as_str:
|
|
299
|
-
return ""
|
|
300
|
-
else:
|
|
301
|
-
return return_args(args, this.return_none)
|
|
302
|
-
|
|
303
|
-
s = this.prefix + this.separator_print.join(map(str, args))
|
|
298
|
+
this._as_str = as_str
|
|
304
299
|
|
|
305
|
-
if
|
|
306
|
-
|
|
300
|
+
if this.print_like:
|
|
301
|
+
if "sep" in kwargs or "separator" in kwargs:
|
|
302
|
+
if "sepp" in kwargs or "separator_print" in kwargs:
|
|
303
|
+
raise AttributeError("both separator and separator_print specified")
|
|
304
|
+
this.separator_print = this.separator
|
|
307
305
|
|
|
308
|
-
|
|
306
|
+
this.values_only = True
|
|
307
|
+
this.show_enter = False
|
|
308
|
+
this.show_exit = False
|
|
309
|
+
this.show_traceback = False
|
|
310
|
+
this.to_clipboard = False
|
|
311
|
+
this.return_none = True
|
|
312
|
+
args = [this.separator_print.join(map(str, args))]
|
|
309
313
|
|
|
310
|
-
def __call__(self, *args, as_str=False, **kwargs):
|
|
311
|
-
this = self.fork(**kwargs)
|
|
312
|
-
|
|
313
|
-
this._as_str = as_str
|
|
314
314
|
if len(args) != 0 and not this.do_show():
|
|
315
315
|
if as_str:
|
|
316
316
|
return ""
|
|
@@ -375,7 +375,7 @@ class _Peek:
|
|
|
375
375
|
this_line_prev = code[line_number - 2].strip()
|
|
376
376
|
else:
|
|
377
377
|
this_line_prev = ""
|
|
378
|
-
if this_line.startswith("@") or this_line_prev.startswith("@"):
|
|
378
|
+
if (this_line.startswith("@") or this_line_prev.startswith("@")) and (this.show_enter or this.show_exit):
|
|
379
379
|
if as_str:
|
|
380
380
|
raise TypeError("as_str may not be True when peek used as decorator")
|
|
381
381
|
|
|
@@ -425,7 +425,7 @@ class _Peek:
|
|
|
425
425
|
|
|
426
426
|
this._line_number_with_filename_and_parent = f"#{line_number}{filename_name}{parent_function}"
|
|
427
427
|
|
|
428
|
-
if this_line.startswith("with ") or this_line.startswith("with\t"):
|
|
428
|
+
if (this_line.startswith("with ") or this_line.startswith("with\t")) and (this.show_enter or this.show_exit):
|
|
429
429
|
if as_str:
|
|
430
430
|
raise TypeError("as_str may not be True when peek used as context manager")
|
|
431
431
|
if args:
|
|
@@ -566,8 +566,8 @@ class _Peek:
|
|
|
566
566
|
self.do_output(f"{context}exit in {duration:.6f} seconds{self._save_traceback}")
|
|
567
567
|
self._is_context_manager = False
|
|
568
568
|
|
|
569
|
-
def context(self, omit_context_separator=False):
|
|
570
|
-
if self.show_line_number and self._line_number_with_filename_and_parent != "":
|
|
569
|
+
def context(self, omit_line_number=False, omit_context_separator=False):
|
|
570
|
+
if not omit_line_number and self.show_line_number and self._line_number_with_filename_and_parent != "":
|
|
571
571
|
parts = [self._line_number_with_filename_and_parent]
|
|
572
572
|
else:
|
|
573
573
|
parts = []
|
|
@@ -674,6 +674,7 @@ class _Peek:
|
|
|
674
674
|
|
|
675
675
|
store_perf_counter = perf_counter()
|
|
676
676
|
name_alias_default = (
|
|
677
|
+
# name, alias, default value
|
|
677
678
|
("color", "col", "-"),
|
|
678
679
|
("color_value", "col_val", ""),
|
|
679
680
|
("compact", "", False),
|
|
@@ -689,6 +690,7 @@ name_alias_default = (
|
|
|
689
690
|
("line_length", "ll", 80),
|
|
690
691
|
("output", "", "stdout"),
|
|
691
692
|
("prefix", "pr", ""),
|
|
693
|
+
("print_like", "print", False),
|
|
692
694
|
("quote_string", "qs", True),
|
|
693
695
|
("return_none", "", False),
|
|
694
696
|
("separator", "sep", ", "),
|
|
@@ -708,6 +710,7 @@ name_alias_default = (
|
|
|
708
710
|
("wrap_indent", "", " "),
|
|
709
711
|
)
|
|
710
712
|
alias_name = {alias: name for (name, alias, default) in name_alias_default if alias}
|
|
713
|
+
name_alias = {name: alias for (name, alias, default) in name_alias_default}
|
|
711
714
|
name_default = {name: default for (name, alias, default) in name_alias_default}
|
|
712
715
|
alias_default = {alias: default for (name, alias, default) in name_alias_default if alias}
|
|
713
716
|
name_and_alias_default = {**name_default, **alias_default}
|
|
@@ -739,3 +742,4 @@ class PeekModule(types.ModuleType):
|
|
|
739
742
|
|
|
740
743
|
if __name__ != "__main__":
|
|
741
744
|
sys.modules["peek"].__class__ = PeekModule
|
|
745
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: peek-python
|
|
3
|
-
Version: 24.0.
|
|
3
|
+
Version: 24.0.5
|
|
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
|
|
@@ -44,7 +44,7 @@ And on top of that, you get some basic benchmarking functionality.
|
|
|
44
44
|
|
|
45
45
|
* [Configuration](#configuration)
|
|
46
46
|
|
|
47
|
-
* [Use peek.print to
|
|
47
|
+
* [Use peek.print to use peek like print with extras](#use-peek.print-to-to use peek like-with-extras)
|
|
48
48
|
|
|
49
49
|
* [Return a string instead of sending to output](#return-a-string-instead-of-sending-to-output)
|
|
50
50
|
|
|
@@ -335,6 +335,7 @@ level lvl 0
|
|
|
335
335
|
line_length ll 80
|
|
336
336
|
output - "stdout"
|
|
337
337
|
prefix pr ""
|
|
338
|
+
print_like print False
|
|
338
339
|
quote_string qs True
|
|
339
340
|
return_none - False
|
|
340
341
|
separator sep ", "
|
|
@@ -921,7 +922,9 @@ x=1.230e+01
|
|
|
921
922
|
```
|
|
922
923
|
Note that if `values_only` is True, f-string will be suppressed, regardless of `values_only_for_fstrings`.
|
|
923
924
|
|
|
925
|
+
|
|
924
926
|
## end
|
|
927
|
+
|
|
925
928
|
The `end` attribute works like the end parameter of print. By default, `end` is "\n".
|
|
926
929
|
This can be useful to have several peek outputs on one line, like:
|
|
927
930
|
|
|
@@ -972,16 +975,35 @@ print(peek.delta)
|
|
|
972
975
|
```
|
|
973
976
|
prints a value that id slightly more than 0.
|
|
974
977
|
|
|
975
|
-
|
|
976
|
-
|
|
978
|
+
## print_like / print
|
|
979
|
+
When print_like (or print) is False, peek will work by expanding the arguments to description/serialized value pairs.
|
|
980
|
+
But, when print_like is True, peek becomes a kind of supercharged print:
|
|
981
|
+
|
|
982
|
+
```
|
|
983
|
+
peek.print_like = True
|
|
984
|
+
peek(12, f"{min(1, 2)=}", list(range(4), color="yellow")
|
|
985
|
+
```
|
|
986
|
+
will print
|
|
987
|
+
```
|
|
988
|
+
12 min(1, 2)=1 [0, 1, 2, 3]
|
|
989
|
+
```
|
|
990
|
+
in yellow, but only if peek.enabled is False, nothing will be printed.
|
|
991
|
+
|
|
992
|
+
You can also use peek.print (see below).
|
|
993
|
+
|
|
994
|
+
> [!TIP]
|
|
995
|
+
>
|
|
996
|
+
> Of course, print_only can be put in a **peek.toml** file.
|
|
997
|
+
|
|
998
|
+
# Use peek.print to use peek like print with extras
|
|
999
|
+
The method `peek.print` allows peek to be used as alternative to print. Note that `peek.print` applies the `color`, `context_separator`, `enabled`, `filter` and `output`, `show_delta` and `show_time`. It is also possible to redirect the output to as string with `as_str`.
|
|
977
1000
|
|
|
978
1001
|
So,
|
|
979
1002
|
|
|
980
1003
|
```
|
|
981
|
-
peek.color = "red"
|
|
982
1004
|
peek.filter = "level==1"
|
|
983
|
-
peek.print(f"{max(1, 2)=}") # default level is 0, so this will be suppressed
|
|
984
|
-
peek.print(f"{min(1, 2)=}", level=1)
|
|
1005
|
+
peek.print(f"{max(1, 2)=}", color="blue") # default level is 0, so this will be suppressed
|
|
1006
|
+
peek.print(f"{min(1, 2)=}", color="red",level=1)
|
|
985
1007
|
```
|
|
986
1008
|
|
|
987
1009
|
will print
|
|
@@ -990,9 +1012,9 @@ will print
|
|
|
990
1012
|
min(1, 2)=1
|
|
991
1013
|
```
|
|
992
1014
|
|
|
993
|
-
in red.
|
|
1015
|
+
in red, but only if peek.enabled is True (which is the default).
|
|
994
1016
|
|
|
995
|
-
The `peek.print`() method applies the prefix
|
|
1017
|
+
The `peek.print`() method applies the prefix, show_delta, show_line_number, show_time, show_ end attributes to the output.
|
|
996
1018
|
|
|
997
1019
|
In order to behave similar to print, `peek` has an extra attribute, `separator_print` (alias: `sepp`). This attribute (default " ") will be used when `peek.printing`.
|
|
998
1020
|
When calling `peek.print`, `sep` may be used instead. So
|
|
@@ -1019,10 +1041,9 @@ but not the same as
|
|
|
1019
1041
|
```
|
|
1020
1042
|
peek.sep = "|" # sets the 'normal' peek separator
|
|
1021
1043
|
```
|
|
1022
|
-
|
|
1023
1044
|
> [!NOTE]
|
|
1024
1045
|
>
|
|
1025
|
-
>
|
|
1046
|
+
> `peek.print` does not obey the line length and will always return None (unless as_str is True).
|
|
1026
1047
|
|
|
1027
1048
|
# Return a string instead of sending to output
|
|
1028
1049
|
|
|
@@ -1087,7 +1108,7 @@ It is possible to use more than one attribute, like
|
|
|
1087
1108
|
```
|
|
1088
1109
|
peek.filter = "color == 'blue' and delta > 5"
|
|
1089
1110
|
```
|
|
1090
|
-
As an alternative to `enabled` we can
|
|
1111
|
+
As an alternative to `enabled` we can also say
|
|
1091
1112
|
```
|
|
1092
1113
|
peek.filter = "False"
|
|
1093
1114
|
```
|
|
@@ -1209,14 +1230,14 @@ Normally, only the `peek` object is used.
|
|
|
1209
1230
|
It can be useful to have multiple instances, e.g. when some of the debugging has to be done with context information
|
|
1210
1231
|
and others requires an alternative prefix.
|
|
1211
1232
|
|
|
1212
|
-
|
|
1233
|
+
There are several ways to obtain a new instance of peek:
|
|
1213
1234
|
|
|
1214
1235
|
* by using `peek.new()`
|
|
1215
1236
|
|
|
1216
1237
|
With this a new peek object is created with the default attributes
|
|
1217
1238
|
* by using `peek.new(ignore_toml=True)`
|
|
1218
1239
|
|
|
1219
|
-
With this a new peekobject is created with the default
|
|
1240
|
+
With this a new peekobject is created with the default attributes. Any peek.toml files are ignored.
|
|
1220
1241
|
* by using `peek.fork()`
|
|
1221
1242
|
|
|
1222
1243
|
With this a new peek object is created with the same attributes as the object it is created ('the parent') from. Note that any non set attributes are copied (propagated) from the parent.
|
|
@@ -1346,7 +1367,7 @@ usable without installation yes no
|
|
|
1346
1367
|
can be used as a decorator yes no
|
|
1347
1368
|
can be used as a context manager yes no
|
|
1348
1369
|
can show traceback yes no
|
|
1349
|
-
|
|
1370
|
+
can be used like print w/extras yes (with peek.print) no
|
|
1350
1371
|
allows non linefeed printing yes (via end parameter) requires patching
|
|
1351
1372
|
PEP8 (Pythonic) API yes no
|
|
1352
1373
|
sorts dicts no by default, optional *) yes
|
|
@@ -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 = "24.0.
|
|
13
|
+
version = "24.0.5"
|
|
14
14
|
readme = "README.md"
|
|
15
15
|
requires-python = ">=3.6"
|
|
16
16
|
dependencies = [
|
|
@@ -301,9 +301,23 @@ def test_print(capsys):
|
|
|
301
301
|
2
|
|
302
302
|
"""
|
|
303
303
|
)
|
|
304
|
+
result=peek.print(1,2,as_str=True)
|
|
305
|
+
assert result=="1 2\n"
|
|
306
|
+
|
|
307
|
+
result=peek.print(1,2)
|
|
308
|
+
assert result is None
|
|
309
|
+
|
|
310
|
+
|
|
304
311
|
with pytest.raises(AttributeError):
|
|
305
312
|
peek.print(sep="|", sepp="/")
|
|
306
313
|
|
|
314
|
+
with pytest.raises(AttributeError):
|
|
315
|
+
peek.print(line_length=120)
|
|
316
|
+
|
|
317
|
+
with pytest.raises(AttributeError):
|
|
318
|
+
peek.print(line_length=120)
|
|
319
|
+
|
|
320
|
+
|
|
307
321
|
def test_clone():
|
|
308
322
|
hello = "world"
|
|
309
323
|
z = peek.clone()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|