Show HN: Seapie – 一个 Python 调试器,断点会进入一个 REPL。
Show HN: Seapie – a Python debugger where breakpoints drop into a REPL

原始链接: https://github.com/hirsimaki-markus/seapie

## Seapie:以人为本的 Python 调试器 Seapie 是一款新的 Python 调试器,旨在易于使用和发现。它优先考虑自然的调试体验,力求“像你想象的那样工作”。与传统的调试器不同,Seapie 专注于 REPL 优先的方法,允许使用标准的 Python 语法(例如 `print(myvar)`,`myvar = None`)直接检查和修改变量。 主要功能包括有用的错误消息、可通过 `!help` 从任何地方访问的内置帮助,以及使用 Python 表达式定义调试条件的能力——例如,当函数返回 `None` 或特定函数在调用堆栈中时停止。 Seapie 可以与你的代码无缝集成;断点使用 `seapie.breakpoint()` 设置,调试直接在 Python shell 中进行。命令如 `!step`、`!traceback` 和 `!location` 提供控制,而调试器不会将你锁定在单独的模式中,允许灵活的探索并在任何时候恢复执行。

## Seapie:一个注重REPL的Python调试器 Markushirsimaki推出了Seapie,一个作为`pdb`替代方案的Python调试器。Seapie的核心功能不是基于命令的界面,而是在断点处通过`seapie.breakpoint()`进入一个完全功能的Python REPL。在REPL中进行的更改会持久保存,调试控制通过小型的`!commands`访问。 评论者指出`pdb`和`ipdb`已经提供了类似REPL的功能,但Seapie旨在实现更无缝的集成。然而,经验丰富的开发者指出,IDE已经提供了丰富的调试体验——显示变量和调用堆栈,而无需REPL命令,这是Seapie目前所缺乏的。 作者欢迎反馈,特别是来自重度调试器用户,建议潜在的改进,例如在断点命中时自动显示行/源代码以及变量预览。Seapie似乎对那些在CLI环境中工作且没有全功能IDE优势的人最有用。
相关文章

原文

1. Debugging for humans

seapie comes with a user experience focused on discoverability: helpful error messages and built-in help you can reach from anywhere

2. Debug by describing what you want

All debuggers let you step. seapie lets Python expressions walk without magic syntax: ”stop when myfunc returns None, and call stack contains myhelper”

>>> !walk (_event_ == "return") and (_return_ is None) and ("myhelper" in _callstack_)

3. REPL-first by design >>>

Checking a variable is print(myvar) changing it is myvar = None. Debugging !commands work in the REPL and inspecting state is just python:

>>> _magic_
{'_line_': 8,
 '_source_': '    return round(total_with_tax, 2)',
 '_path_': '/home/hirsimak/seapie/test/demo.py',
 '_return_': 35.64,
 '_exception_': None,
 '_event_': 'return',
 '_callstack_': ['<module>', 'checkout']}
>>>

myscript.py

print("script says hello!")
import seapie; seapie.breakpoint()  # execution pauses here, you get >>>
do_stuff(myvariable)

terminal

user@system:~/$ python myscript.py
script says hello!
🔗  Attaching seapie
seapie 4.0.0 (Python 3.13.3) [GCC 13.3.0] on linux
Type "!help" for seapie help
>>>

terminal

>>> print(locals())
{'x': 1, 'myvariable': None}
>>>
>>> myvariable = x
>>>
>>> _magic_.keys()
dict_keys(['_line_', '_source_', '_path_', '_return_', '_exception_', '_event_', '_callstack_'])
>>>
>>> _line_, _source_
(18, '    while True:')
>>>
>>> !bad-command
💀  Unknown command !bad-command
⚡ !command quicklist (example: >>> !location)
    !(h)elp           Show help
    !(l)ocation       Show source code around currently executing line
    !(t)raceback      Show callstack with current frame highlighted
    !(f)rame          Move up and down in callstack
    !(k)eep           Constantly show any Python expression at the top of the terminal
    !(s)tep           Step through code execution
    !(e)vent          Step until a specific event type
    !(u)ntil          Step until a target like linenumber or file
... ( cut for brevity in readme ) ...
>>>

Seapie doesn’t lock you into the prompt - you can step forward, jump around, or resume normal execution whenever you feel done exploring. If you’re ever curious what’s possible, !help is always there, inside the shell. (For the curious: a snapshot of the built-in help lives in help_dump.txt.)

Click to expand

seapie is short for 'Scope Escaping Arbitrary Python Injection Executor'.

If you need license other than Unlicense, contact me ɯoɔ˙lᴉɐɯƃ (ʇɐ) snʞɹɐɯ˙ᴉʞɐɯᴉsɹᴉɥ.

seapie$ pip install -e .

  • Remember: increment __version__ in __init__.py
  • Remember: .pypirc file is needed.
  • seapie$ python -m build --wheel
  • seapie$ rm -rf build/ && rm -rf src/seapie.egg-info/
  • seapie$ python -m twine check dist/*
  • seapie$ python -m twine upload dist/*
  • seapie$ rm -rf dist/
  • Seapie is essentially singleton; only one thread can be debugged at a time.
  • Remote debugging support could be added in the future. Python 3.14 looks promising.

Overall, pdb is ok but it felt rough for the novice I once was. pdb asks you to learn a small debugger language on top of Python and interaction with your code requires a separate 'mode'. In my opinion the correct specification for debugger user experience is that 'it works like i imagine it should work' and seapie tries to achieve that.

How to re-record the demo gif

  • add export PS1='$ ' to bashrc, comment out spam from neofetch and such
  • resize terminal to about 81x15 characters. Check with stty size.
  • $ cd seapie/test
  • $ clear
  • $ asciinema rec --quiet demo.cast
  • $ batcat buggy.py
  • $ python buggy.py
  • $ print(_source_)
  • $ items
  • $ items.remove("bad input value")
  • $ items
  • $ !continue
  • separate terminal: $ pkill -f asciinema
  • back in first terminal: ctrl+D
  • $ asciinema play demo.cast
  • $ asciinema-agg demo.cast demo.gif --font-family "DejaVu Sans Mono" --font-size 20
联系我们 contact @ memedata.com