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
:straight (dape :type git :host github :repo "svaante/dape")
:config
(setq dape-repl-use-shorthand t)
(add-to-list 'dape-configs
`(debugpy
modes (python-ts-mode python-mode)
command "python3"
command-args ("-m" "debugpy.adapter")
:type "executable"
:request "launch"
:cwd dape-cwd-fn
:program dape-find-file-buffer-default))
(add-to-list 'dape-configs
'(streamlit
modes (python-ts-mode python-mode)
command "python3"
command-args ("-m" "debugpy.adapter")
:type "executable"
:request "launch"
:module "streamlit"
:cwd dape-cwd-fn
:args ["run" dape-find-file-buffer-default]
))
)Keybinds
I use the following keybinds using general for
debugging:
;; Debug map
(general-define-key
:keymaps 'my/debug-map
"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