Mixing breakpoints with print debugging.
Project description
breakword
breakword is a small debugging utility that combines print debugging with breakpoint debugging. It aims to facilitate debugging the kind of problem where you might use print statements to quickly spot where something seems to be off, and then switch to a step by step debugger.
breakword normally requires running your program twice and will only work properly if it is deterministic.
How to use
-
Set the
PYTHONBREAKPOINTenvironment variable tobreakword.breakpoint. -
Use
breakpointlike aprintstatement:
for i in range(10):
breakpoint(i)
This will print out something like this:
$ python example.py
⏎ standard 0
⏎ sound 1
⏎ character 2
⏎ thank 3
⏎ play 4
⏎ however 5
⏎ fish 6
⏎ cultural 7
⏎ either 8
⏎ and 9
- Use the
BREAKWORDenvironment variable to set a breakpoint to what you want to investigate further. For instance, if you want to stop wheni == 6in the above program, you can run the following command:
$ env BREAKWORD=fish python example.py
⏎ standard 0
⏎ sound 1
⏎ character 2
⏎ thank 3
⏎ play 4
⏎ however 5
⏎ fish 6
> example.py(2)<module>()
-> for i in range(10):
(Pdb) i
6
You can also give a comma-separated list of words, e.g. BREAKWORD=sound,fish.
Note: breakpoint() with no arguments retains the normal behavior.
More functions
-
breakword.log(*things, **config): Print a word and optionally other things after it. -
breakword.brk(watch=None, **config): Sets a breakpoint to trigger afterlogprinted out the given word. IfwatchisNoneor not given, theBREAKWORDenvironment variable is consulted. If the variable is not set, nothing will happen.- This is equivalent to
breakword.after(word).breakpoint().
- This is equivalent to
-
breakword.after(watch=None, **config): Returns an object that evaluates toTrueright afterlogprinted out the given watch word. As withbrk, ifwatchisNoneor not given, theBREAKWORDenvironment variable is consulted. -
breakword.word(**config): Returns the next word as a string. You can print it yourself, in which case it's basically likelog, or you can store it in an object. -
breakword.logbrk(**config): Callslogand thenbrk. -
breakword.wordbrk(**config): Callswordand thenbrk. The word is returned. -
breakword.set_default_logger(logger): Set the logging function to use (defaults toprint)
Tracking objects
-
breakword.track(obj, all=False)will set thebreakwordattribute in the object to the next word in the list. By setting theBREAKWORDenvironment variable, you will set a breakpoint to the corresponding call totrack. Set theallargument toTrueand the attribute will contain a list. Note: this will not work ifobjis an integer or string, in those cases track will print a warning. -
breakword.track_creation(*classes)will set thebreakwordattribute on all instances of the given classes, when they are created. That way, you can set a breakpoint back to the creation of some object of interest.
Groups
Use breakword.groups.<name> to get a "word group" with the given name. Each group generates words independently and will therefore not interfere with each other. They have log, brk, after, word, etc. as methods. The default group is groups[""].
from breakword import groups
assert groups.aardvark == groups["aardvark"]
# Log "a" in the aardvark group
groups.aardvark.log("a")
# Log "b" in the pelican group
groups.pelican.log("b")
# Get the next word in the pelican group
word = groups.pelican.word()
# Conditional behavior to perform only after the word "cherry"
if groups.pelican.after("cherry"):
print("blah")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file breakword-0.3.1.tar.gz.
File metadata
- Download URL: breakword-0.3.1.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.0b3 CPython/3.8.5 Darwin/19.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c539db1d1c0413512da2510b978ee19619d2a1d959171419227f3914c687c05
|
|
| MD5 |
9a8f73d111e55e1a9b160808db862195
|
|
| BLAKE2b-256 |
735164a106d4b81265430f809bb067874451a73da8bd8d3737768f48256f9bef
|
File details
Details for the file breakword-0.3.1-py3-none-any.whl.
File metadata
- Download URL: breakword-0.3.1-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.0b3 CPython/3.8.5 Darwin/19.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10f9ee86617d3e07284babc04ef811ae4bf01708fc0c422fe7a5e967c8bc5c37
|
|
| MD5 |
4c7d8dc70f100ebbd49fe0f584243e00
|
|
| BLAKE2b-256 |
68bd00ddc1bca0ed8bc14e889a007a8a8bf1bcc9f547a0b026f3e14e1b3b4681
|