peek-python 25.0.1__tar.gz → 25.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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: peek-python
3
- Version: 25.0.1
3
+ Version: 25.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
@@ -46,13 +46,13 @@ And on top of that, you get some basic benchmarking functionality.
46
46
 
47
47
  * [Use peek.print to use peek like print with extras](#use-peekprint-to-use-peek-like-print-with-extras)
48
48
 
49
+ * [Peeking locals and globals](#peeking-locals-and-globals)
50
+
49
51
  * [Return a string instead of sending to output](#return-a-string-instead-of-sending-to-output)
50
52
 
51
53
  * [Disabling peek's output](#disabling-peeks-output)
52
54
 
53
- * [Using level to control peek output](#using-level-to-control-peek-output)
54
-
55
- * [Using color to control peek output](#using-color-to-control-peek-output)
55
+ * [Using filter to control peek output](#using-filter-to-control-peek-output)
56
56
 
57
57
  * [Copying to the clipboard](#copying-to-the-clipboard)
58
58
 
@@ -1098,6 +1098,35 @@ peek.sep = "|" # sets the 'normal' peek separator
1098
1098
  >
1099
1099
  > `peek.print` does not obey the line length and will always return None (unless as_str is True).
1100
1100
 
1101
+
1102
+ # Peeking locals and globals
1103
+ It is possible to get the name and values of all local or global variables.
1104
+
1105
+ To do that, just put `locals` or `globals` in the call to peek, e.g.:
1106
+
1107
+ ```
1108
+ def my_func():
1109
+ a = 10
1110
+ b = a * a
1111
+ peek(locals)
1112
+ my_func()
1113
+ ```
1114
+
1115
+ will print all local variables, apart from those starting with `__`, so:
1116
+ ```
1117
+ a=10, b=100
1118
+ ```
1119
+
1120
+ Likewise,
1121
+ ```
1122
+ peek(globals)
1123
+ ```
1124
+ will print all global variables, apart from those starting with `__`
1125
+
1126
+ > [!IMPORTANT]
1127
+ >
1128
+ > You should not add parentheses after `locals` or `globals` for peek to work properly!
1129
+
1101
1130
  # Return a string instead of sending to output
1102
1131
 
1103
1132
  `peek(*args, as_str=True)` is like `peek(*args)` but the output is returned as a string instead
@@ -1423,6 +1452,7 @@ can show traceback yes no
1423
1452
  can be used like print w/extras yes (with peek.print) no
1424
1453
  allows non linefeed printing yes (via end parameter) requires patching
1425
1454
  PEP8 (Pythonic) API yes no
1455
+ format specification optional no
1426
1456
  sorts dicts no by default, optional *) yes
1427
1457
  supports compact, indent,
1428
1458
  and underscore_numbers
@@ -26,13 +26,13 @@ And on top of that, you get some basic benchmarking functionality.
26
26
 
27
27
  * [Use peek.print to use peek like print with extras](#use-peekprint-to-use-peek-like-print-with-extras)
28
28
 
29
+ * [Peeking locals and globals](#peeking-locals-and-globals)
30
+
29
31
  * [Return a string instead of sending to output](#return-a-string-instead-of-sending-to-output)
30
32
 
31
33
  * [Disabling peek's output](#disabling-peeks-output)
32
34
 
33
- * [Using level to control peek output](#using-level-to-control-peek-output)
34
-
35
- * [Using color to control peek output](#using-color-to-control-peek-output)
35
+ * [Using filter to control peek output](#using-filter-to-control-peek-output)
36
36
 
37
37
  * [Copying to the clipboard](#copying-to-the-clipboard)
38
38
 
@@ -1078,6 +1078,35 @@ peek.sep = "|" # sets the 'normal' peek separator
1078
1078
  >
1079
1079
  > `peek.print` does not obey the line length and will always return None (unless as_str is True).
1080
1080
 
1081
+
1082
+ # Peeking locals and globals
1083
+ It is possible to get the name and values of all local or global variables.
1084
+
1085
+ To do that, just put `locals` or `globals` in the call to peek, e.g.:
1086
+
1087
+ ```
1088
+ def my_func():
1089
+ a = 10
1090
+ b = a * a
1091
+ peek(locals)
1092
+ my_func()
1093
+ ```
1094
+
1095
+ will print all local variables, apart from those starting with `__`, so:
1096
+ ```
1097
+ a=10, b=100
1098
+ ```
1099
+
1100
+ Likewise,
1101
+ ```
1102
+ peek(globals)
1103
+ ```
1104
+ will print all global variables, apart from those starting with `__`
1105
+
1106
+ > [!IMPORTANT]
1107
+ >
1108
+ > You should not add parentheses after `locals` or `globals` for peek to work properly!
1109
+
1081
1110
  # Return a string instead of sending to output
1082
1111
 
1083
1112
  `peek(*args, as_str=True)` is like `peek(*args)` but the output is returned as a string instead
@@ -1403,6 +1432,7 @@ can show traceback yes no
1403
1432
  can be used like print w/extras yes (with peek.print) no
1404
1433
  allows non linefeed printing yes (via end parameter) requires patching
1405
1434
  PEP8 (Pythonic) API yes no
1435
+ format specification optional no
1406
1436
  sorts dicts no by default, optional *) yes
1407
1437
  supports compact, indent,
1408
1438
  and underscore_numbers
@@ -4,7 +4,7 @@
4
4
  # | .__/ \___| \___||_|\_\
5
5
  # |_| like print, but easy.
6
6
 
7
- __version__ = "25.0.1"
7
+ __version__ = "25.0.2"
8
8
 
9
9
  """
10
10
  See https://github.com/salabim/peek for details
@@ -111,6 +111,9 @@ class _Peek:
111
111
  colors["-"] = "\033[0m"
112
112
  colors[""] = "\033[0m"
113
113
 
114
+ LOCALS=object()
115
+ GLOBALS=object()
116
+
114
117
  codes = {}
115
118
 
116
119
  ansi_to_rgb = {
@@ -523,7 +526,13 @@ class _Peek:
523
526
  pass
524
527
  if left:
525
528
  left += this.equals_separator
526
- pairs.append(Pair(left=left, right=right))
529
+ if right in (locals, globals,vars):
530
+ frame = inspect.currentframe().f_back.f_back
531
+ for name, value in {locals: frame.f_locals, globals: frame.f_globals, vars:frame.f_locals}[right].items():
532
+ if not (isinstance(value,PeekModule) or name.startswith("__")):
533
+ pairs.append(Pair(left=name+this.equals_separator,right=value))
534
+ else:
535
+ pairs.append(Pair(left=left, right=right))
527
536
 
528
537
  just_one_line = False
529
538
  if not (len(pairs) > 1 and this.separator == ""):
@@ -713,9 +722,9 @@ class _Peek:
713
722
  def serialize_kwargs(self, obj, width):
714
723
  if self.format:
715
724
  if isinstance(self.format, str):
716
- iterator=iter([self.format])
725
+ iterator = iter([self.format])
717
726
  else:
718
- iterator=iter(self.format)
727
+ iterator = iter(self.format)
719
728
  for sub_format in iterator:
720
729
  format_string = "{" + sub_format + "}" if sub_format.startswith(":") or sub_format.startswith("!") else "{:" + sub_format + "}"
721
730
  try:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: peek-python
3
- Version: 25.0.1
3
+ Version: 25.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
@@ -46,13 +46,13 @@ And on top of that, you get some basic benchmarking functionality.
46
46
 
47
47
  * [Use peek.print to use peek like print with extras](#use-peekprint-to-use-peek-like-print-with-extras)
48
48
 
49
+ * [Peeking locals and globals](#peeking-locals-and-globals)
50
+
49
51
  * [Return a string instead of sending to output](#return-a-string-instead-of-sending-to-output)
50
52
 
51
53
  * [Disabling peek's output](#disabling-peeks-output)
52
54
 
53
- * [Using level to control peek output](#using-level-to-control-peek-output)
54
-
55
- * [Using color to control peek output](#using-color-to-control-peek-output)
55
+ * [Using filter to control peek output](#using-filter-to-control-peek-output)
56
56
 
57
57
  * [Copying to the clipboard](#copying-to-the-clipboard)
58
58
 
@@ -1098,6 +1098,35 @@ peek.sep = "|" # sets the 'normal' peek separator
1098
1098
  >
1099
1099
  > `peek.print` does not obey the line length and will always return None (unless as_str is True).
1100
1100
 
1101
+
1102
+ # Peeking locals and globals
1103
+ It is possible to get the name and values of all local or global variables.
1104
+
1105
+ To do that, just put `locals` or `globals` in the call to peek, e.g.:
1106
+
1107
+ ```
1108
+ def my_func():
1109
+ a = 10
1110
+ b = a * a
1111
+ peek(locals)
1112
+ my_func()
1113
+ ```
1114
+
1115
+ will print all local variables, apart from those starting with `__`, so:
1116
+ ```
1117
+ a=10, b=100
1118
+ ```
1119
+
1120
+ Likewise,
1121
+ ```
1122
+ peek(globals)
1123
+ ```
1124
+ will print all global variables, apart from those starting with `__`
1125
+
1126
+ > [!IMPORTANT]
1127
+ >
1128
+ > You should not add parentheses after `locals` or `globals` for peek to work properly!
1129
+
1101
1130
  # Return a string instead of sending to output
1102
1131
 
1103
1132
  `peek(*args, as_str=True)` is like `peek(*args)` but the output is returned as a string instead
@@ -1423,6 +1452,7 @@ can show traceback yes no
1423
1452
  can be used like print w/extras yes (with peek.print) no
1424
1453
  allows non linefeed printing yes (via end parameter) requires patching
1425
1454
  PEP8 (Pythonic) API yes no
1455
+ format specification optional no
1426
1456
  sorts dicts no by default, optional *) yes
1427
1457
  supports compact, indent,
1428
1458
  and underscore_numbers
@@ -10,7 +10,7 @@ authors = [
10
10
  { name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com" },
11
11
  ]
12
12
  description = "peek - debugging and benchmarking made easy"
13
- version = "25.0.1"
13
+ version = "25.0.2"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.6"
16
16
  dependencies = [
@@ -122,6 +122,7 @@ def test_time_delta():
122
122
  time.sleep(0.1)
123
123
  assert 10.05 < peek.delta < 11
124
124
 
125
+
125
126
 
126
127
  def test_dynamic_prefix(capsys):
127
128
  g.i = 0
@@ -307,7 +308,8 @@ def test_print(capsys):
307
308
 
308
309
  result=peek.print(1,2)
309
310
  assert result is None
310
-
311
+ out, err = capsys.readouterr()
312
+ assert out == "1 2\n"
311
313
 
312
314
  with pytest.raises(AttributeError):
313
315
  peek.print(sep="|", sepp="/")
File without changes
File without changes