Debug Python Streamlit app in Emacs
Intro
Streamlit is a way to
build data interfaces/applications in pure Python without the
need for frontend coding. So far I relied mostly on
st.write
and the reload facility of Streamlit to
debug my app. Yesterday I came across dape.el mode for
Emacs which allows you to use functionalities similar to dap-mode but
without a need to have LSP installed which I find very
interesting.
Configuration
One question and
a bit of configuration later, I am able to easily debug any
Python app including Streamlit application in Emacs thanks to
the dape.el
developer.
Here is the configuration I use:
use-package dape
(:type git :host github :repo "svaante/dape")
:straight (dape
:configsetq dape-repl-use-shorthand t)
('dape-configs
(add-to-list
`(debugpy
modes (python-ts-mode python-mode)"python3"
command "-m" "debugpy.adapter")
command-args (:type "executable"
"launch"
:request
:cwd dape-cwd-fn
:program dape-find-file-buffer-default))
'dape-configs
(add-to-list
'(streamlit
modes (python-ts-mode python-mode)"python3"
command "-m" "debugpy.adapter")
command-args (:type "executable"
"launch"
:request "streamlit"
:module
:cwd dape-cwd-fn"run" dape-find-file-buffer-default]
:args [
)) )
Keybinds
I use the following keybinds using general
for
debugging:
;; Debug map
(general-define-key'my/debug-map
:keymaps "s" #'dape
"n" #'dape-next
"i" #'dape-step-in
"o" #'dape-step-out
"c" #'dape-continue
"r" #'dape-restart
"b" #'dape-toggle-breakpoint
"d" #'dape-remove-breakpoint-at-point
"D" #'dape-remove-all-breakpoints
"l" #'dape-log-breakpoint
"q" #'dape-quit
"k" #'dape-kill)
my full configuration can be found in my dotemacs repository.
Screenshot
