peek-python 25.0.2.post1__tar.gz → 25.0.4__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.2
2
2
  Name: peek-python
3
- Version: 25.0.2.post1
3
+ Version: 25.0.4
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
@@ -662,6 +662,7 @@ The color attribute is used to specify the color of the output.
662
662
  There's a choice of `"black"`, `"white"`, `"red"`, `"green"`, `"blue"`, `"cyan"`, `"magenta"`, `"yellow"`, `" dark_black"`, `"dark_white"`, `"dark_red"`, `"dark_green"`, `"dark_blue"`, `"dark_cyan"`, `"dark_magenta"` and `"dark_yellow"`:
663
663
 
664
664
  <img src="https://www.salabim.org/peek/peek_picture2.png" width=25%>
665
+
665
666
  To set the color to 'nothing'", "use "-".
666
667
 
667
668
  On top of that, color_value may be used to specify the value part of an output item. By specifying color_value as "" (the default), the value part will be displayed with the same color as the rest of the output.
@@ -642,6 +642,7 @@ The color attribute is used to specify the color of the output.
642
642
  There's a choice of `"black"`, `"white"`, `"red"`, `"green"`, `"blue"`, `"cyan"`, `"magenta"`, `"yellow"`, `" dark_black"`, `"dark_white"`, `"dark_red"`, `"dark_green"`, `"dark_blue"`, `"dark_cyan"`, `"dark_magenta"` and `"dark_yellow"`:
643
643
 
644
644
  <img src="https://www.salabim.org/peek/peek_picture2.png" width=25%>
645
+
645
646
  To set the color to 'nothing'", "use "-".
646
647
 
647
648
  On top of that, color_value may be used to specify the value part of an output item. By specifying color_value as "" (the default), the value part will be displayed with the same color as the rest of the output.
@@ -4,7 +4,7 @@
4
4
  # | .__/ \___| \___||_|\_\
5
5
  # |_| like print, but easy.
6
6
 
7
- __version__ = "25.0.2"
7
+ __version__ = "25.0.4"
8
8
 
9
9
  """
10
10
  See https://github.com/salabim/peek for details
@@ -120,7 +120,6 @@ class _Peek:
120
120
  _color_name_to_ANSI["-"] = _color_name_to_ANSI["reset"]
121
121
  _color_name_to_ANSI[""] = _color_name_to_ANSI["reset"]
122
122
 
123
-
124
123
  _ANSI_to_rgb = {
125
124
  "\033[1;30m": (51, 51, 51),
126
125
  "\033[1;31m": (255, 0, 0),
@@ -141,8 +140,6 @@ class _Peek:
141
140
  "\033[0m": (),
142
141
  }
143
142
 
144
-
145
-
146
143
  codes = {}
147
144
 
148
145
  @staticmethod
@@ -254,7 +251,7 @@ class _Peek:
254
251
  while s:
255
252
  for ansi, rgb in _Peek._ANSI_to_rgb.items():
256
253
  if s.startswith(ansi):
257
- console.set_color(tuple(v/255 for v in rgb))
254
+ console.set_color(*tuple(v / 255 for v in rgb))
258
255
  s = s[len(ansi) :]
259
256
  break
260
257
  else:
@@ -316,7 +313,16 @@ class _Peek:
316
313
  return self.__getattribute__(item)
317
314
 
318
315
  def __setattr__(self, item, value):
319
- if item in ("_parent", "_is_context_manager", "_line_number_with_filename_and_parent", "_save_traceback", "_enter_time", "_as_str", "_as_colored_str", "_attributes"):
316
+ if item in (
317
+ "_parent",
318
+ "_is_context_manager",
319
+ "_line_number_with_filename_and_parent",
320
+ "_save_traceback",
321
+ "_enter_time",
322
+ "_as_str",
323
+ "_as_colored_str",
324
+ "_attributes",
325
+ ):
320
326
  return super().__setattr__(item, value)
321
327
  self._attributes.update(_Peek.spec_to_attributes(**{item: value}))
322
328
 
@@ -341,14 +347,14 @@ class _Peek:
341
347
  return False
342
348
  return self.enabled
343
349
 
344
- def print(self, *args, as_str=None, as_colored_str=None, **kwargs):
350
+ def print(self, *args, as_str=False, as_colored_str=False, **kwargs):
345
351
  if "print" in kwargs and "print_like" in kwargs:
346
352
  raise AttributeError("both print_like and print specified")
347
353
  if not "print" in kwargs and not "print_like" in kwargs:
348
354
  kwargs["print_like"] = True
349
355
  return self(*args, as_str=as_str, as_colored_str=as_colored_str, **kwargs)
350
356
 
351
- def __call__(self, *args, as_str=None, as_colored_str=None, _via_module=False, **kwargs):
357
+ def __call__(self, *args, as_str=False, as_colored_str=False, _via_module=False, **kwargs):
352
358
  def add_to_pairs(pairs, left, right):
353
359
  if right in (locals, globals, vars):
354
360
  frame = inspect.currentframe().f_back.f_back
@@ -363,15 +369,8 @@ class _Peek:
363
369
  any_args = bool(args)
364
370
  this = self.fork(**kwargs)
365
371
 
366
- if as_str is None:
367
- as_str=False
368
- if as_colored_str is None:
369
- as_colored_str=False
370
- else:
371
- if as_colored_str is None:
372
- as_colored_str=False
373
- else:
374
- raise ValueError("not allowed to use both as_str and as_colored_str")
372
+ if as_str and as_colored_str:
373
+ raise ValueError("not allowed to use both as_str and as_colored_str")
375
374
 
376
375
  this._as_str = as_str
377
376
  this._as_colored_str = as_colored_str
@@ -558,7 +557,6 @@ class _Peek:
558
557
  left += this.equals_separator
559
558
  add_to_pairs(pairs, left, right)
560
559
 
561
-
562
560
  just_one_line = False
563
561
  if not (len(pairs) > 1 and this.separator == ""):
564
562
  if not any("\n" in pair.left for pair in pairs):
@@ -624,13 +622,12 @@ class _Peek:
624
622
  return out + this.end
625
623
  else:
626
624
  return ""
627
-
625
+
628
626
  if as_colored_str:
629
627
  if this.do_show():
630
628
  return this._color_name_to_ANSI[this.color.lower()] + out + this.end + this._color_name_to_ANSI["-"]
631
629
  else:
632
- return ""
633
-
630
+ return ""
634
631
 
635
632
  if this.to_clipboard:
636
633
  peek.copy_to_clipboard(pairs[-1].right if "pairs" in locals() else "", confirm=False)
@@ -699,7 +696,6 @@ class _Peek:
699
696
  elif self.output == "stdout":
700
697
  if self.color not in ["", "-"]:
701
698
  s = self._color_name_to_ANSI[self.color.lower()] + s + self.end + self._color_name_to_ANSI["-"]
702
- print("***",repr(s))
703
699
  if Pythonista:
704
700
  _Peek.print_pythonista_color(s, end="")
705
701
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: peek-python
3
- Version: 25.0.2.post1
3
+ Version: 25.0.4
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
@@ -662,6 +662,7 @@ The color attribute is used to specify the color of the output.
662
662
  There's a choice of `"black"`, `"white"`, `"red"`, `"green"`, `"blue"`, `"cyan"`, `"magenta"`, `"yellow"`, `" dark_black"`, `"dark_white"`, `"dark_red"`, `"dark_green"`, `"dark_blue"`, `"dark_cyan"`, `"dark_magenta"` and `"dark_yellow"`:
663
663
 
664
664
  <img src="https://www.salabim.org/peek/peek_picture2.png" width=25%>
665
+
665
666
  To set the color to 'nothing'", "use "-".
666
667
 
667
668
  On top of that, color_value may be used to specify the value part of an output item. By specifying color_value as "" (the default), the value part will be displayed with the same color as the rest of the output.
@@ -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.2.post1"
13
+ version = "25.0.4"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.6"
16
16
  dependencies = [
@@ -299,7 +299,14 @@ def test_as_str(capsys):
299
299
  with peek(as_str=True):
300
300
  pass
301
301
 
302
-
302
+ def test_as_colored_str():
303
+ hello = "world"
304
+ s = peek(hello, as_colored_str=True)
305
+ assert s == "\x1b[0mhello='world'\n\x1b[0m"
306
+
307
+ with pytest.raises(ValueError):
308
+ s=peek(hello, as_str=True, as_colored_str=True)
309
+
303
310
  @pytest.mark.skipif(Pythonista, reason="Pythonista problem")
304
311
  def test_print(capsys):
305
312
  peek.print(*range(4))