peek-python 24.0.1__tar.gz → 24.0.2__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.1 → peek_python-24.0.2}/PKG-INFO +48 -56
- {peek_python-24.0.1 → peek_python-24.0.2}/README.md +47 -55
- {peek_python-24.0.1 → peek_python-24.0.2}/peek/peek.py +27 -39
- {peek_python-24.0.1 → peek_python-24.0.2}/peek_python.egg-info/PKG-INFO +48 -56
- {peek_python-24.0.1 → peek_python-24.0.2}/pyproject.toml +1 -1
- {peek_python-24.0.1 → peek_python-24.0.2}/license.txt +0 -0
- {peek_python-24.0.1 → peek_python-24.0.2}/peek/__init__.py +0 -0
- {peek_python-24.0.1 → peek_python-24.0.2}/peek_python.egg-info/SOURCES.txt +0 -0
- {peek_python-24.0.1 → peek_python-24.0.2}/peek_python.egg-info/dependency_links.txt +0 -0
- {peek_python-24.0.1 → peek_python-24.0.2}/peek_python.egg-info/requires.txt +0 -0
- {peek_python-24.0.1 → peek_python-24.0.2}/peek_python.egg-info/top_level.txt +0 -0
- {peek_python-24.0.1 → peek_python-24.0.2}/setup.cfg +0 -0
- {peek_python-24.0.1 → peek_python-24.0.2}/tests/test_peek.py +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.2
|
|
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
|
|
@@ -18,8 +18,7 @@ Requires-Dist: pyperclip>=1.9.0
|
|
|
18
18
|
Requires-Dist: six>=1.17.0
|
|
19
19
|
Requires-Dist: tomli>=2.2.1
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
<img src="https://www.salabim.org/peek/peek_logo1.png">
|
|
23
22
|
|
|
24
23
|
# Introduction
|
|
25
24
|
|
|
@@ -49,7 +48,9 @@ And on top of that, you get some basic benchmarking functionality.
|
|
|
49
48
|
|
|
50
49
|
* [Disabling peek's output](#disabling-peeks-output)
|
|
51
50
|
|
|
52
|
-
* [Using
|
|
51
|
+
* [Using level to control peek output](#Using-level-to-control-peek-output)
|
|
52
|
+
|
|
53
|
+
* [Using color to control peek output](#Using-color-to-control-peek-output)
|
|
53
54
|
|
|
54
55
|
* [Copying to the clipboard](#Copying-to-the-clipboard)
|
|
55
56
|
|
|
@@ -63,14 +64,12 @@ And on top of that, you get some basic benchmarking functionality.
|
|
|
63
64
|
|
|
64
65
|
* [Using peek in a REPL](#using-peek-in-a-repl)
|
|
65
66
|
|
|
66
|
-
* [Alternative to `peek`](#alternative-to-peek)
|
|
67
|
-
|
|
68
67
|
* [Limitations](#limitations)
|
|
69
68
|
|
|
70
|
-
* [Acknowledgement](#acknowledgement)
|
|
71
|
-
|
|
72
69
|
* [Changelog](#changelog)
|
|
73
70
|
|
|
71
|
+
* [Acknowledgement](#acknowledgement)
|
|
72
|
+
|
|
74
73
|
* [Differences with IceCream](#differences-with-icecream)
|
|
75
74
|
|
|
76
75
|
|
|
@@ -85,9 +84,10 @@ or when you want to upgrade,
|
|
|
85
84
|
pip install peek-python --upgrade
|
|
86
85
|
```
|
|
87
86
|
|
|
88
|
-
Alternatively, peek.py can be just copied into you current work directory from GitHub
|
|
87
|
+
Alternatively, peek.py can be just copied into you current work directory from GitHub
|
|
88
|
+
(https://github.com/salabim/peek).
|
|
89
89
|
|
|
90
|
-
Note that peek requires the `asttokens`, `colorama`, `executing`. `six`, `tomli` and `pyperclip` modules, all of which will be automatically installed
|
|
90
|
+
Note that peek requires the `asttokens`, `colorama`, `executing`. `six`, `tomli` and `pyperclip` modules, all of which will be automatically installed.
|
|
91
91
|
|
|
92
92
|
# Importing peek
|
|
93
93
|
|
|
@@ -103,9 +103,8 @@ import peek
|
|
|
103
103
|
from peek import peek
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
> After this, `peek` is automatically a builtin and can thus be used in any module without importing it there.
|
|
106
|
+
Note that after this, `peek` is automatically a builtin and can thus be used in any module without
|
|
107
|
+
importing it there.
|
|
109
108
|
|
|
110
109
|
# Inspect variables and expressions
|
|
111
110
|
|
|
@@ -155,7 +154,7 @@ prints
|
|
|
155
154
|
```
|
|
156
155
|
world={"EN": "world ", "NL": "wereld", "FR": "monde", "DE": "Welt"}, X.a: 3
|
|
157
156
|
```
|
|
158
|
-
Just give `peek()` a variable or expression and you're done.
|
|
157
|
+
Just give `peek()` a variable or expression and you're done.
|
|
159
158
|
|
|
160
159
|
|
|
161
160
|
# Inspect execution
|
|
@@ -189,8 +188,6 @@ prints something like
|
|
|
189
188
|
#5 in add2()
|
|
190
189
|
add2(1000)=1002
|
|
191
190
|
```
|
|
192
|
-
Just call `peek()` and you're done. Isn't that easy?
|
|
193
|
-
|
|
194
191
|
|
|
195
192
|
# Return Value
|
|
196
193
|
|
|
@@ -322,9 +319,9 @@ a number of configuration attributes:
|
|
|
322
319
|
attribute alternative default
|
|
323
320
|
------------------------------------------------------
|
|
324
321
|
color col "-"
|
|
325
|
-
color_value
|
|
326
|
-
context_separator cs " ==> "
|
|
322
|
+
color_value col_val "-"
|
|
327
323
|
compact - False
|
|
324
|
+
context_separator cs " ==> "
|
|
328
325
|
depth - 1000000
|
|
329
326
|
delta - 0
|
|
330
327
|
enabled - True
|
|
@@ -348,10 +345,10 @@ show_time st False
|
|
|
348
345
|
show_traceback - False
|
|
349
346
|
sort_dicts - False
|
|
350
347
|
to_clipboard clip False
|
|
351
|
-
underscore_numbers un False
|
|
352
|
-
wrap_indent - " "
|
|
348
|
+
underscore_numbers un False
|
|
353
349
|
values_only vo False
|
|
354
350
|
value_only_for_fstrings voff False
|
|
351
|
+
wrap_indent - " "
|
|
355
352
|
------------------------------------------------------
|
|
356
353
|
```
|
|
357
354
|
It is perfectly ok to set/get any of these attributes directly, like
|
|
@@ -362,7 +359,6 @@ print(peek.prefix)
|
|
|
362
359
|
|
|
363
360
|
But, it is also possible to apply configuration directly, only here, in the call to `peek`:
|
|
364
361
|
So, it is possible to say
|
|
365
|
-
|
|
366
362
|
```
|
|
367
363
|
peek(12, prefix="==> ")
|
|
368
364
|
```
|
|
@@ -370,23 +366,25 @@ peek(12, prefix="==> ")
|
|
|
370
366
|
```
|
|
371
367
|
==> 12
|
|
372
368
|
```
|
|
373
|
-
It is also possible to configure
|
|
369
|
+
It is also possible to configure several attributes permanently with the configure method.
|
|
374
370
|
```
|
|
375
|
-
peek.configure(prefix="==> ")
|
|
371
|
+
peek.configure(prefix="==> ", color="blue")
|
|
376
372
|
peek(12)
|
|
377
373
|
```
|
|
378
|
-
will print
|
|
374
|
+
will print in blue
|
|
379
375
|
```
|
|
380
376
|
==> 12
|
|
381
377
|
```
|
|
382
378
|
It is arguably easier to say:
|
|
383
379
|
```
|
|
384
380
|
peek.prefix = "==> "
|
|
381
|
+
peek.color = "blue"
|
|
385
382
|
peek(12)
|
|
386
383
|
```
|
|
387
384
|
or even
|
|
388
385
|
```
|
|
389
386
|
peek.pr = "==> "
|
|
387
|
+
peek.col = "blue"
|
|
390
388
|
peek(12)
|
|
391
389
|
```
|
|
392
390
|
to print
|
|
@@ -395,7 +393,7 @@ to print
|
|
|
395
393
|
```
|
|
396
394
|
Yet another way to configure peek is to get a new instance of peek with peek.new() and the required configuration:
|
|
397
395
|
```
|
|
398
|
-
z = peek.new(prefix="==> ")
|
|
396
|
+
z = peek.new(prefix="==> ", color="blue")
|
|
399
397
|
z(12)
|
|
400
398
|
```
|
|
401
399
|
will print
|
|
@@ -620,7 +618,7 @@ prints
|
|
|
620
618
|
The `show_traceback` functionality is also available when peek is used as a decorator or context manager.
|
|
621
619
|
|
|
622
620
|
## line_length / ll
|
|
623
|
-
This attribute is used to specify the line length (for wrapping). The default is
|
|
621
|
+
This attribute is used to specify the line length (for wrapping). The default is 80.
|
|
624
622
|
Peek tries to keep all output on one line, but if it can't it will wrap:
|
|
625
623
|
|
|
626
624
|
```
|
|
@@ -637,7 +635,7 @@ d=
|
|
|
637
635
|
'a3': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}
|
|
638
636
|
```
|
|
639
637
|
|
|
640
|
-
## color / col and color_value /
|
|
638
|
+
## color / col and color_value / colv
|
|
641
639
|
The color attribute is used to specify the color of the output.
|
|
642
640
|
There's a choice of black, white, red, green, blue, cyan, magenta and yellow.
|
|
643
641
|
To set the color to 'nothing', use "-".
|
|
@@ -665,7 +663,7 @@ Of course, color and color_value may be specified in a peek.toml file, to make a
|
|
|
665
663
|
>
|
|
666
664
|
> The color and color_value attributes are only applied when using stdout as output.
|
|
667
665
|
>
|
|
668
|
-
> Colors can be ignored completely by using `peek.output = "stdout_nocolor
|
|
666
|
+
> Colors can be ignored completely by using `peek.output = "stdout_nocolor`.
|
|
669
667
|
|
|
670
668
|
## compact
|
|
671
669
|
This attribute is used to specify the compact parameter for `pformat` (see the pprint documentation
|
|
@@ -818,6 +816,8 @@ numbers={'one': 1, 'thousand': 1_000, 'million': 1_000_000, 'x1234567890': 1_234
|
|
|
818
816
|
numbers={'one': 1, 'thousand': 1000, 'million': 1000000, 'x1234567890': 1234567890}
|
|
819
817
|
```
|
|
820
818
|
|
|
819
|
+
Note that under Python <=3.7, numbers are never underscored.
|
|
820
|
+
|
|
821
821
|
## seperator / sep
|
|
822
822
|
|
|
823
823
|
By default, pairs (on one line) are separated by `, `.
|
|
@@ -836,7 +836,6 @@ prints
|
|
|
836
836
|
a='abcd', (b,c)=(1, 1000), d=['peek', 'c', 'e', 'c', 'r', 'e', 'a', 'm']
|
|
837
837
|
a='abcd' | (b,c)=(1, 1000) | d=['peek', 'c', 'e', 'c', 'r', 'e', 'a', 'm']
|
|
838
838
|
```
|
|
839
|
-
Note that under Python <=3.7, numbers are never printed with underscores.
|
|
840
839
|
|
|
841
840
|
## context_separator
|
|
842
841
|
|
|
@@ -909,14 +908,15 @@ If True, the left_hand side will be suppressed in case of an f-string:
|
|
|
909
908
|
|
|
910
909
|
```
|
|
911
910
|
x = 12.3
|
|
912
|
-
peek
|
|
911
|
+
peek.quote_string = False
|
|
912
|
+
peek(f"{x=:0.3e}")
|
|
913
913
|
peek.values_only_for_fstrings = True
|
|
914
|
-
peek(f"{x
|
|
914
|
+
peek(f"{x=:0.3e}")
|
|
915
915
|
```
|
|
916
916
|
prints
|
|
917
917
|
```
|
|
918
|
-
f"{x
|
|
919
|
-
|
|
918
|
+
f"{x=:0.3e}"=x=1.230e+01
|
|
919
|
+
x=1.230e+01
|
|
920
920
|
```
|
|
921
921
|
Note that if `values_only` is True, f-string will be suppressed, regardless of `values_only_for_fstrings`.
|
|
922
922
|
|
|
@@ -990,7 +990,7 @@ delta=0.011826 ==> 2
|
|
|
990
990
|
delta=0.044893 ==> 6
|
|
991
991
|
True
|
|
992
992
|
```
|
|
993
|
-
Of course `peek()` continues to return its arguments when disabled
|
|
993
|
+
Of course `peek()` continues to return its arguments when disabled.
|
|
994
994
|
|
|
995
995
|
It is also possible to suppress output with the provided attribute (see above).
|
|
996
996
|
|
|
@@ -1014,7 +1014,7 @@ It is possible to use more than one attribute, like
|
|
|
1014
1014
|
```
|
|
1015
1015
|
peek.filter = "color == 'blue' and delta > 5"
|
|
1016
1016
|
```
|
|
1017
|
-
As an alternative to `enabled` we can
|
|
1017
|
+
As an alternative to `enabled` we can alo say
|
|
1018
1018
|
```
|
|
1019
1019
|
peek.filter = "False"
|
|
1020
1020
|
```
|
|
@@ -1023,7 +1023,7 @@ peek.filter = "False"
|
|
|
1023
1023
|
|
|
1024
1024
|
It is possible to copy a value to the clipboard. There are two ways:
|
|
1025
1025
|
|
|
1026
|
-
### With peek(
|
|
1026
|
+
### With peek(to_clipboard=True)
|
|
1027
1027
|
|
|
1028
1028
|
With the optional keyword argument, *to_clipboard*:
|
|
1029
1029
|
|
|
@@ -1089,22 +1089,22 @@ The parent function can be suppressed by setting `show_line_number` or `sln` to
|
|
|
1089
1089
|
|
|
1090
1090
|
It can be useful to configure peek at import time. This can be done by providing a `peek.toml` file which
|
|
1091
1091
|
can contain any attribute configuration overriding the standard settings.
|
|
1092
|
-
E.g. if there is
|
|
1092
|
+
E.g. if there is a `peek.toml` file with the following contents
|
|
1093
1093
|
|
|
1094
1094
|
```
|
|
1095
1095
|
outpout = "stderr"
|
|
1096
1096
|
show_time = true
|
|
1097
1097
|
ll = 160
|
|
1098
|
-
|
|
1098
|
+
quote_string = false
|
|
1099
1099
|
```
|
|
1100
1100
|
in the same folder as the application, this program:
|
|
1101
1101
|
```
|
|
1102
1102
|
hello = "world"
|
|
1103
1103
|
peek(hello)
|
|
1104
1104
|
```
|
|
1105
|
-
will print to stderr (rather than stdout):
|
|
1105
|
+
will print something like this to stderr (rather than stdout):
|
|
1106
1106
|
```
|
|
1107
|
-
@ 14:53:41.392190 ==> hello=
|
|
1107
|
+
@ 14:53:41.392190 ==> hello=world
|
|
1108
1108
|
```
|
|
1109
1109
|
At import time current directory will be searched for `peek.toml` and if not found, one level up, etc. until the root directory is reached.
|
|
1110
1110
|
|
|
@@ -1136,15 +1136,14 @@ Normally, only the `peek` object is used.
|
|
|
1136
1136
|
It can be useful to have multiple instances, e.g. when some of the debugging has to be done with context information
|
|
1137
1137
|
and others requires an alternative prefix.
|
|
1138
1138
|
|
|
1139
|
-
|
|
1139
|
+
THere are several ways to obtain a new instance of peek:
|
|
1140
1140
|
|
|
1141
1141
|
* by using `peek.new()`
|
|
1142
1142
|
|
|
1143
1143
|
With this a new peek object is created with the default attributes
|
|
1144
|
-
and possibly peek.toml overrides.
|
|
1145
1144
|
* by using `peek.new(ignore_toml=True)`
|
|
1146
1145
|
|
|
1147
|
-
With this a new
|
|
1146
|
+
With this a new peekobject is created with the default attibutes. Any peek.toml files are ignored.
|
|
1148
1147
|
* by using `peek.fork()`
|
|
1149
1148
|
|
|
1150
1149
|
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.
|
|
@@ -1232,15 +1231,9 @@ Peek may be used in a REPL, but with limited functionality:
|
|
|
1232
1231
|
* use as a decorator is not supported
|
|
1233
1232
|
* use as a context manager is not supported
|
|
1234
1233
|
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
In that case, it is possible to use p instead
|
|
1240
|
-
```
|
|
1241
|
-
from peek import p
|
|
1242
|
-
```
|
|
1243
|
-
The `p` object is a *fork* of peek. That means that attributes of `peek` are propagated to `p`, unless overridden.
|
|
1234
|
+
> [!NOTE]
|
|
1235
|
+
>
|
|
1236
|
+
> Under Python >=3.13 most of the normal peek functionality is available in the REPL. A reason to upgrade!
|
|
1244
1237
|
|
|
1245
1238
|
|
|
1246
1239
|
# Limitations
|
|
@@ -1259,12 +1252,11 @@ The changelog can be found here:
|
|
|
1259
1252
|
|
|
1260
1253
|
# Acknowledgement
|
|
1261
1254
|
|
|
1262
|
-
The **peek** package is inspired by the **IceCream** package, but is a
|
|
1263
|
-
nearly complete rewrite. See https://github.com/gruns/icecream
|
|
1255
|
+
The **peek** package is inspired by the **IceCream** package, but is a nearly complete rewrite. See https://github.com/gruns/icecream
|
|
1264
1256
|
|
|
1265
1257
|
Many thanks to the author Ansgar Grunseid / grunseid.com / grunseid@gmail.com .
|
|
1266
1258
|
|
|
1267
|
-
The peek package is a rebrand of the **ycecream** package, with enhancements.
|
|
1259
|
+
The peek package is a rebrand of the **ycecream** package, with many enhancements.
|
|
1268
1260
|
|
|
1269
1261
|
# Differences with IceCream
|
|
1270
1262
|
|
|
@@ -1299,7 +1291,7 @@ colorize ***) yes, off by default yes, on by default
|
|
|
1299
1291
|
-----------------------------------------------------------------------------------------
|
|
1300
1292
|
*) under Python <= 3.7, dicts are always sorted
|
|
1301
1293
|
**) under Python <= 3.7, numbers are never underscored
|
|
1302
|
-
***) peek allows selection of
|
|
1294
|
+
***) peek allows selection of colors, whereas IceCream does coloring based on contents.
|
|
1303
1295
|
|
|
1304
1296
|
```
|
|
1305
1297
|
  
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
<img src="https://www.salabim.org/peek/peek_logo1.png">
|
|
3
2
|
|
|
4
3
|
# Introduction
|
|
5
4
|
|
|
@@ -29,7 +28,9 @@ And on top of that, you get some basic benchmarking functionality.
|
|
|
29
28
|
|
|
30
29
|
* [Disabling peek's output](#disabling-peeks-output)
|
|
31
30
|
|
|
32
|
-
* [Using
|
|
31
|
+
* [Using level to control peek output](#Using-level-to-control-peek-output)
|
|
32
|
+
|
|
33
|
+
* [Using color to control peek output](#Using-color-to-control-peek-output)
|
|
33
34
|
|
|
34
35
|
* [Copying to the clipboard](#Copying-to-the-clipboard)
|
|
35
36
|
|
|
@@ -43,14 +44,12 @@ And on top of that, you get some basic benchmarking functionality.
|
|
|
43
44
|
|
|
44
45
|
* [Using peek in a REPL](#using-peek-in-a-repl)
|
|
45
46
|
|
|
46
|
-
* [Alternative to `peek`](#alternative-to-peek)
|
|
47
|
-
|
|
48
47
|
* [Limitations](#limitations)
|
|
49
48
|
|
|
50
|
-
* [Acknowledgement](#acknowledgement)
|
|
51
|
-
|
|
52
49
|
* [Changelog](#changelog)
|
|
53
50
|
|
|
51
|
+
* [Acknowledgement](#acknowledgement)
|
|
52
|
+
|
|
54
53
|
* [Differences with IceCream](#differences-with-icecream)
|
|
55
54
|
|
|
56
55
|
|
|
@@ -65,9 +64,10 @@ or when you want to upgrade,
|
|
|
65
64
|
pip install peek-python --upgrade
|
|
66
65
|
```
|
|
67
66
|
|
|
68
|
-
Alternatively, peek.py can be just copied into you current work directory from GitHub
|
|
67
|
+
Alternatively, peek.py can be just copied into you current work directory from GitHub
|
|
68
|
+
(https://github.com/salabim/peek).
|
|
69
69
|
|
|
70
|
-
Note that peek requires the `asttokens`, `colorama`, `executing`. `six`, `tomli` and `pyperclip` modules, all of which will be automatically installed
|
|
70
|
+
Note that peek requires the `asttokens`, `colorama`, `executing`. `six`, `tomli` and `pyperclip` modules, all of which will be automatically installed.
|
|
71
71
|
|
|
72
72
|
# Importing peek
|
|
73
73
|
|
|
@@ -83,9 +83,8 @@ import peek
|
|
|
83
83
|
from peek import peek
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
> After this, `peek` is automatically a builtin and can thus be used in any module without importing it there.
|
|
86
|
+
Note that after this, `peek` is automatically a builtin and can thus be used in any module without
|
|
87
|
+
importing it there.
|
|
89
88
|
|
|
90
89
|
# Inspect variables and expressions
|
|
91
90
|
|
|
@@ -135,7 +134,7 @@ prints
|
|
|
135
134
|
```
|
|
136
135
|
world={"EN": "world ", "NL": "wereld", "FR": "monde", "DE": "Welt"}, X.a: 3
|
|
137
136
|
```
|
|
138
|
-
Just give `peek()` a variable or expression and you're done.
|
|
137
|
+
Just give `peek()` a variable or expression and you're done.
|
|
139
138
|
|
|
140
139
|
|
|
141
140
|
# Inspect execution
|
|
@@ -169,8 +168,6 @@ prints something like
|
|
|
169
168
|
#5 in add2()
|
|
170
169
|
add2(1000)=1002
|
|
171
170
|
```
|
|
172
|
-
Just call `peek()` and you're done. Isn't that easy?
|
|
173
|
-
|
|
174
171
|
|
|
175
172
|
# Return Value
|
|
176
173
|
|
|
@@ -302,9 +299,9 @@ a number of configuration attributes:
|
|
|
302
299
|
attribute alternative default
|
|
303
300
|
------------------------------------------------------
|
|
304
301
|
color col "-"
|
|
305
|
-
color_value
|
|
306
|
-
context_separator cs " ==> "
|
|
302
|
+
color_value col_val "-"
|
|
307
303
|
compact - False
|
|
304
|
+
context_separator cs " ==> "
|
|
308
305
|
depth - 1000000
|
|
309
306
|
delta - 0
|
|
310
307
|
enabled - True
|
|
@@ -328,10 +325,10 @@ show_time st False
|
|
|
328
325
|
show_traceback - False
|
|
329
326
|
sort_dicts - False
|
|
330
327
|
to_clipboard clip False
|
|
331
|
-
underscore_numbers un False
|
|
332
|
-
wrap_indent - " "
|
|
328
|
+
underscore_numbers un False
|
|
333
329
|
values_only vo False
|
|
334
330
|
value_only_for_fstrings voff False
|
|
331
|
+
wrap_indent - " "
|
|
335
332
|
------------------------------------------------------
|
|
336
333
|
```
|
|
337
334
|
It is perfectly ok to set/get any of these attributes directly, like
|
|
@@ -342,7 +339,6 @@ print(peek.prefix)
|
|
|
342
339
|
|
|
343
340
|
But, it is also possible to apply configuration directly, only here, in the call to `peek`:
|
|
344
341
|
So, it is possible to say
|
|
345
|
-
|
|
346
342
|
```
|
|
347
343
|
peek(12, prefix="==> ")
|
|
348
344
|
```
|
|
@@ -350,23 +346,25 @@ peek(12, prefix="==> ")
|
|
|
350
346
|
```
|
|
351
347
|
==> 12
|
|
352
348
|
```
|
|
353
|
-
It is also possible to configure
|
|
349
|
+
It is also possible to configure several attributes permanently with the configure method.
|
|
354
350
|
```
|
|
355
|
-
peek.configure(prefix="==> ")
|
|
351
|
+
peek.configure(prefix="==> ", color="blue")
|
|
356
352
|
peek(12)
|
|
357
353
|
```
|
|
358
|
-
will print
|
|
354
|
+
will print in blue
|
|
359
355
|
```
|
|
360
356
|
==> 12
|
|
361
357
|
```
|
|
362
358
|
It is arguably easier to say:
|
|
363
359
|
```
|
|
364
360
|
peek.prefix = "==> "
|
|
361
|
+
peek.color = "blue"
|
|
365
362
|
peek(12)
|
|
366
363
|
```
|
|
367
364
|
or even
|
|
368
365
|
```
|
|
369
366
|
peek.pr = "==> "
|
|
367
|
+
peek.col = "blue"
|
|
370
368
|
peek(12)
|
|
371
369
|
```
|
|
372
370
|
to print
|
|
@@ -375,7 +373,7 @@ to print
|
|
|
375
373
|
```
|
|
376
374
|
Yet another way to configure peek is to get a new instance of peek with peek.new() and the required configuration:
|
|
377
375
|
```
|
|
378
|
-
z = peek.new(prefix="==> ")
|
|
376
|
+
z = peek.new(prefix="==> ", color="blue")
|
|
379
377
|
z(12)
|
|
380
378
|
```
|
|
381
379
|
will print
|
|
@@ -600,7 +598,7 @@ prints
|
|
|
600
598
|
The `show_traceback` functionality is also available when peek is used as a decorator or context manager.
|
|
601
599
|
|
|
602
600
|
## line_length / ll
|
|
603
|
-
This attribute is used to specify the line length (for wrapping). The default is
|
|
601
|
+
This attribute is used to specify the line length (for wrapping). The default is 80.
|
|
604
602
|
Peek tries to keep all output on one line, but if it can't it will wrap:
|
|
605
603
|
|
|
606
604
|
```
|
|
@@ -617,7 +615,7 @@ d=
|
|
|
617
615
|
'a3': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}
|
|
618
616
|
```
|
|
619
617
|
|
|
620
|
-
## color / col and color_value /
|
|
618
|
+
## color / col and color_value / colv
|
|
621
619
|
The color attribute is used to specify the color of the output.
|
|
622
620
|
There's a choice of black, white, red, green, blue, cyan, magenta and yellow.
|
|
623
621
|
To set the color to 'nothing', use "-".
|
|
@@ -645,7 +643,7 @@ Of course, color and color_value may be specified in a peek.toml file, to make a
|
|
|
645
643
|
>
|
|
646
644
|
> The color and color_value attributes are only applied when using stdout as output.
|
|
647
645
|
>
|
|
648
|
-
> Colors can be ignored completely by using `peek.output = "stdout_nocolor
|
|
646
|
+
> Colors can be ignored completely by using `peek.output = "stdout_nocolor`.
|
|
649
647
|
|
|
650
648
|
## compact
|
|
651
649
|
This attribute is used to specify the compact parameter for `pformat` (see the pprint documentation
|
|
@@ -798,6 +796,8 @@ numbers={'one': 1, 'thousand': 1_000, 'million': 1_000_000, 'x1234567890': 1_234
|
|
|
798
796
|
numbers={'one': 1, 'thousand': 1000, 'million': 1000000, 'x1234567890': 1234567890}
|
|
799
797
|
```
|
|
800
798
|
|
|
799
|
+
Note that under Python <=3.7, numbers are never underscored.
|
|
800
|
+
|
|
801
801
|
## seperator / sep
|
|
802
802
|
|
|
803
803
|
By default, pairs (on one line) are separated by `, `.
|
|
@@ -816,7 +816,6 @@ prints
|
|
|
816
816
|
a='abcd', (b,c)=(1, 1000), d=['peek', 'c', 'e', 'c', 'r', 'e', 'a', 'm']
|
|
817
817
|
a='abcd' | (b,c)=(1, 1000) | d=['peek', 'c', 'e', 'c', 'r', 'e', 'a', 'm']
|
|
818
818
|
```
|
|
819
|
-
Note that under Python <=3.7, numbers are never printed with underscores.
|
|
820
819
|
|
|
821
820
|
## context_separator
|
|
822
821
|
|
|
@@ -889,14 +888,15 @@ If True, the left_hand side will be suppressed in case of an f-string:
|
|
|
889
888
|
|
|
890
889
|
```
|
|
891
890
|
x = 12.3
|
|
892
|
-
peek
|
|
891
|
+
peek.quote_string = False
|
|
892
|
+
peek(f"{x=:0.3e}")
|
|
893
893
|
peek.values_only_for_fstrings = True
|
|
894
|
-
peek(f"{x
|
|
894
|
+
peek(f"{x=:0.3e}")
|
|
895
895
|
```
|
|
896
896
|
prints
|
|
897
897
|
```
|
|
898
|
-
f"{x
|
|
899
|
-
|
|
898
|
+
f"{x=:0.3e}"=x=1.230e+01
|
|
899
|
+
x=1.230e+01
|
|
900
900
|
```
|
|
901
901
|
Note that if `values_only` is True, f-string will be suppressed, regardless of `values_only_for_fstrings`.
|
|
902
902
|
|
|
@@ -970,7 +970,7 @@ delta=0.011826 ==> 2
|
|
|
970
970
|
delta=0.044893 ==> 6
|
|
971
971
|
True
|
|
972
972
|
```
|
|
973
|
-
Of course `peek()` continues to return its arguments when disabled
|
|
973
|
+
Of course `peek()` continues to return its arguments when disabled.
|
|
974
974
|
|
|
975
975
|
It is also possible to suppress output with the provided attribute (see above).
|
|
976
976
|
|
|
@@ -994,7 +994,7 @@ It is possible to use more than one attribute, like
|
|
|
994
994
|
```
|
|
995
995
|
peek.filter = "color == 'blue' and delta > 5"
|
|
996
996
|
```
|
|
997
|
-
As an alternative to `enabled` we can
|
|
997
|
+
As an alternative to `enabled` we can alo say
|
|
998
998
|
```
|
|
999
999
|
peek.filter = "False"
|
|
1000
1000
|
```
|
|
@@ -1003,7 +1003,7 @@ peek.filter = "False"
|
|
|
1003
1003
|
|
|
1004
1004
|
It is possible to copy a value to the clipboard. There are two ways:
|
|
1005
1005
|
|
|
1006
|
-
### With peek(
|
|
1006
|
+
### With peek(to_clipboard=True)
|
|
1007
1007
|
|
|
1008
1008
|
With the optional keyword argument, *to_clipboard*:
|
|
1009
1009
|
|
|
@@ -1069,22 +1069,22 @@ The parent function can be suppressed by setting `show_line_number` or `sln` to
|
|
|
1069
1069
|
|
|
1070
1070
|
It can be useful to configure peek at import time. This can be done by providing a `peek.toml` file which
|
|
1071
1071
|
can contain any attribute configuration overriding the standard settings.
|
|
1072
|
-
E.g. if there is
|
|
1072
|
+
E.g. if there is a `peek.toml` file with the following contents
|
|
1073
1073
|
|
|
1074
1074
|
```
|
|
1075
1075
|
outpout = "stderr"
|
|
1076
1076
|
show_time = true
|
|
1077
1077
|
ll = 160
|
|
1078
|
-
|
|
1078
|
+
quote_string = false
|
|
1079
1079
|
```
|
|
1080
1080
|
in the same folder as the application, this program:
|
|
1081
1081
|
```
|
|
1082
1082
|
hello = "world"
|
|
1083
1083
|
peek(hello)
|
|
1084
1084
|
```
|
|
1085
|
-
will print to stderr (rather than stdout):
|
|
1085
|
+
will print something like this to stderr (rather than stdout):
|
|
1086
1086
|
```
|
|
1087
|
-
@ 14:53:41.392190 ==> hello=
|
|
1087
|
+
@ 14:53:41.392190 ==> hello=world
|
|
1088
1088
|
```
|
|
1089
1089
|
At import time current directory will be searched for `peek.toml` and if not found, one level up, etc. until the root directory is reached.
|
|
1090
1090
|
|
|
@@ -1116,15 +1116,14 @@ Normally, only the `peek` object is used.
|
|
|
1116
1116
|
It can be useful to have multiple instances, e.g. when some of the debugging has to be done with context information
|
|
1117
1117
|
and others requires an alternative prefix.
|
|
1118
1118
|
|
|
1119
|
-
|
|
1119
|
+
THere are several ways to obtain a new instance of peek:
|
|
1120
1120
|
|
|
1121
1121
|
* by using `peek.new()`
|
|
1122
1122
|
|
|
1123
1123
|
With this a new peek object is created with the default attributes
|
|
1124
|
-
and possibly peek.toml overrides.
|
|
1125
1124
|
* by using `peek.new(ignore_toml=True)`
|
|
1126
1125
|
|
|
1127
|
-
With this a new
|
|
1126
|
+
With this a new peekobject is created with the default attibutes. Any peek.toml files are ignored.
|
|
1128
1127
|
* by using `peek.fork()`
|
|
1129
1128
|
|
|
1130
1129
|
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.
|
|
@@ -1212,15 +1211,9 @@ Peek may be used in a REPL, but with limited functionality:
|
|
|
1212
1211
|
* use as a decorator is not supported
|
|
1213
1212
|
* use as a context manager is not supported
|
|
1214
1213
|
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
In that case, it is possible to use p instead
|
|
1220
|
-
```
|
|
1221
|
-
from peek import p
|
|
1222
|
-
```
|
|
1223
|
-
The `p` object is a *fork* of peek. That means that attributes of `peek` are propagated to `p`, unless overridden.
|
|
1214
|
+
> [!NOTE]
|
|
1215
|
+
>
|
|
1216
|
+
> Under Python >=3.13 most of the normal peek functionality is available in the REPL. A reason to upgrade!
|
|
1224
1217
|
|
|
1225
1218
|
|
|
1226
1219
|
# Limitations
|
|
@@ -1239,12 +1232,11 @@ The changelog can be found here:
|
|
|
1239
1232
|
|
|
1240
1233
|
# Acknowledgement
|
|
1241
1234
|
|
|
1242
|
-
The **peek** package is inspired by the **IceCream** package, but is a
|
|
1243
|
-
nearly complete rewrite. See https://github.com/gruns/icecream
|
|
1235
|
+
The **peek** package is inspired by the **IceCream** package, but is a nearly complete rewrite. See https://github.com/gruns/icecream
|
|
1244
1236
|
|
|
1245
1237
|
Many thanks to the author Ansgar Grunseid / grunseid.com / grunseid@gmail.com .
|
|
1246
1238
|
|
|
1247
|
-
The peek package is a rebrand of the **ycecream** package, with enhancements.
|
|
1239
|
+
The peek package is a rebrand of the **ycecream** package, with many enhancements.
|
|
1248
1240
|
|
|
1249
1241
|
# Differences with IceCream
|
|
1250
1242
|
|
|
@@ -1279,7 +1271,7 @@ colorize ***) yes, off by default yes, on by default
|
|
|
1279
1271
|
-----------------------------------------------------------------------------------------
|
|
1280
1272
|
*) under Python <= 3.7, dicts are always sorted
|
|
1281
1273
|
**) under Python <= 3.7, numbers are never underscored
|
|
1282
|
-
***) peek allows selection of
|
|
1274
|
+
***) peek allows selection of colors, whereas IceCream does coloring based on contents.
|
|
1283
1275
|
|
|
1284
1276
|
```
|
|
1285
1277
|
  
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
# | .__/ \___| \___||_|\_\
|
|
5
5
|
# |_| like print, but easy.
|
|
6
6
|
|
|
7
|
-
__version__ = "24.0.
|
|
7
|
+
__version__ = "24.0.2"
|
|
8
8
|
|
|
9
9
|
"""
|
|
10
10
|
See https://github.com/salabim/peek for details
|
|
@@ -42,6 +42,7 @@ if Pythonista:
|
|
|
42
42
|
import clipboard
|
|
43
43
|
else:
|
|
44
44
|
import colorama
|
|
45
|
+
|
|
45
46
|
colorama.just_fix_windows_console()
|
|
46
47
|
import pyperclip
|
|
47
48
|
|
|
@@ -160,21 +161,6 @@ def check_validity(name, value):
|
|
|
160
161
|
raise AttributeError(f"incorrect {name_org}: {repr(value)}{in_read_toml_message}")
|
|
161
162
|
|
|
162
163
|
|
|
163
|
-
class Source(executing.Source):
|
|
164
|
-
def get_text_with_indentation(self, node):
|
|
165
|
-
result = self.asttokens().get_text(node)
|
|
166
|
-
if "\n" in result:
|
|
167
|
-
result = " " * node.first_token.start[1] + result
|
|
168
|
-
result = textwrap.dedent(result)
|
|
169
|
-
result = result.strip()
|
|
170
|
-
return result
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
def change_path(new_path): # used in tests
|
|
174
|
-
global Path
|
|
175
|
-
Path = new_path
|
|
176
|
-
|
|
177
|
-
|
|
178
164
|
_fixed_perf_counter = None
|
|
179
165
|
|
|
180
166
|
|
|
@@ -260,7 +246,7 @@ class _Peek:
|
|
|
260
246
|
return self.__getattribute__(item)
|
|
261
247
|
|
|
262
248
|
def __setattr__(self, item, value):
|
|
263
|
-
if item in ("_parent", "
|
|
249
|
+
if item in ("_parent", "_is_context_manager", "_line_number_with_filename_and_parent", "_save_traceback", "_enter_time", "_as_str", "_attributes"):
|
|
264
250
|
return super().__setattr__(item, value)
|
|
265
251
|
self._attributes.update(spec_to_attributes({item: value}))
|
|
266
252
|
|
|
@@ -290,14 +276,14 @@ class _Peek:
|
|
|
290
276
|
codes = {}
|
|
291
277
|
this = self.fork(**kwargs)
|
|
292
278
|
|
|
293
|
-
this.
|
|
279
|
+
this._as_str = as_str
|
|
294
280
|
if len(args) != 0 and not this.do_show():
|
|
295
281
|
if as_str:
|
|
296
282
|
return ""
|
|
297
283
|
else:
|
|
298
284
|
return return_args(args, this.return_none)
|
|
299
285
|
|
|
300
|
-
self.
|
|
286
|
+
self._is_context_manager = False
|
|
301
287
|
|
|
302
288
|
Pair = collections.namedtuple("Pair", "left right")
|
|
303
289
|
|
|
@@ -340,7 +326,7 @@ class _Peek:
|
|
|
340
326
|
frame_info = inspect.getframeinfo(call_frame, context=1)
|
|
341
327
|
|
|
342
328
|
# parent_function = frame_info.function
|
|
343
|
-
parent_function = Source.executing(call_frame).code_qualname() # changed in version 1.3.10 to include class name
|
|
329
|
+
parent_function = executing.Source.executing(call_frame).code_qualname() # changed in version 1.3.10 to include class name
|
|
344
330
|
parent_function = parent_function.replace(".<locals>.", ".")
|
|
345
331
|
if parent_function == "<module>" or str(this.show_line_number) in ("n", "no parent"):
|
|
346
332
|
parent_function = ""
|
|
@@ -365,7 +351,7 @@ class _Peek:
|
|
|
365
351
|
break
|
|
366
352
|
else:
|
|
367
353
|
line_number += 1
|
|
368
|
-
this.
|
|
354
|
+
this._line_number_with_filename_and_parent = f"#{line_number}{filename_name}{parent_function}"
|
|
369
355
|
|
|
370
356
|
def real_decorator(function):
|
|
371
357
|
@functools.wraps(function)
|
|
@@ -395,15 +381,15 @@ class _Peek:
|
|
|
395
381
|
return real_decorator
|
|
396
382
|
|
|
397
383
|
if filename in ("<stdin>", "<string>"):
|
|
398
|
-
this.
|
|
384
|
+
this._line_number_with_filename_and_parent = ""
|
|
399
385
|
else:
|
|
400
|
-
call_node = Source.executing(call_frame).node
|
|
386
|
+
call_node = executing.Source.executing(call_frame).node
|
|
401
387
|
if call_node is None:
|
|
402
388
|
no_source_error()
|
|
403
389
|
line_number = call_node.lineno
|
|
404
390
|
this_line = code[line_number - 1].strip()
|
|
405
391
|
|
|
406
|
-
this.
|
|
392
|
+
this._line_number_with_filename_and_parent = f"#{line_number}{filename_name}{parent_function}"
|
|
407
393
|
|
|
408
394
|
if this_line.startswith("with ") or this_line.startswith("with\t"):
|
|
409
395
|
if as_str:
|
|
@@ -411,7 +397,7 @@ class _Peek:
|
|
|
411
397
|
if args:
|
|
412
398
|
raise TypeError("non-keyword arguments are not allowed when peek used as context manager")
|
|
413
399
|
|
|
414
|
-
this.
|
|
400
|
+
this._is_context_manager = True
|
|
415
401
|
return this
|
|
416
402
|
|
|
417
403
|
if not this.do_show():
|
|
@@ -426,7 +412,7 @@ class _Peek:
|
|
|
426
412
|
for right in args:
|
|
427
413
|
pairs.append(Pair(left="", right=right))
|
|
428
414
|
else:
|
|
429
|
-
source = Source.for_frame(call_frame)
|
|
415
|
+
source = executing.Source.for_frame(call_frame)
|
|
430
416
|
for node, right in zip(call_node.args, args):
|
|
431
417
|
left = source.asttokens().get_text(node)
|
|
432
418
|
if "\n" in left:
|
|
@@ -456,6 +442,7 @@ class _Peek:
|
|
|
456
442
|
if not (len(pairs) > 1 and this.separator == ""):
|
|
457
443
|
if not any("\n" in pair.left for pair in pairs):
|
|
458
444
|
as_one_line = context + this.separator.join(pair.left + this.serialize_kwargs(obj=pair.right, width=10000) for pair in pairs)
|
|
445
|
+
# as_one_line = context + this.separator.join(pair.left + (this.serialize_kwargs(obj=pair.right, width=10000)) for pair in pairs)
|
|
459
446
|
if len(as_one_line) <= this.line_length and "\n" not in as_one_line:
|
|
460
447
|
out = as_one_line
|
|
461
448
|
just_one_line = True
|
|
@@ -531,25 +518,25 @@ class _Peek:
|
|
|
531
518
|
self._attributes = save
|
|
532
519
|
|
|
533
520
|
def __enter__(self):
|
|
534
|
-
if not hasattr(self, "
|
|
521
|
+
if not hasattr(self, "_is_context_manager"):
|
|
535
522
|
raise ValueError("not allowed as context_manager")
|
|
536
|
-
self.
|
|
537
|
-
self.
|
|
523
|
+
self._save_traceback = self.traceback()
|
|
524
|
+
self._enter_time = perf_counter()
|
|
538
525
|
if self.show_enter:
|
|
539
526
|
context = self.context()
|
|
540
|
-
self.do_output(context + "enter" + self.
|
|
527
|
+
self.do_output(context + "enter" + self._save_traceback)
|
|
541
528
|
return self
|
|
542
529
|
|
|
543
530
|
def __exit__(self, *args):
|
|
544
531
|
if self.show_exit:
|
|
545
532
|
context = self.context()
|
|
546
|
-
duration = perf_counter() - self.
|
|
547
|
-
self.do_output(f"{context}exit in {duration:.6f} seconds{self.
|
|
548
|
-
self.
|
|
533
|
+
duration = perf_counter() - self._enter_time
|
|
534
|
+
self.do_output(f"{context}exit in {duration:.6f} seconds{self._save_traceback}")
|
|
535
|
+
self._is_context_manager = False
|
|
549
536
|
|
|
550
537
|
def context(self, omit_context_separator=False):
|
|
551
|
-
if self.show_line_number and self.
|
|
552
|
-
parts = [self.
|
|
538
|
+
if self.show_line_number and self._line_number_with_filename_and_parent != "":
|
|
539
|
+
parts = [self._line_number_with_filename_and_parent]
|
|
553
540
|
else:
|
|
554
541
|
parts = []
|
|
555
542
|
if self.show_time:
|
|
@@ -565,7 +552,7 @@ class _Peek:
|
|
|
565
552
|
return str(self.prefix() if callable(self.prefix) else self.prefix) + context
|
|
566
553
|
|
|
567
554
|
def add_color_value(self, s):
|
|
568
|
-
if self.output != "stdout" or self.
|
|
555
|
+
if self.output != "stdout" or self._as_str:
|
|
569
556
|
return s
|
|
570
557
|
if self.color_value.lower() not in (self.color.lower(), ""):
|
|
571
558
|
return colors[self.color_value.lower()] + s + colors[self.color.lower()]
|
|
@@ -646,8 +633,9 @@ class _Peek:
|
|
|
646
633
|
return ""
|
|
647
634
|
|
|
648
635
|
def serialize_kwargs(self, obj, width):
|
|
649
|
-
if isinstance(obj, str)
|
|
650
|
-
|
|
636
|
+
if isinstance(obj, str):
|
|
637
|
+
if not self.quote_string:
|
|
638
|
+
return str(self.add_color_value(obj))
|
|
651
639
|
kwargs = {
|
|
652
640
|
key: getattr(self, key)
|
|
653
641
|
for key in ("sort_dicts", "compact", "indent", "depth", "underscore_numbers")
|
|
@@ -705,6 +693,7 @@ in_read_toml_message = ""
|
|
|
705
693
|
peek = peek_toml.new()
|
|
706
694
|
builtins.peek = peek
|
|
707
695
|
|
|
696
|
+
|
|
708
697
|
class PeekModule(types.ModuleType):
|
|
709
698
|
def __call__(self, *args, **kwargs):
|
|
710
699
|
return peek(*args, **kwargs)
|
|
@@ -724,4 +713,3 @@ class PeekModule(types.ModuleType):
|
|
|
724
713
|
|
|
725
714
|
if __name__ != "__main__":
|
|
726
715
|
sys.modules["peek"].__class__ = PeekModule
|
|
727
|
-
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: peek-python
|
|
3
|
-
Version: 24.0.
|
|
3
|
+
Version: 24.0.2
|
|
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
|
|
@@ -18,8 +18,7 @@ Requires-Dist: pyperclip>=1.9.0
|
|
|
18
18
|
Requires-Dist: six>=1.17.0
|
|
19
19
|
Requires-Dist: tomli>=2.2.1
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
<img src="https://www.salabim.org/peek/peek_logo1.png">
|
|
23
22
|
|
|
24
23
|
# Introduction
|
|
25
24
|
|
|
@@ -49,7 +48,9 @@ And on top of that, you get some basic benchmarking functionality.
|
|
|
49
48
|
|
|
50
49
|
* [Disabling peek's output](#disabling-peeks-output)
|
|
51
50
|
|
|
52
|
-
* [Using
|
|
51
|
+
* [Using level to control peek output](#Using-level-to-control-peek-output)
|
|
52
|
+
|
|
53
|
+
* [Using color to control peek output](#Using-color-to-control-peek-output)
|
|
53
54
|
|
|
54
55
|
* [Copying to the clipboard](#Copying-to-the-clipboard)
|
|
55
56
|
|
|
@@ -63,14 +64,12 @@ And on top of that, you get some basic benchmarking functionality.
|
|
|
63
64
|
|
|
64
65
|
* [Using peek in a REPL](#using-peek-in-a-repl)
|
|
65
66
|
|
|
66
|
-
* [Alternative to `peek`](#alternative-to-peek)
|
|
67
|
-
|
|
68
67
|
* [Limitations](#limitations)
|
|
69
68
|
|
|
70
|
-
* [Acknowledgement](#acknowledgement)
|
|
71
|
-
|
|
72
69
|
* [Changelog](#changelog)
|
|
73
70
|
|
|
71
|
+
* [Acknowledgement](#acknowledgement)
|
|
72
|
+
|
|
74
73
|
* [Differences with IceCream](#differences-with-icecream)
|
|
75
74
|
|
|
76
75
|
|
|
@@ -85,9 +84,10 @@ or when you want to upgrade,
|
|
|
85
84
|
pip install peek-python --upgrade
|
|
86
85
|
```
|
|
87
86
|
|
|
88
|
-
Alternatively, peek.py can be just copied into you current work directory from GitHub
|
|
87
|
+
Alternatively, peek.py can be just copied into you current work directory from GitHub
|
|
88
|
+
(https://github.com/salabim/peek).
|
|
89
89
|
|
|
90
|
-
Note that peek requires the `asttokens`, `colorama`, `executing`. `six`, `tomli` and `pyperclip` modules, all of which will be automatically installed
|
|
90
|
+
Note that peek requires the `asttokens`, `colorama`, `executing`. `six`, `tomli` and `pyperclip` modules, all of which will be automatically installed.
|
|
91
91
|
|
|
92
92
|
# Importing peek
|
|
93
93
|
|
|
@@ -103,9 +103,8 @@ import peek
|
|
|
103
103
|
from peek import peek
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
> After this, `peek` is automatically a builtin and can thus be used in any module without importing it there.
|
|
106
|
+
Note that after this, `peek` is automatically a builtin and can thus be used in any module without
|
|
107
|
+
importing it there.
|
|
109
108
|
|
|
110
109
|
# Inspect variables and expressions
|
|
111
110
|
|
|
@@ -155,7 +154,7 @@ prints
|
|
|
155
154
|
```
|
|
156
155
|
world={"EN": "world ", "NL": "wereld", "FR": "monde", "DE": "Welt"}, X.a: 3
|
|
157
156
|
```
|
|
158
|
-
Just give `peek()` a variable or expression and you're done.
|
|
157
|
+
Just give `peek()` a variable or expression and you're done.
|
|
159
158
|
|
|
160
159
|
|
|
161
160
|
# Inspect execution
|
|
@@ -189,8 +188,6 @@ prints something like
|
|
|
189
188
|
#5 in add2()
|
|
190
189
|
add2(1000)=1002
|
|
191
190
|
```
|
|
192
|
-
Just call `peek()` and you're done. Isn't that easy?
|
|
193
|
-
|
|
194
191
|
|
|
195
192
|
# Return Value
|
|
196
193
|
|
|
@@ -322,9 +319,9 @@ a number of configuration attributes:
|
|
|
322
319
|
attribute alternative default
|
|
323
320
|
------------------------------------------------------
|
|
324
321
|
color col "-"
|
|
325
|
-
color_value
|
|
326
|
-
context_separator cs " ==> "
|
|
322
|
+
color_value col_val "-"
|
|
327
323
|
compact - False
|
|
324
|
+
context_separator cs " ==> "
|
|
328
325
|
depth - 1000000
|
|
329
326
|
delta - 0
|
|
330
327
|
enabled - True
|
|
@@ -348,10 +345,10 @@ show_time st False
|
|
|
348
345
|
show_traceback - False
|
|
349
346
|
sort_dicts - False
|
|
350
347
|
to_clipboard clip False
|
|
351
|
-
underscore_numbers un False
|
|
352
|
-
wrap_indent - " "
|
|
348
|
+
underscore_numbers un False
|
|
353
349
|
values_only vo False
|
|
354
350
|
value_only_for_fstrings voff False
|
|
351
|
+
wrap_indent - " "
|
|
355
352
|
------------------------------------------------------
|
|
356
353
|
```
|
|
357
354
|
It is perfectly ok to set/get any of these attributes directly, like
|
|
@@ -362,7 +359,6 @@ print(peek.prefix)
|
|
|
362
359
|
|
|
363
360
|
But, it is also possible to apply configuration directly, only here, in the call to `peek`:
|
|
364
361
|
So, it is possible to say
|
|
365
|
-
|
|
366
362
|
```
|
|
367
363
|
peek(12, prefix="==> ")
|
|
368
364
|
```
|
|
@@ -370,23 +366,25 @@ peek(12, prefix="==> ")
|
|
|
370
366
|
```
|
|
371
367
|
==> 12
|
|
372
368
|
```
|
|
373
|
-
It is also possible to configure
|
|
369
|
+
It is also possible to configure several attributes permanently with the configure method.
|
|
374
370
|
```
|
|
375
|
-
peek.configure(prefix="==> ")
|
|
371
|
+
peek.configure(prefix="==> ", color="blue")
|
|
376
372
|
peek(12)
|
|
377
373
|
```
|
|
378
|
-
will print
|
|
374
|
+
will print in blue
|
|
379
375
|
```
|
|
380
376
|
==> 12
|
|
381
377
|
```
|
|
382
378
|
It is arguably easier to say:
|
|
383
379
|
```
|
|
384
380
|
peek.prefix = "==> "
|
|
381
|
+
peek.color = "blue"
|
|
385
382
|
peek(12)
|
|
386
383
|
```
|
|
387
384
|
or even
|
|
388
385
|
```
|
|
389
386
|
peek.pr = "==> "
|
|
387
|
+
peek.col = "blue"
|
|
390
388
|
peek(12)
|
|
391
389
|
```
|
|
392
390
|
to print
|
|
@@ -395,7 +393,7 @@ to print
|
|
|
395
393
|
```
|
|
396
394
|
Yet another way to configure peek is to get a new instance of peek with peek.new() and the required configuration:
|
|
397
395
|
```
|
|
398
|
-
z = peek.new(prefix="==> ")
|
|
396
|
+
z = peek.new(prefix="==> ", color="blue")
|
|
399
397
|
z(12)
|
|
400
398
|
```
|
|
401
399
|
will print
|
|
@@ -620,7 +618,7 @@ prints
|
|
|
620
618
|
The `show_traceback` functionality is also available when peek is used as a decorator or context manager.
|
|
621
619
|
|
|
622
620
|
## line_length / ll
|
|
623
|
-
This attribute is used to specify the line length (for wrapping). The default is
|
|
621
|
+
This attribute is used to specify the line length (for wrapping). The default is 80.
|
|
624
622
|
Peek tries to keep all output on one line, but if it can't it will wrap:
|
|
625
623
|
|
|
626
624
|
```
|
|
@@ -637,7 +635,7 @@ d=
|
|
|
637
635
|
'a3': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}
|
|
638
636
|
```
|
|
639
637
|
|
|
640
|
-
## color / col and color_value /
|
|
638
|
+
## color / col and color_value / colv
|
|
641
639
|
The color attribute is used to specify the color of the output.
|
|
642
640
|
There's a choice of black, white, red, green, blue, cyan, magenta and yellow.
|
|
643
641
|
To set the color to 'nothing', use "-".
|
|
@@ -665,7 +663,7 @@ Of course, color and color_value may be specified in a peek.toml file, to make a
|
|
|
665
663
|
>
|
|
666
664
|
> The color and color_value attributes are only applied when using stdout as output.
|
|
667
665
|
>
|
|
668
|
-
> Colors can be ignored completely by using `peek.output = "stdout_nocolor
|
|
666
|
+
> Colors can be ignored completely by using `peek.output = "stdout_nocolor`.
|
|
669
667
|
|
|
670
668
|
## compact
|
|
671
669
|
This attribute is used to specify the compact parameter for `pformat` (see the pprint documentation
|
|
@@ -818,6 +816,8 @@ numbers={'one': 1, 'thousand': 1_000, 'million': 1_000_000, 'x1234567890': 1_234
|
|
|
818
816
|
numbers={'one': 1, 'thousand': 1000, 'million': 1000000, 'x1234567890': 1234567890}
|
|
819
817
|
```
|
|
820
818
|
|
|
819
|
+
Note that under Python <=3.7, numbers are never underscored.
|
|
820
|
+
|
|
821
821
|
## seperator / sep
|
|
822
822
|
|
|
823
823
|
By default, pairs (on one line) are separated by `, `.
|
|
@@ -836,7 +836,6 @@ prints
|
|
|
836
836
|
a='abcd', (b,c)=(1, 1000), d=['peek', 'c', 'e', 'c', 'r', 'e', 'a', 'm']
|
|
837
837
|
a='abcd' | (b,c)=(1, 1000) | d=['peek', 'c', 'e', 'c', 'r', 'e', 'a', 'm']
|
|
838
838
|
```
|
|
839
|
-
Note that under Python <=3.7, numbers are never printed with underscores.
|
|
840
839
|
|
|
841
840
|
## context_separator
|
|
842
841
|
|
|
@@ -909,14 +908,15 @@ If True, the left_hand side will be suppressed in case of an f-string:
|
|
|
909
908
|
|
|
910
909
|
```
|
|
911
910
|
x = 12.3
|
|
912
|
-
peek
|
|
911
|
+
peek.quote_string = False
|
|
912
|
+
peek(f"{x=:0.3e}")
|
|
913
913
|
peek.values_only_for_fstrings = True
|
|
914
|
-
peek(f"{x
|
|
914
|
+
peek(f"{x=:0.3e}")
|
|
915
915
|
```
|
|
916
916
|
prints
|
|
917
917
|
```
|
|
918
|
-
f"{x
|
|
919
|
-
|
|
918
|
+
f"{x=:0.3e}"=x=1.230e+01
|
|
919
|
+
x=1.230e+01
|
|
920
920
|
```
|
|
921
921
|
Note that if `values_only` is True, f-string will be suppressed, regardless of `values_only_for_fstrings`.
|
|
922
922
|
|
|
@@ -990,7 +990,7 @@ delta=0.011826 ==> 2
|
|
|
990
990
|
delta=0.044893 ==> 6
|
|
991
991
|
True
|
|
992
992
|
```
|
|
993
|
-
Of course `peek()` continues to return its arguments when disabled
|
|
993
|
+
Of course `peek()` continues to return its arguments when disabled.
|
|
994
994
|
|
|
995
995
|
It is also possible to suppress output with the provided attribute (see above).
|
|
996
996
|
|
|
@@ -1014,7 +1014,7 @@ It is possible to use more than one attribute, like
|
|
|
1014
1014
|
```
|
|
1015
1015
|
peek.filter = "color == 'blue' and delta > 5"
|
|
1016
1016
|
```
|
|
1017
|
-
As an alternative to `enabled` we can
|
|
1017
|
+
As an alternative to `enabled` we can alo say
|
|
1018
1018
|
```
|
|
1019
1019
|
peek.filter = "False"
|
|
1020
1020
|
```
|
|
@@ -1023,7 +1023,7 @@ peek.filter = "False"
|
|
|
1023
1023
|
|
|
1024
1024
|
It is possible to copy a value to the clipboard. There are two ways:
|
|
1025
1025
|
|
|
1026
|
-
### With peek(
|
|
1026
|
+
### With peek(to_clipboard=True)
|
|
1027
1027
|
|
|
1028
1028
|
With the optional keyword argument, *to_clipboard*:
|
|
1029
1029
|
|
|
@@ -1089,22 +1089,22 @@ The parent function can be suppressed by setting `show_line_number` or `sln` to
|
|
|
1089
1089
|
|
|
1090
1090
|
It can be useful to configure peek at import time. This can be done by providing a `peek.toml` file which
|
|
1091
1091
|
can contain any attribute configuration overriding the standard settings.
|
|
1092
|
-
E.g. if there is
|
|
1092
|
+
E.g. if there is a `peek.toml` file with the following contents
|
|
1093
1093
|
|
|
1094
1094
|
```
|
|
1095
1095
|
outpout = "stderr"
|
|
1096
1096
|
show_time = true
|
|
1097
1097
|
ll = 160
|
|
1098
|
-
|
|
1098
|
+
quote_string = false
|
|
1099
1099
|
```
|
|
1100
1100
|
in the same folder as the application, this program:
|
|
1101
1101
|
```
|
|
1102
1102
|
hello = "world"
|
|
1103
1103
|
peek(hello)
|
|
1104
1104
|
```
|
|
1105
|
-
will print to stderr (rather than stdout):
|
|
1105
|
+
will print something like this to stderr (rather than stdout):
|
|
1106
1106
|
```
|
|
1107
|
-
@ 14:53:41.392190 ==> hello=
|
|
1107
|
+
@ 14:53:41.392190 ==> hello=world
|
|
1108
1108
|
```
|
|
1109
1109
|
At import time current directory will be searched for `peek.toml` and if not found, one level up, etc. until the root directory is reached.
|
|
1110
1110
|
|
|
@@ -1136,15 +1136,14 @@ Normally, only the `peek` object is used.
|
|
|
1136
1136
|
It can be useful to have multiple instances, e.g. when some of the debugging has to be done with context information
|
|
1137
1137
|
and others requires an alternative prefix.
|
|
1138
1138
|
|
|
1139
|
-
|
|
1139
|
+
THere are several ways to obtain a new instance of peek:
|
|
1140
1140
|
|
|
1141
1141
|
* by using `peek.new()`
|
|
1142
1142
|
|
|
1143
1143
|
With this a new peek object is created with the default attributes
|
|
1144
|
-
and possibly peek.toml overrides.
|
|
1145
1144
|
* by using `peek.new(ignore_toml=True)`
|
|
1146
1145
|
|
|
1147
|
-
With this a new
|
|
1146
|
+
With this a new peekobject is created with the default attibutes. Any peek.toml files are ignored.
|
|
1148
1147
|
* by using `peek.fork()`
|
|
1149
1148
|
|
|
1150
1149
|
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.
|
|
@@ -1232,15 +1231,9 @@ Peek may be used in a REPL, but with limited functionality:
|
|
|
1232
1231
|
* use as a decorator is not supported
|
|
1233
1232
|
* use as a context manager is not supported
|
|
1234
1233
|
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
In that case, it is possible to use p instead
|
|
1240
|
-
```
|
|
1241
|
-
from peek import p
|
|
1242
|
-
```
|
|
1243
|
-
The `p` object is a *fork* of peek. That means that attributes of `peek` are propagated to `p`, unless overridden.
|
|
1234
|
+
> [!NOTE]
|
|
1235
|
+
>
|
|
1236
|
+
> Under Python >=3.13 most of the normal peek functionality is available in the REPL. A reason to upgrade!
|
|
1244
1237
|
|
|
1245
1238
|
|
|
1246
1239
|
# Limitations
|
|
@@ -1259,12 +1252,11 @@ The changelog can be found here:
|
|
|
1259
1252
|
|
|
1260
1253
|
# Acknowledgement
|
|
1261
1254
|
|
|
1262
|
-
The **peek** package is inspired by the **IceCream** package, but is a
|
|
1263
|
-
nearly complete rewrite. See https://github.com/gruns/icecream
|
|
1255
|
+
The **peek** package is inspired by the **IceCream** package, but is a nearly complete rewrite. See https://github.com/gruns/icecream
|
|
1264
1256
|
|
|
1265
1257
|
Many thanks to the author Ansgar Grunseid / grunseid.com / grunseid@gmail.com .
|
|
1266
1258
|
|
|
1267
|
-
The peek package is a rebrand of the **ycecream** package, with enhancements.
|
|
1259
|
+
The peek package is a rebrand of the **ycecream** package, with many enhancements.
|
|
1268
1260
|
|
|
1269
1261
|
# Differences with IceCream
|
|
1270
1262
|
|
|
@@ -1299,7 +1291,7 @@ colorize ***) yes, off by default yes, on by default
|
|
|
1299
1291
|
-----------------------------------------------------------------------------------------
|
|
1300
1292
|
*) under Python <= 3.7, dicts are always sorted
|
|
1301
1293
|
**) under Python <= 3.7, numbers are never underscored
|
|
1302
|
-
***) peek allows selection of
|
|
1294
|
+
***) peek allows selection of colors, whereas IceCream does coloring based on contents.
|
|
1303
1295
|
|
|
1304
1296
|
```
|
|
1305
1297
|
  
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|