breakword


Namebreakword JSON
Version 0.3.2 PyPI version JSON
download
home_pageNone
SummaryMixing breakpoints with print debugging.
upload_time2024-09-12 19:40:49
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords breakpoint debug print
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# 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

1. Set the `PYTHONBREAKPOINT` environment variable to `breakword.breakpoint`.

2. Use `breakpoint` like a `print` statement:

```python
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
```

3. Use the `BREAKWORD` environment variable to set a breakpoint to what you want to investigate further. For instance, if you want to stop when `i == 6` in 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.

![demo](https://raw.githubusercontent.com/breuleux/breakword/master/media/demo.png)


## 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 after `log` printed out the given word. If `watch` is `None` or not given, the `BREAKWORD` environment variable is consulted. If the variable is not set, nothing will happen.
  * This is equivalent to `breakword.after(word).breakpoint()`.

* `breakword.after(watch=None, **config)`: Returns an object that evaluates to `True` right after `log` printed out the given watch word. As with `brk`, if `watch` is `None` or not given, the `BREAKWORD` environment variable is consulted.

* `breakword.word(**config)`: Returns the next word as a string. You can print it yourself, in which case it's basically like `log`, or you can store it in an object.

* `breakword.logbrk(**config)`: Calls `log` and then `brk`.

* `breakword.wordbrk(**config)`: Calls `word` and then `brk`. The word is returned.

* `breakword.set_default_logger(logger)`: Set the logging function to use (defaults to `print`)


## Tracking objects

* `breakword.track(obj, all=False)` will set the `breakword` attribute in the object to the next word in the list. By setting the `BREAKWORD` environment variable, you will set a breakpoint to the corresponding call to `track`. Set the `all` argument to `True` and the attribute will contain a list. Note: this will not work if `obj` is an integer or string, in those cases track will print a warning.

* `breakword.track_creation(*classes)` will set the `breakword` attribute 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[""]`.


```python
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")
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "breakword",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "breakpoint, debug, print",
    "author": null,
    "author_email": "Olivier Breuleux <breuleux@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/4f/05/68b629182345322908240eadfd0a5bd83dc306b9e2a8f568983dfbf2bb7d/breakword-0.3.2.tar.gz",
    "platform": null,
    "description": "\n# breakword\n\n`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.\n\n`breakword` normally requires running your program twice and will only work properly if it is deterministic.\n\n\n## How to use\n\n1. Set the `PYTHONBREAKPOINT` environment variable to `breakword.breakpoint`.\n\n2. Use `breakpoint` like a `print` statement:\n\n```python\nfor i in range(10):\n    breakpoint(i)\n```\n\nThis will print out something like this:\n\n```\n$ python example.py\n\u23ce standard 0\n\u23ce sound 1\n\u23ce character 2\n\u23ce thank 3\n\u23ce play 4\n\u23ce however 5\n\u23ce fish 6\n\u23ce cultural 7\n\u23ce either 8\n\u23ce and 9\n```\n\n3. Use the `BREAKWORD` environment variable to set a breakpoint to what you want to investigate further. For instance, if you want to stop when `i == 6` in the above program, you can run the following command:\n\n\n```\n$ env BREAKWORD=fish python example.py\n\u23ce standard 0\n\u23ce sound 1\n\u23ce character 2\n\u23ce thank 3\n\u23ce play 4\n\u23ce however 5\n\u23ce fish 6\n> example.py(2)<module>()\n-> for i in range(10):\n(Pdb) i\n6\n```\n\nYou can also give a comma-separated list of words, e.g. `BREAKWORD=sound,fish`.\n\n**Note:** `breakpoint()` with no arguments retains the normal behavior.\n\n![demo](https://raw.githubusercontent.com/breuleux/breakword/master/media/demo.png)\n\n\n## More functions\n\n* `breakword.log(*things, **config)`: Print a word and optionally other things after it.\n\n* `breakword.brk(watch=None, **config)`: Sets a breakpoint to trigger after `log` printed out the given word. If `watch` is `None` or not given, the `BREAKWORD` environment variable is consulted. If the variable is not set, nothing will happen.\n  * This is equivalent to `breakword.after(word).breakpoint()`.\n\n* `breakword.after(watch=None, **config)`: Returns an object that evaluates to `True` right after `log` printed out the given watch word. As with `brk`, if `watch` is `None` or not given, the `BREAKWORD` environment variable is consulted.\n\n* `breakword.word(**config)`: Returns the next word as a string. You can print it yourself, in which case it's basically like `log`, or you can store it in an object.\n\n* `breakword.logbrk(**config)`: Calls `log` and then `brk`.\n\n* `breakword.wordbrk(**config)`: Calls `word` and then `brk`. The word is returned.\n\n* `breakword.set_default_logger(logger)`: Set the logging function to use (defaults to `print`)\n\n\n## Tracking objects\n\n* `breakword.track(obj, all=False)` will set the `breakword` attribute in the object to the next word in the list. By setting the `BREAKWORD` environment variable, you will set a breakpoint to the corresponding call to `track`. Set the `all` argument to `True` and the attribute will contain a list. Note: this will not work if `obj` is an integer or string, in those cases track will print a warning.\n\n* `breakword.track_creation(*classes)` will set the `breakword` attribute 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.\n\n\n## Groups\n\nUse `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[\"\"]`.\n\n\n```python\nfrom breakword import groups\n\nassert groups.aardvark == groups[\"aardvark\"]\n\n# Log \"a\" in the aardvark group\ngroups.aardvark.log(\"a\")\n\n# Log \"b\" in the pelican group\ngroups.pelican.log(\"b\")\n\n# Get the next word in the pelican group\nword = groups.pelican.word()\n\n# Conditional behavior to perform only after the word \"cherry\"\nif groups.pelican.after(\"cherry\"):\n    print(\"blah\")\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Mixing breakpoints with print debugging.",
    "version": "0.3.2",
    "project_urls": {
        "Homepage": "https://github.com/breuleux/breakword",
        "Repository": "https://github.com/breuleux/breakword"
    },
    "split_keywords": [
        "breakpoint",
        " debug",
        " print"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3a9e1350806e403a60373c442d1e32a77688a563817097e6aeda16f3d3b5112d",
                "md5": "d9001c0334e4a87986bb07922d19279b",
                "sha256": "fa6431e68be3fc6e668f288341dc81b804c14ca3a70c7a0c9bb487310c177ad3"
            },
            "downloads": -1,
            "filename": "breakword-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d9001c0334e4a87986bb07922d19279b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10232,
            "upload_time": "2024-09-12T19:40:51",
            "upload_time_iso_8601": "2024-09-12T19:40:51.568070Z",
            "url": "https://files.pythonhosted.org/packages/3a/9e/1350806e403a60373c442d1e32a77688a563817097e6aeda16f3d3b5112d/breakword-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4f0568b629182345322908240eadfd0a5bd83dc306b9e2a8f568983dfbf2bb7d",
                "md5": "22a06cd43cd716759385ceab81b0bbfa",
                "sha256": "38404e7189d8bfe5a910c31333671b171dc49c95a9b139d62a9feaf72df20b5a"
            },
            "downloads": -1,
            "filename": "breakword-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "22a06cd43cd716759385ceab81b0bbfa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 532606,
            "upload_time": "2024-09-12T19:40:49",
            "upload_time_iso_8601": "2024-09-12T19:40:49.741994Z",
            "url": "https://files.pythonhosted.org/packages/4f/05/68b629182345322908240eadfd0a5bd83dc306b9e2a8f568983dfbf2bb7d/breakword-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-12 19:40:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "breuleux",
    "github_project": "breakword",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "breakword"
}
        
Elapsed time: 0.35678s