peek-python 24.0.5__tar.gz → 25.0.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: peek-python
3
- Version: 24.0.5
3
+ Version: 25.0.0
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 use peek like print with extras](#use-peek.print-to-to use peek like-with-extras)
47
+ * [Use peek.print to use peek like print with extras](#use-peekprint-to-use-peek-like-print-with-extras)
48
48
 
49
49
  * [Return a string instead of sending to output](#return-a-string-instead-of-sending-to-output)
50
50
 
@@ -86,11 +86,12 @@ or when you want to upgrade,
86
86
  pip install peek-python --upgrade
87
87
  ```
88
88
 
89
- Alternatively, peek.py can be just copied into you current work directory from GitHub
90
- (https://github.com/salabim/peek).
91
-
92
89
  Note that peek requires the `asttokens`, `colorama`, `executing`. `six`, `tomli` and `pyperclip` modules, all of which will be automatically installed.
93
90
 
91
+ > [!NOTE]
92
+ >
93
+ > The GitHub repository can be found on https://github.com/salabim/peek .
94
+
94
95
  # Importing peek
95
96
 
96
97
  All you need is:
@@ -108,6 +109,7 @@ from peek import peek
108
109
  Note that after this, `peek` is automatically a builtin and can thus be used in any module without
109
110
  importing it there.
110
111
 
112
+
111
113
  # Inspect variables and expressions
112
114
 
113
115
  Have you ever printed variables or expressions to debug your program? If you've
@@ -154,10 +156,24 @@ peek(world, X.a)
154
156
 
155
157
  prints
156
158
  ```
157
- world={"EN": "world ", "NL": "wereld", "FR": "monde", "DE": "Welt"}, X.a: 3
159
+ world={"EN": "world ", "NL": "wereld", "FR": "monde", "DE": "Welt"}, X.a=3
158
160
  ```
159
161
  Just give `peek()` a variable or expression and you're done.
160
162
 
163
+ And you can even add color to distinguish between peek's output lines:
164
+
165
+ ```
166
+ for number in range(10):
167
+ number_divided_by_3 = number / 3
168
+ if number % 3 == 0:
169
+ peek(number, number_divided_by_3, color="red")
170
+ else:
171
+ peek(number, number_divided_by_3, color="yellow")
172
+ ```
173
+
174
+ This will result in:
175
+
176
+ <img src="https://www.salabim.org/peek/peek_colors1.png">
161
177
 
162
178
  # Inspect execution
163
179
 
@@ -214,8 +230,8 @@ The (keyword) arguments passed will be shown and upon return, the return value.
214
230
 
215
231
  ```
216
232
  @peek()
217
- def mul(x, peek):
218
- return x * peek
233
+ def mul(x, y):
234
+ return x * y
219
235
 
220
236
  print(mul(5, 7))
221
237
  ```
@@ -321,13 +337,13 @@ a number of configuration attributes:
321
337
  attribute alternative default
322
338
  ------------------------------------------------------
323
339
  color col "-"
324
- color_value col_val "-"
340
+ color_value col_val "-"
325
341
  compact - False
326
342
  context_separator cs " ==> "
327
343
  depth - 1000000
328
344
  delta - 0
329
345
  enabled - True
330
- end - "\n"
346
+ end - "\n"
331
347
  equals_separator - "="
332
348
  filter f ""
333
349
  indent - 1
@@ -336,7 +352,7 @@ line_length ll 80
336
352
  output - "stdout"
337
353
  prefix pr ""
338
354
  print_like print False
339
- quote_string qs True
355
+ quote_string qs True
340
356
  return_none - False
341
357
  separator sep ", "
342
358
  separator_print sepp "" "
@@ -363,6 +379,7 @@ print(peek.prefix)
363
379
 
364
380
  But, it is also possible to apply configuration directly, only here, in the call to `peek`:
365
381
  So, it is possible to say
382
+
366
383
  ```
367
384
  peek(12, prefix="==> ")
368
385
  ```
@@ -397,8 +414,8 @@ to print
397
414
  ```
398
415
  Yet another way to configure peek is to get a new instance of peek with peek.new() and the required configuration:
399
416
  ```
400
- z = peek.new(prefix="==> ", color="blue")
401
- z(12)
417
+ peek0 = peek.new(prefix="==> ", color="blue")
418
+ peek0(12)
402
419
  ```
403
420
  will print
404
421
  ```
@@ -432,7 +449,7 @@ hello = "world"
432
449
  peek.prefix = unix_timestamp
433
450
  peek(hello)
434
451
  ```
435
- prints
452
+ prints something like
436
453
  ```
437
454
  1613635601 hello='world'
438
455
  ```
@@ -490,7 +507,6 @@ Finally, you can specify the following strings:
490
507
  ```
491
508
  E.g.
492
509
  ```
493
- import sys
494
510
  peek.output = "stderr"
495
511
  ```
496
512
  to print to stderr.
@@ -510,13 +526,13 @@ def add_len(obj):
510
526
  add = ""
511
527
  return f"{repr(obj)}{add}"
512
528
 
513
- l7 = list(range(7))
529
+ zero_to_six = list(range(7))
514
530
  hello = "world"
515
- peek(7, hello, l7, serialize=add_len)
531
+ peek(7, hello, zero_to_six, serialize=add_len)
516
532
  ```
517
533
  prints
518
534
  ```
519
- 7, hello='world' [len=5], l7=[0, 1, 2, 3, 4, 5, 6] [len=7]
535
+ 7, hello='world' [len=5], zero_to_six=[0, 1, 2, 3, 4, 5, 6] [len=7]
520
536
  ```
521
537
 
522
538
  ## show_line_number / sln
@@ -604,7 +620,7 @@ def x():
604
620
  x()
605
621
  x()
606
622
  ```
607
- prints
623
+ prints something like
608
624
  ```
609
625
  #4 in x()
610
626
  Traceback (most recent call last)
@@ -628,15 +644,15 @@ Peek tries to keep all output on one line, but if it can't it will wrap:
628
644
  ```
629
645
  d = dict(a1=1,a2=dict(a=1,b=1,c=3),a3=list(range(10)))
630
646
  peek(d)
631
- peek(d, line_length=80)
647
+ peek(d, line_length=160)
632
648
  ```
633
649
  prints
634
650
  ```
635
- d={'a1': 1, 'a2': {'a': 1, 'b': 1, 'c': 3}, 'a3': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}
636
651
  d=
637
652
  {'a1': 1,
638
653
  'a2': {'a': 1, 'b': 1, 'c': 3},
639
654
  'a3': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}
655
+ d={'a1': 1, 'a2': {'a': 1, 'b': 1, 'c': 3}, 'a3': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}
640
656
  ```
641
657
 
642
658
  ## color / col and color_value / colv
@@ -649,17 +665,18 @@ On top of that, color_value may be used to specify the value part of an output i
649
665
  For instance:
650
666
 
651
667
  ```
652
- x = "x"
653
- y = "y"
654
- peek(x, y)
655
- peek(x, y, color_value="green")
656
- peek(x, y, color="red")
657
- peek(x, y, color="red", color_value="green")
668
+ item1 = "value1"
669
+ item2 = "value2"
670
+ peek.color="yellow"
671
+ peek(item1, item2)
672
+ peek(item1, item2, color_value="green")
673
+ peek(item1, item2, color="red")
674
+ peek(item1, item2, color="red", color_value="green")
658
675
  ```
659
676
 
660
677
  will result in:
661
678
 
662
- <img src="https://www.salabim.org/peek/peek_colors.png">
679
+ <img src="https://www.salabim.org/peek/peek_colors2.png">
663
680
 
664
681
  Of course, color and color_value may be specified in a peek.toml file, to make all peek output in a specified color.
665
682
 
@@ -824,7 +841,7 @@ Note that under Python <=3.7, numbers are never underscored.
824
841
 
825
842
  ## seperator / sep
826
843
 
827
- By default, pairs (on one line) are separated by `", ""`.
844
+ By default, pairs (on one line) are separated by `", "`.
828
845
  It is possible to change this with the attribute ` separator`:
829
846
 
830
847
  ```
@@ -1003,7 +1020,7 @@ So,
1003
1020
  ```
1004
1021
  peek.filter = "level==1"
1005
1022
  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)
1023
+ peek.print(f"{min(1, 2)=}", color="red", level=1)
1007
1024
  ```
1008
1025
 
1009
1026
  will print
@@ -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 use peek like print with extras](#use-peek.print-to-to use peek like-with-extras)
27
+ * [Use peek.print to use peek like print with extras](#use-peekprint-to-use-peek-like-print-with-extras)
28
28
 
29
29
  * [Return a string instead of sending to output](#return-a-string-instead-of-sending-to-output)
30
30
 
@@ -66,11 +66,12 @@ or when you want to upgrade,
66
66
  pip install peek-python --upgrade
67
67
  ```
68
68
 
69
- Alternatively, peek.py can be just copied into you current work directory from GitHub
70
- (https://github.com/salabim/peek).
71
-
72
69
  Note that peek requires the `asttokens`, `colorama`, `executing`. `six`, `tomli` and `pyperclip` modules, all of which will be automatically installed.
73
70
 
71
+ > [!NOTE]
72
+ >
73
+ > The GitHub repository can be found on https://github.com/salabim/peek .
74
+
74
75
  # Importing peek
75
76
 
76
77
  All you need is:
@@ -88,6 +89,7 @@ from peek import peek
88
89
  Note that after this, `peek` is automatically a builtin and can thus be used in any module without
89
90
  importing it there.
90
91
 
92
+
91
93
  # Inspect variables and expressions
92
94
 
93
95
  Have you ever printed variables or expressions to debug your program? If you've
@@ -134,10 +136,24 @@ peek(world, X.a)
134
136
 
135
137
  prints
136
138
  ```
137
- world={"EN": "world ", "NL": "wereld", "FR": "monde", "DE": "Welt"}, X.a: 3
139
+ world={"EN": "world ", "NL": "wereld", "FR": "monde", "DE": "Welt"}, X.a=3
138
140
  ```
139
141
  Just give `peek()` a variable or expression and you're done.
140
142
 
143
+ And you can even add color to distinguish between peek's output lines:
144
+
145
+ ```
146
+ for number in range(10):
147
+ number_divided_by_3 = number / 3
148
+ if number % 3 == 0:
149
+ peek(number, number_divided_by_3, color="red")
150
+ else:
151
+ peek(number, number_divided_by_3, color="yellow")
152
+ ```
153
+
154
+ This will result in:
155
+
156
+ <img src="https://www.salabim.org/peek/peek_colors1.png">
141
157
 
142
158
  # Inspect execution
143
159
 
@@ -194,8 +210,8 @@ The (keyword) arguments passed will be shown and upon return, the return value.
194
210
 
195
211
  ```
196
212
  @peek()
197
- def mul(x, peek):
198
- return x * peek
213
+ def mul(x, y):
214
+ return x * y
199
215
 
200
216
  print(mul(5, 7))
201
217
  ```
@@ -301,13 +317,13 @@ a number of configuration attributes:
301
317
  attribute alternative default
302
318
  ------------------------------------------------------
303
319
  color col "-"
304
- color_value col_val "-"
320
+ color_value col_val "-"
305
321
  compact - False
306
322
  context_separator cs " ==> "
307
323
  depth - 1000000
308
324
  delta - 0
309
325
  enabled - True
310
- end - "\n"
326
+ end - "\n"
311
327
  equals_separator - "="
312
328
  filter f ""
313
329
  indent - 1
@@ -316,7 +332,7 @@ line_length ll 80
316
332
  output - "stdout"
317
333
  prefix pr ""
318
334
  print_like print False
319
- quote_string qs True
335
+ quote_string qs True
320
336
  return_none - False
321
337
  separator sep ", "
322
338
  separator_print sepp "" "
@@ -343,6 +359,7 @@ print(peek.prefix)
343
359
 
344
360
  But, it is also possible to apply configuration directly, only here, in the call to `peek`:
345
361
  So, it is possible to say
362
+
346
363
  ```
347
364
  peek(12, prefix="==> ")
348
365
  ```
@@ -377,8 +394,8 @@ to print
377
394
  ```
378
395
  Yet another way to configure peek is to get a new instance of peek with peek.new() and the required configuration:
379
396
  ```
380
- z = peek.new(prefix="==> ", color="blue")
381
- z(12)
397
+ peek0 = peek.new(prefix="==> ", color="blue")
398
+ peek0(12)
382
399
  ```
383
400
  will print
384
401
  ```
@@ -412,7 +429,7 @@ hello = "world"
412
429
  peek.prefix = unix_timestamp
413
430
  peek(hello)
414
431
  ```
415
- prints
432
+ prints something like
416
433
  ```
417
434
  1613635601 hello='world'
418
435
  ```
@@ -470,7 +487,6 @@ Finally, you can specify the following strings:
470
487
  ```
471
488
  E.g.
472
489
  ```
473
- import sys
474
490
  peek.output = "stderr"
475
491
  ```
476
492
  to print to stderr.
@@ -490,13 +506,13 @@ def add_len(obj):
490
506
  add = ""
491
507
  return f"{repr(obj)}{add}"
492
508
 
493
- l7 = list(range(7))
509
+ zero_to_six = list(range(7))
494
510
  hello = "world"
495
- peek(7, hello, l7, serialize=add_len)
511
+ peek(7, hello, zero_to_six, serialize=add_len)
496
512
  ```
497
513
  prints
498
514
  ```
499
- 7, hello='world' [len=5], l7=[0, 1, 2, 3, 4, 5, 6] [len=7]
515
+ 7, hello='world' [len=5], zero_to_six=[0, 1, 2, 3, 4, 5, 6] [len=7]
500
516
  ```
501
517
 
502
518
  ## show_line_number / sln
@@ -584,7 +600,7 @@ def x():
584
600
  x()
585
601
  x()
586
602
  ```
587
- prints
603
+ prints something like
588
604
  ```
589
605
  #4 in x()
590
606
  Traceback (most recent call last)
@@ -608,15 +624,15 @@ Peek tries to keep all output on one line, but if it can't it will wrap:
608
624
  ```
609
625
  d = dict(a1=1,a2=dict(a=1,b=1,c=3),a3=list(range(10)))
610
626
  peek(d)
611
- peek(d, line_length=80)
627
+ peek(d, line_length=160)
612
628
  ```
613
629
  prints
614
630
  ```
615
- d={'a1': 1, 'a2': {'a': 1, 'b': 1, 'c': 3}, 'a3': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}
616
631
  d=
617
632
  {'a1': 1,
618
633
  'a2': {'a': 1, 'b': 1, 'c': 3},
619
634
  'a3': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}
635
+ d={'a1': 1, 'a2': {'a': 1, 'b': 1, 'c': 3}, 'a3': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]}
620
636
  ```
621
637
 
622
638
  ## color / col and color_value / colv
@@ -629,17 +645,18 @@ On top of that, color_value may be used to specify the value part of an output i
629
645
  For instance:
630
646
 
631
647
  ```
632
- x = "x"
633
- y = "y"
634
- peek(x, y)
635
- peek(x, y, color_value="green")
636
- peek(x, y, color="red")
637
- peek(x, y, color="red", color_value="green")
648
+ item1 = "value1"
649
+ item2 = "value2"
650
+ peek.color="yellow"
651
+ peek(item1, item2)
652
+ peek(item1, item2, color_value="green")
653
+ peek(item1, item2, color="red")
654
+ peek(item1, item2, color="red", color_value="green")
638
655
  ```
639
656
 
640
657
  will result in:
641
658
 
642
- <img src="https://www.salabim.org/peek/peek_colors.png">
659
+ <img src="https://www.salabim.org/peek/peek_colors2.png">
643
660
 
644
661
  Of course, color and color_value may be specified in a peek.toml file, to make all peek output in a specified color.
645
662
 
@@ -804,7 +821,7 @@ Note that under Python <=3.7, numbers are never underscored.
804
821
 
805
822
  ## seperator / sep
806
823
 
807
- By default, pairs (on one line) are separated by `", ""`.
824
+ By default, pairs (on one line) are separated by `", "`.
808
825
  It is possible to change this with the attribute ` separator`:
809
826
 
810
827
  ```
@@ -983,7 +1000,7 @@ So,
983
1000
  ```
984
1001
  peek.filter = "level==1"
985
1002
  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)
1003
+ peek.print(f"{min(1, 2)=}", color="red", level=1)
987
1004
  ```
988
1005
 
989
1006
  will print