peek-python 24.0.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: peek-python
3
- Version: 24.0.3
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,6 +44,8 @@ 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)
48
+
47
49
  * [Return a string instead of sending to output](#return-a-string-instead-of-sending-to-output)
48
50
 
49
51
  * [Disabling peek's output](#disabling-peeks-output)
@@ -325,7 +327,7 @@ context_separator cs " ==> "
325
327
  depth - 1000000
326
328
  delta - 0
327
329
  enabled - True
328
- enforce_line_length - False
330
+ end - "\n"
329
331
  equals_separator - "="
330
332
  filter f ""
331
333
  indent - 1
@@ -333,9 +335,11 @@ level lvl 0
333
335
  line_length ll 80
334
336
  output - "stdout"
335
337
  prefix pr ""
338
+ print_like print False
336
339
  quote_string qs True
337
340
  return_none - False
338
341
  separator sep ", "
342
+ separator_print sepp "" "
339
343
  serialize - pprint.pformat
340
344
  show_delta sd False
341
345
  show_enter se True
@@ -820,7 +824,7 @@ Note that under Python <=3.7, numbers are never underscored.
820
824
 
821
825
  ## seperator / sep
822
826
 
823
- By default, pairs (on one line) are separated by `, `.
827
+ By default, pairs (on one line) are separated by `", ""`.
824
828
  It is possible to change this with the attribute ` separator`:
825
829
 
826
830
  ```
@@ -833,8 +837,8 @@ peek(a, (b, c), d, separator=" | ")
833
837
  ```
834
838
  prints
835
839
  ```
836
- a='abcd', (b,c)=(1, 1000), d=['peek', 'c', 'e', 'c', 'r', 'e', 'a', 'm']
837
- a='abcd' | (b,c)=(1, 1000) | d=['peek', 'c', 'e', 'c', 'r', 'e', 'a', 'm']
840
+ a='abcd', (b,c)=(1, 1000), d=['p', 'e', 'e', 'k']
841
+ a='abcd' | (b,c)=(1, 1000) | d=['p', 'e', 'e', 'k']
838
842
  ```
839
843
 
840
844
  ## context_separator
@@ -898,8 +902,6 @@ prints
898
902
  hello='world', 2 * hello='worldworld'
899
903
  'world', 'worldworld'
900
904
  ```
901
- The values=True version of peek can be seen as a supercharged print/pprint.
902
-
903
905
 
904
906
  ## values_only_for_fstrings / voff
905
907
  If False (the default), both the original f-string and the
@@ -920,6 +922,31 @@ x=1.230e+01
920
922
  ```
921
923
  Note that if `values_only` is True, f-string will be suppressed, regardless of `values_only_for_fstrings`.
922
924
 
925
+
926
+ ## end
927
+
928
+ The `end` attribute works like the end parameter of print. By default, `end` is "\n".
929
+ This can be useful to have several peek outputs on one line, like:
930
+
931
+ ```
932
+ for i in range(5):
933
+ peek(i*i, end=' ')
934
+ peek('')
935
+ ```
936
+ Maybe more useful is to show the output change on the same line, e.g. a status.
937
+ ```
938
+ import time
939
+ for i in range(50):
940
+ peek(f"time {time.time()}",end="\r")
941
+ time.sleep(0.1)
942
+ peek('')
943
+ ```
944
+ The `end` parameter will be only applied when output is stdout, stdout_nocolor or stderr.
945
+
946
+ > [!NOTE]
947
+ >
948
+ > `\r` does not work under Pythonista.
949
+
923
950
  ## return_none
924
951
  Normally, `peek()`returns the values passed directly, which is usually fine. However, when used in a notebook
925
952
  or REPL, that value will be shown, and that can be annoying. Therefore, if `return_none`is True, `peek()`will
@@ -940,9 +967,6 @@ a=3, b=4
940
967
  None
941
968
  ```
942
969
 
943
- ## enforce_line_length
944
- If enforce_line_length is True, all output lines are explicitly truncated to the given line_length, even those that are not truncated by pformat.
945
-
946
970
  ## delta
947
971
  The delta attribute can be used to (re)set the current delta, e.g.
948
972
  ```
@@ -951,6 +975,76 @@ print(peek.delta)
951
975
  ```
952
976
  prints a value that id slightly more than 0.
953
977
 
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`.
1000
+
1001
+ So,
1002
+
1003
+ ```
1004
+ peek.filter = "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)
1007
+ ```
1008
+
1009
+ will print
1010
+
1011
+ ```
1012
+ min(1, 2)=1
1013
+ ```
1014
+
1015
+ in red, but only if peek.enabled is True (which is the default).
1016
+
1017
+ The `peek.print`() method applies the prefix, show_delta, show_line_number, show_time, show_ end attributes to the output.
1018
+
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`.
1020
+ When calling `peek.print`, `sep` may be used instead. So
1021
+
1022
+ ```
1023
+ peek.sepp = "|"
1024
+ peek.print("test")
1025
+ ```
1026
+
1027
+ Has the same effect as
1028
+
1029
+ ```
1030
+ peek.print("test", sep="|")
1031
+ ```
1032
+
1033
+ and
1034
+
1035
+ ```
1036
+ peek.print("test", sepp="|")
1037
+ ```
1038
+
1039
+ but not the same as
1040
+
1041
+ ```
1042
+ peek.sep = "|" # sets the 'normal' peek separator
1043
+ ```
1044
+ > [!NOTE]
1045
+ >
1046
+ > `peek.print` does not obey the line length and will always return None (unless as_str is True).
1047
+
954
1048
  # Return a string instead of sending to output
955
1049
 
956
1050
  `peek(*args, as_str=True)` is like `peek(*args)` but the output is returned as a string instead
@@ -1014,7 +1108,7 @@ It is possible to use more than one attribute, like
1014
1108
  ```
1015
1109
  peek.filter = "color == 'blue' and delta > 5"
1016
1110
  ```
1017
- As an alternative to `enabled` we can alo say
1111
+ As an alternative to `enabled` we can also say
1018
1112
  ```
1019
1113
  peek.filter = "False"
1020
1114
  ```
@@ -1136,14 +1230,14 @@ Normally, only the `peek` object is used.
1136
1230
  It can be useful to have multiple instances, e.g. when some of the debugging has to be done with context information
1137
1231
  and others requires an alternative prefix.
1138
1232
 
1139
- THere are several ways to obtain a new instance of peek:
1233
+ There are several ways to obtain a new instance of peek:
1140
1234
 
1141
1235
  * by using `peek.new()`
1142
1236
 
1143
1237
  With this a new peek object is created with the default attributes
1144
1238
  * by using `peek.new(ignore_toml=True)`
1145
1239
 
1146
- With this a new peekobject is created with the default attibutes. Any peek.toml files are ignored.
1240
+ With this a new peekobject is created with the default attributes. Any peek.toml files are ignored.
1147
1241
  * by using `peek.fork()`
1148
1242
 
1149
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.
@@ -1273,6 +1367,8 @@ usable without installation yes no
1273
1367
  can be used as a decorator yes no
1274
1368
  can be used as a context manager yes no
1275
1369
  can show traceback yes no
1370
+ can be used like print w/extras yes (with peek.print) no
1371
+ allows non linefeed printing yes (via end parameter) requires patching
1276
1372
  PEP8 (Pythonic) API yes no
1277
1373
  sorts dicts no by default, optional *) yes
1278
1374
  supports compact, indent,