peek-python 25.0.20__tar.gz → 25.0.22__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.4
2
2
  Name: peek-python
3
- Version: 25.0.20
3
+ Version: 25.0.22
4
4
  Summary: peek - like print, but 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
@@ -467,7 +467,7 @@ prints something like
467
467
  1613635601 hello='world'
468
468
  ```
469
469
 
470
- output
470
+ ### output
471
471
  This will allow the output to be handled by something else than the default (output being written to stdout).
472
472
 
473
473
  The `output` attribute can be
@@ -1082,9 +1082,9 @@ Maybe more useful is to show the output change on the same line, e.g. a status.
1082
1082
  ```
1083
1083
  import time
1084
1084
  for i in range(50):
1085
- peek(f"time {time.time()}",end="\r")
1086
- time.sleep(0.1)
1087
- peek('')
1085
+ peek.print(f"time {time.time():10.2f}",end="", prefix="\r")
1086
+ time.sleep(0.1)
1087
+ peek.print()
1088
1088
  ```
1089
1089
  > [!NOTE]
1090
1090
  >
@@ -1092,7 +1092,7 @@ peek('')
1092
1092
 
1093
1093
  > [!NOTE]
1094
1094
  >
1095
- > `\r` does not work under Pythonista.
1095
+ > `Under Pythonista \r` has to be at the start of a peek.print output. Otherwise, it does not work.
1096
1096
 
1097
1097
  ### return_none
1098
1098
  Normally, `peek()`returns the values passed directly, which is usually fine. However, when used in a notebook
@@ -1134,7 +1134,7 @@ will print
1134
1134
  ```
1135
1135
  12 min(1, 2)=1 [0, 1, 2, 3]
1136
1136
  ```
1137
- in yellow, but only if peek.enabled is False, nothing will be printed.
1137
+ in yellow, but if peek.enabled is False, nothing will be printed.
1138
1138
 
1139
1139
  You can also use peek.print (see below).
1140
1140
 
@@ -1192,7 +1192,7 @@ peek.sep = "|" # sets the 'normal' peek separator
1192
1192
 
1193
1193
 
1194
1194
  ## Peeking locals and globals
1195
- It is possible to get the name and values of all local or global variables.
1195
+ It is possible to get the names and values of all local or global variables.
1196
1196
 
1197
1197
  To do that, just put `locals` or `globals` in the call to peek, e.g.:
1198
1198
 
@@ -1280,10 +1280,10 @@ It is also possible to suppress output with the provided attribute (see above).
1280
1280
 
1281
1281
  ## Using filter to control peek output
1282
1282
 
1283
- It is possible to define a filter function that determines whether peek output should be suppressed
1283
+ It is possible to define a filter function that determines whether peek output should be suppressed.
1284
1284
  By default, the filter is defined as "" denoting no filter.
1285
1285
 
1286
- Suppose we a (float) level to a peek statement. By default, this level is 0. E.g.:
1286
+ Suppose we add a (float) level to a peek statement. By default, this level is 0. E.g.:
1287
1287
 
1288
1288
  ```
1289
1289
  peek("critical", level=0)
@@ -1291,7 +1291,7 @@ peek("important", level=1)
1291
1291
  peek("warning", level=2)
1292
1292
  ```
1293
1293
 
1294
- With `peek.filter ="level <= 1"` the program makes sure that level=2 is not displayed at all.
1294
+ With `peek.filter = "level <= 1"` the program makes sure that level=2 is not displayed at all.
1295
1295
 
1296
1296
  It is possible to use more than one attribute, like
1297
1297
 
@@ -450,7 +450,7 @@ prints something like
450
450
  1613635601 hello='world'
451
451
  ```
452
452
 
453
- output
453
+ ### output
454
454
  This will allow the output to be handled by something else than the default (output being written to stdout).
455
455
 
456
456
  The `output` attribute can be
@@ -1065,9 +1065,9 @@ Maybe more useful is to show the output change on the same line, e.g. a status.
1065
1065
  ```
1066
1066
  import time
1067
1067
  for i in range(50):
1068
- peek(f"time {time.time()}",end="\r")
1069
- time.sleep(0.1)
1070
- peek('')
1068
+ peek.print(f"time {time.time():10.2f}",end="", prefix="\r")
1069
+ time.sleep(0.1)
1070
+ peek.print()
1071
1071
  ```
1072
1072
  > [!NOTE]
1073
1073
  >
@@ -1075,7 +1075,7 @@ peek('')
1075
1075
 
1076
1076
  > [!NOTE]
1077
1077
  >
1078
- > `\r` does not work under Pythonista.
1078
+ > `Under Pythonista \r` has to be at the start of a peek.print output. Otherwise, it does not work.
1079
1079
 
1080
1080
  ### return_none
1081
1081
  Normally, `peek()`returns the values passed directly, which is usually fine. However, when used in a notebook
@@ -1117,7 +1117,7 @@ will print
1117
1117
  ```
1118
1118
  12 min(1, 2)=1 [0, 1, 2, 3]
1119
1119
  ```
1120
- in yellow, but only if peek.enabled is False, nothing will be printed.
1120
+ in yellow, but if peek.enabled is False, nothing will be printed.
1121
1121
 
1122
1122
  You can also use peek.print (see below).
1123
1123
 
@@ -1175,7 +1175,7 @@ peek.sep = "|" # sets the 'normal' peek separator
1175
1175
 
1176
1176
 
1177
1177
  ## Peeking locals and globals
1178
- It is possible to get the name and values of all local or global variables.
1178
+ It is possible to get the names and values of all local or global variables.
1179
1179
 
1180
1180
  To do that, just put `locals` or `globals` in the call to peek, e.g.:
1181
1181
 
@@ -1263,10 +1263,10 @@ It is also possible to suppress output with the provided attribute (see above).
1263
1263
 
1264
1264
  ## Using filter to control peek output
1265
1265
 
1266
- It is possible to define a filter function that determines whether peek output should be suppressed
1266
+ It is possible to define a filter function that determines whether peek output should be suppressed.
1267
1267
  By default, the filter is defined as "" denoting no filter.
1268
1268
 
1269
- Suppose we a (float) level to a peek statement. By default, this level is 0. E.g.:
1269
+ Suppose we add a (float) level to a peek statement. By default, this level is 0. E.g.:
1270
1270
 
1271
1271
  ```
1272
1272
  peek("critical", level=0)
@@ -1274,7 +1274,7 @@ peek("important", level=1)
1274
1274
  peek("warning", level=2)
1275
1275
  ```
1276
1276
 
1277
- With `peek.filter ="level <= 1"` the program makes sure that level=2 is not displayed at all.
1277
+ With `peek.filter = "level <= 1"` the program makes sure that level=2 is not displayed at all.
1278
1278
 
1279
1279
  It is possible to use more than one attribute, like
1280
1280
 
@@ -4,7 +4,6 @@
4
4
  # | .__/ \___| \___||_|\_\
5
5
  # |_| like print, but easy.
6
6
 
7
- __version__ = "25.0.20"
8
7
 
9
8
  """
10
9
  See https://github.com/salabim/peek for details
@@ -15,6 +14,7 @@ Inspired by IceCream "Never use print() to debug again".
15
14
  Also contains some of the original code.
16
15
  IceCream was written by Ansgar Grunseid / grunseid.com / grunseid@gmail.com
17
16
  """
17
+
18
18
  import inspect
19
19
  import sys
20
20
  import datetime
@@ -32,14 +32,16 @@ import executing
32
32
  import types
33
33
  import pprint
34
34
  import builtins
35
- import traceback
36
35
  import shutil
37
36
 
37
+ __version__ = "25.0.22"
38
+
38
39
  from pathlib import Path
39
40
 
40
41
  Pythonista = sys.platform == "ios"
41
42
  Pyodide = "pyodide" in sys.modules
42
43
 
44
+
43
45
  if Pythonista:
44
46
  import console
45
47
  else:
@@ -52,6 +54,7 @@ try:
52
54
  except ModuleNotFoundError:
53
55
  import tomli as tomlib
54
56
 
57
+
55
58
  class _Peek:
56
59
  name_alias_default = (
57
60
  # name, alias, default value, print_like accept?
@@ -184,7 +187,7 @@ class _Peek:
184
187
  return
185
188
 
186
189
  elif name == "line_length":
187
- if (isinstance(value, numbers.Number) and value >= 0) or value=='terminal_width':
190
+ if (isinstance(value, numbers.Number) and value >= 0) or value == "terminal_width":
188
191
  return
189
192
 
190
193
  elif name == "indent":
@@ -248,18 +251,18 @@ class _Peek:
248
251
  _Peek.in_read_toml_message = f" in reading environment variable(s)"
249
252
  for environment_variable, value in os.environ.items():
250
253
  environment_variable = environment_variable.lower()
251
- value=value.strip()
254
+ value = value.strip()
252
255
  if environment_variable.startswith("peek."):
253
256
  attribute = environment_variable[5:]
254
257
  if (value.startswith("'") and value.endswith("'")) or (value.startswith('"') and value.endswith('"')):
255
258
  value = value[1:-1]
256
- elif value.lower()=="true":
257
- value=True
258
- elif value.lower()=="false":
259
- value=False
259
+ elif value.lower() == "true":
260
+ value = True
261
+ elif value.lower() == "false":
262
+ value = False
260
263
  else:
261
264
  try:
262
- value=int(value)
265
+ value = int(value)
263
266
  except ValueError:
264
267
  ...
265
268
 
@@ -278,16 +281,20 @@ class _Peek:
278
281
 
279
282
  @staticmethod
280
283
  def print_pythonista_color(s, end="\n", file=sys.stdout):
284
+ cached = ""
281
285
  while s:
282
286
  for ansi, rgb in _Peek._ANSI_to_rgb.items():
283
287
  if s.startswith(ansi):
288
+ if cached:
289
+ print(cached, end="", file=file)
290
+ cached = ""
284
291
  console.set_color(*tuple(v / 255 for v in rgb))
285
292
  s = s[len(ansi) :]
286
293
  break
287
294
  else:
288
- print(s[0], end="", file=file)
295
+ cached += s[0]
289
296
  s = s[1:]
290
- print("", end=end, file=file)
297
+ print(cached + end, end="", file=file)
291
298
 
292
299
  def print_without_color(s, end="\n", file=sys.stdout):
293
300
  while s:
@@ -339,7 +346,7 @@ class _Peek:
339
346
  item = _Peek.de_alias(item)
340
347
  if item in _Peek.name_default or item == "delta1":
341
348
  node = self
342
- while not item in node._attributes or node._attributes[item] is None:
349
+ while item not in node._attributes or node._attributes[item] is None:
343
350
  node = node._parent
344
351
  if item == "delta":
345
352
  return _Peek.perf_counter() - node._attributes["delta1"] + node._attributes["delta"]
@@ -383,7 +390,7 @@ class _Peek:
383
390
  def print(self, *args, as_str=False, **kwargs):
384
391
  if "print" in kwargs and "print_like" in kwargs:
385
392
  raise AttributeError("both print_like and print specified")
386
- if not "print" in kwargs and not "print_like" in kwargs:
393
+ if "print" not in kwargs and "print_like" not in kwargs:
387
394
  kwargs["print_like"] = True
388
395
  return self(*args, as_str=as_str, **kwargs)
389
396
 
@@ -401,8 +408,8 @@ class _Peek:
401
408
 
402
409
  any_args = bool(args)
403
410
  this = self.fork(**kwargs)
404
- if this.line_length in ( 0, 'terminal_width'):
405
- this.line_length=shutil.get_terminal_size().columns
411
+ if this.line_length in (0, "terminal_width"):
412
+ this.line_length = shutil.get_terminal_size().columns
406
413
 
407
414
  this._as_str = as_str
408
415
 
@@ -615,7 +622,7 @@ class _Peek:
615
622
  indent1_rest = wrap_indent
616
623
  lines = [context]
617
624
  else:
618
- indent1 = context.rstrip().ljust(len(wrap_indent))
625
+ indent1 = context.rstrip().ljust(len(wrap_indent))
619
626
  indent1_rest = wrap_indent
620
627
  lines = []
621
628
  else:
@@ -626,7 +633,7 @@ class _Peek:
626
633
  for pair in pairs:
627
634
  do_right = False
628
635
  if "\n" in pair.left:
629
- for s in pair.left.splitlines():
636
+ for s in pair.left.splitlines():
630
637
  lines.append(indent1 + s)
631
638
  do_right = True
632
639
  else:
@@ -659,7 +666,7 @@ class _Peek:
659
666
  if as_str:
660
667
  if this.do_show():
661
668
  if this.use_color and this.color not in ("", "-"):
662
- out = f'{_Peek._color_name_to_ANSI[this.color.lower()]}{out}{_Peek._color_name_to_ANSI["-"]}'
669
+ out = f"{_Peek._color_name_to_ANSI[this.color.lower()]}{out}{_Peek._color_name_to_ANSI['-']}"
663
670
  return out + this.end
664
671
  else:
665
672
  return ""
@@ -726,22 +733,23 @@ class _Peek:
726
733
  def do_output(self, s):
727
734
  if self.do_show():
728
735
  if self.use_color and self.color not in ("", "-"):
729
- s = f'{_Peek._color_name_to_ANSI[self.color.lower()]}{s}{_Peek._color_name_to_ANSI["-"]}'
736
+ s = f"{_Peek._color_name_to_ANSI[self.color.lower()]}{s}{_Peek._color_name_to_ANSI['-']}"
737
+ s_end = s + self.end
730
738
 
731
739
  if callable(self.output):
732
740
  if self.output == builtins.print or "end" in inspect.signature(self.output).parameters:
733
741
  # test for builtins.print is required as for Python <= 3.10, builtins.print has no signature
734
- self.output(s, end=self.end)
742
+ self.output(s_end, end="")
735
743
  else:
736
- self.output(s + self.end)
744
+ self.output(s_end)
737
745
  elif self.output in ("stdout", "stderr"):
738
746
  file = sys.stdout if self.output == "stdout" else sys.stderr
739
747
  if Pythonista:
740
- _Peek.print_pythonista_color(s, end=self.end, file=file)
748
+ _Peek.print_pythonista_color(s_end, end="", file=file)
741
749
  # elif Pyodide: # not handled via use_color
742
750
  # _Peek.print_without_color(s, end=self.end, file=file)
743
751
  else:
744
- print(s, end=self.end, file=file)
752
+ print(s_end, end="", file=file)
745
753
  elif self.output == "logging.debug":
746
754
  logging.debug(s)
747
755
  elif self.output == "logging.info":
@@ -756,12 +764,12 @@ class _Peek:
756
764
  pass
757
765
  elif isinstance(self.output, str):
758
766
  with open(self.output, "a+", encoding="utf-8") as f:
759
- print(s, file=f, end=self.end)
767
+ print(s_end, file=f, end="")
760
768
  elif isinstance(self.output, Path):
761
769
  with self.output.open("a+", encoding="utf-8") as f:
762
- print(s, file=f, end=self.end)
770
+ print(s_end, file=f, end="")
763
771
  else:
764
- print(s, file=self.output, end=self.end)
772
+ print(s_end, file=self.output, end="")
765
773
 
766
774
  def copy_to_clipboard(self, value, confirm=True):
767
775
  if Pythonista:
@@ -820,13 +828,12 @@ class _Peek:
820
828
  }
821
829
  if "width" in inspect.signature(self.serialize).parameters:
822
830
  kwargs["width"] = width
823
- return self.add_color_value(self.serialize(obj, **kwargs).replace("\\n", "\n"))
824
-
831
+ return self.add_color_value(self.serialize(obj, **kwargs).replace("\\n", "\n"))
832
+
825
833
  def reset(self):
826
834
  reset()
827
835
 
828
836
 
829
-
830
837
  def reset():
831
838
  global _peek_no_toml
832
839
  global _peek_toml
@@ -855,9 +862,9 @@ class _PeekModule(types.ModuleType):
855
862
 
856
863
  def __str__(self):
857
864
  return str(peek)
858
-
865
+
866
+
859
867
  reset()
860
868
 
861
869
  if __name__ != "__main__":
862
870
  sys.modules["peek"].__class__ = _PeekModule
863
-
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: peek-python
3
- Version: 25.0.20
3
+ Version: 25.0.22
4
4
  Summary: peek - like print, but 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
@@ -467,7 +467,7 @@ prints something like
467
467
  1613635601 hello='world'
468
468
  ```
469
469
 
470
- output
470
+ ### output
471
471
  This will allow the output to be handled by something else than the default (output being written to stdout).
472
472
 
473
473
  The `output` attribute can be
@@ -1082,9 +1082,9 @@ Maybe more useful is to show the output change on the same line, e.g. a status.
1082
1082
  ```
1083
1083
  import time
1084
1084
  for i in range(50):
1085
- peek(f"time {time.time()}",end="\r")
1086
- time.sleep(0.1)
1087
- peek('')
1085
+ peek.print(f"time {time.time():10.2f}",end="", prefix="\r")
1086
+ time.sleep(0.1)
1087
+ peek.print()
1088
1088
  ```
1089
1089
  > [!NOTE]
1090
1090
  >
@@ -1092,7 +1092,7 @@ peek('')
1092
1092
 
1093
1093
  > [!NOTE]
1094
1094
  >
1095
- > `\r` does not work under Pythonista.
1095
+ > `Under Pythonista \r` has to be at the start of a peek.print output. Otherwise, it does not work.
1096
1096
 
1097
1097
  ### return_none
1098
1098
  Normally, `peek()`returns the values passed directly, which is usually fine. However, when used in a notebook
@@ -1134,7 +1134,7 @@ will print
1134
1134
  ```
1135
1135
  12 min(1, 2)=1 [0, 1, 2, 3]
1136
1136
  ```
1137
- in yellow, but only if peek.enabled is False, nothing will be printed.
1137
+ in yellow, but if peek.enabled is False, nothing will be printed.
1138
1138
 
1139
1139
  You can also use peek.print (see below).
1140
1140
 
@@ -1192,7 +1192,7 @@ peek.sep = "|" # sets the 'normal' peek separator
1192
1192
 
1193
1193
 
1194
1194
  ## Peeking locals and globals
1195
- It is possible to get the name and values of all local or global variables.
1195
+ It is possible to get the names and values of all local or global variables.
1196
1196
 
1197
1197
  To do that, just put `locals` or `globals` in the call to peek, e.g.:
1198
1198
 
@@ -1280,10 +1280,10 @@ It is also possible to suppress output with the provided attribute (see above).
1280
1280
 
1281
1281
  ## Using filter to control peek output
1282
1282
 
1283
- It is possible to define a filter function that determines whether peek output should be suppressed
1283
+ It is possible to define a filter function that determines whether peek output should be suppressed.
1284
1284
  By default, the filter is defined as "" denoting no filter.
1285
1285
 
1286
- Suppose we a (float) level to a peek statement. By default, this level is 0. E.g.:
1286
+ Suppose we add a (float) level to a peek statement. By default, this level is 0. E.g.:
1287
1287
 
1288
1288
  ```
1289
1289
  peek("critical", level=0)
@@ -1291,7 +1291,7 @@ peek("important", level=1)
1291
1291
  peek("warning", level=2)
1292
1292
  ```
1293
1293
 
1294
- With `peek.filter ="level <= 1"` the program makes sure that level=2 is not displayed at all.
1294
+ With `peek.filter = "level <= 1"` the program makes sure that level=2 is not displayed at all.
1295
1295
 
1296
1296
  It is possible to use more than one attribute, like
1297
1297
 
@@ -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 - like print, but easy"
13
- version = "25.0.20"
13
+ version = "25.0.22"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.9"
16
16
  dependencies = [
File without changes