jc-debug 1.0.2__py3-none-any.whl → 1.0.3__py3-none-any.whl

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.
debug/__init__.py CHANGED
@@ -155,7 +155,7 @@ __all__ = [
155
155
  "DebugChannel",
156
156
  "line_iter",
157
157
  ]
158
- __version__ = "1.0.2"
158
+ __version__ = "1.0.3"
159
159
 
160
160
  import inspect, os, sys, traceback
161
161
 
@@ -547,16 +547,23 @@ class DebugChannel:
547
547
  return self # Return without writing any output.
548
548
 
549
549
  # Format our message and write it to the debug stream.
550
- if isinstance(message, (list, tuple)):
550
+ sort=False
551
+ if isinstance(message, (list, set, tuple)):
551
552
  if isinstance(message, tuple):
552
553
  left, right = "()"
554
+ elif isinstance(message, set):
555
+ left, right = "{}"
556
+ message=sorted(list(message),key=lambda val:repr(val))
553
557
  else:
554
558
  left, right = "[]"
555
559
  messages = message
556
560
  message = left
557
561
  self.stream.write(self.fmt.format(**locals()))
558
- for message in messages:
559
- message = self.indstr + repr(message)
562
+ for i in range(len(messages)):
563
+ m = messages[i]
564
+ message = f"{self.indstr}{m!r}"
565
+ if i<len(messages)-1:
566
+ message+=','
560
567
  self.stream.write(self.fmt.format(**locals()))
561
568
  message = right
562
569
  self.stream.write(self.fmt.format(**locals()))
@@ -564,8 +571,10 @@ class DebugChannel:
564
571
  messages = dict(message)
565
572
  message = "{"
566
573
  self.stream.write(self.fmt.format(**locals()))
567
- for k in messages.keys():
568
- message = f"{self.indstr}{k!r}: {messages[k]!r}"
574
+ for i,(k,v) in enumerate(messages.items()):
575
+ message = f"{self.indstr}{k!r}: {v!r}"
576
+ if i<len(messages)-1:
577
+ message+=','
569
578
  self.stream.write(self.fmt.format(**locals()))
570
579
  message = "}"
571
580
  self.stream.write(self.fmt.format(**locals()))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jc-debug
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: Makes debugging to the console both simpler and much more powerful.
5
5
  Author-email: Jeff Clough <jeff@cloughcottage.com>
6
6
  License: MIT License
@@ -42,8 +42,8 @@ Dynamic: license-file
42
42
 
43
43
  # debug
44
44
 
45
- This debug module a class named DebugChannel, instances of which are
46
- useful for adding temporary or conditional debug output to CLI scripts.
45
+ This debug module a class named DebugChannel, instances of which are useful for
46
+ adding temporary or conditional debug output to CLI scripts.
47
47
 
48
48
  The minimal boilerplate is pretty simple:
49
49
 
@@ -53,9 +53,9 @@ from debug import DebugChannel
53
53
  dc=DebugChannel(True)
54
54
  ```
55
55
 
56
- By default, DebugChannels are created disabled (the write no output), so
57
- the `True` above enables `dc` during its instantiation so it needn't be
58
- enabled later.
56
+ By default, DebugChannels are created disabled (the write no output), so the
57
+ `True` above enables `dc` during its instantiation so it needn't be enabled
58
+ later.
59
59
 
60
60
  A more common way of handling this is ...
61
61
 
@@ -73,18 +73,18 @@ dc.enable(opt.debug)
73
73
  ...
74
74
  ```
75
75
 
76
- This enables the `dc` DebugChannel instance only if --debug is given on
77
- the script's command line.
76
+ This enables the `dc` DebugChannel instance only if --debug is given on the
77
+ script's command line.
78
78
 
79
79
  By default, output is sent to stdandard error and formatted as:
80
80
 
81
81
  '{label}: [{pid}] {basename}:{line}:{function}: {indent}{message}\n'
82
82
 
83
- There are several variables you can include in DebugChannel's output.
84
- See the DebugChannel docs below for a list.
83
+ There are several variables you can include in DebugChannel's output. See the
84
+ DebugChannel docs below for a list.
85
85
 
86
- So, for example, if you want to see how your variables are behaving in a
87
- loop, you might do something like this:
86
+ So, for example, if you want to see how your variables are behaving in a loop,
87
+ you might do something like this:
88
88
 
89
89
  ```python
90
90
  from debug import DebugChannel
@@ -96,15 +96,15 @@ dc=DebugChannel(
96
96
 
97
97
  dc("Entering loop ...").indent()
98
98
  for i in range(5):
99
- dc(f"i={i}").indent()
99
+ dc(f"{i=}").indent()
100
100
  for j in range(3):
101
- dc(f"j={j}")
101
+ dc(f"{j=}")
102
102
  dc.undent()("Done with j loop.")
103
103
  dc.undent()("Done with i loop.")
104
104
  ```
105
105
 
106
- That gives you this necely indented output. The indent() and undent()
107
- methods are one thing that makes DebugChannels so nice to work with.
106
+ That gives you this necely indented output. The indent() and undent() methods
107
+ are one thing that makes DebugChannels so nice to work with.
108
108
 
109
109
  DC: 8: Entering loop ...
110
110
  DC: 10: i=0
@@ -134,8 +134,8 @@ methods are one thing that makes DebugChannels so nice to work with.
134
134
  DC: 13: Done with j loop.
135
135
  DC: 14: Done with i loop.
136
136
 
137
- That's a simple example, but you might be starting to get an idea of
138
- how versatile DebugChannel instances can be.
137
+ That's a simple example, but you might be starting to get an idea of how
138
+ versatile DebugChannel instances can be.
139
139
 
140
140
  A DebugChannel can also be used as a function decorator:
141
141
 
@@ -163,9 +163,9 @@ example2("First test",3)
163
163
  example2("Second test",2)
164
164
  ```
165
165
 
166
- This causes entry into and exit from the decorated function to be
167
- recorded in the given DebugChannel's output. If you put that into a file
168
- named foo.py and then run "python3 -m foo", you'll get this:
166
+ This causes entry into and exit from the decorated function to be recorded in
167
+ the given DebugChannel's output. If you put that into a file named foo.py and
168
+ then run "python3 -m foo", you'll get this:
169
169
 
170
170
  ```
171
171
  DC: __main__: example2('First test',3) ...
@@ -189,6 +189,55 @@ DC: example2: example1(...) returns None after 23µs.
189
189
  DC: __main__: example2(...) returns None after 423ms.
190
190
  ```
191
191
 
192
+ When outputting a data structure, it's nice to be a little structured about it.
193
+ So if you send a list, tuple, dict, or set to a DebugChannel instance as the
194
+ whole message, it will be formatted one item at a time in the output.
195
+
196
+ ```python
197
+ from debug import DebugChannel
198
+
199
+ dc=DebugChannel(True,fmt="{label}: {line:3}: {indent}{message}\n")
200
+
201
+ l="this is a test".split()
202
+ s=set(l)
203
+ d=dict(zip('abcd',l))
204
+
205
+ dc("l:")(l)
206
+ dc("s:")(s)
207
+ dc("d:")(d)
208
+ ```
209
+
210
+ Notice the idiom of using dc(...)'s output as the DebugChannel instance itself,
211
+ allowing further manipulation in the same "breath." Here's the output:
212
+
213
+ ```python
214
+ DC: 12: l:
215
+ DC: 12: [
216
+ DC: 12: 'this',
217
+ DC: 12: 'is',
218
+ DC: 12: 'a',
219
+ DC: 12: 'test'
220
+ DC: 12: ]
221
+ DC: 13: s:
222
+ DC: 13: {
223
+ DC: 13: 'a',
224
+ DC: 13: 'is',
225
+ DC: 13: 'test',
226
+ DC: 13: 'this'
227
+ DC: 13: }
228
+ DC: 14: d:
229
+ DC: 14: {
230
+ DC: 14: 'a': 'this',
231
+ DC: 14: 'b': 'is',
232
+ DC: 14: 'c': 'a',
233
+ DC: 14: 'd': 'test'
234
+ DC: 14: }
235
+ ```
236
+
237
+ Notice sets are output in alphabetical order (according to their repr()
238
+ values). Since sets are unordered by nature, this makes them easier to inspect
239
+ visually without misrepresenting their contents.
240
+
192
241
  That's a very general start. See DebugChannel's class docs for more.
193
242
 
194
243
  <a id="debug.DebugChannel"></a>
@@ -0,0 +1,6 @@
1
+ debug/__init__.py,sha256=6vQdS1S3T0FrC9TkCqGdjfbxJgbGciO9-X7eZbhYA30,21660
2
+ jc_debug-1.0.3.dist-info/licenses/LICENSE,sha256=q63VTXVTnH1QywnYTQQ1TgL2NE0XLV9pmNTxBh8TnSY,1068
3
+ jc_debug-1.0.3.dist-info/METADATA,sha256=c2yH8INFBI7TtmDLyMt978_ZAKbX6SBLgRTCAPanmLQ,16002
4
+ jc_debug-1.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ jc_debug-1.0.3.dist-info/top_level.txt,sha256=mcOe8k8TNE9HfR15fLTnDFWyd3DViA-MH52TaEvPL4A,6
6
+ jc_debug-1.0.3.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- debug/__init__.py,sha256=YMDCZf2W-xANOxLRBPZAplu5ZpI_iJDXCR-BtABwqJY,21269
2
- jc_debug-1.0.2.dist-info/licenses/LICENSE,sha256=q63VTXVTnH1QywnYTQQ1TgL2NE0XLV9pmNTxBh8TnSY,1068
3
- jc_debug-1.0.2.dist-info/METADATA,sha256=6fhq0I8wOKrO28O6Rmm2FcesTZET3GHJEdNip86B9EI,14842
4
- jc_debug-1.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- jc_debug-1.0.2.dist-info/top_level.txt,sha256=mcOe8k8TNE9HfR15fLTnDFWyd3DViA-MH52TaEvPL4A,6
6
- jc_debug-1.0.2.dist-info/RECORD,,