reddit / emacs

Tips and best practices for REPL-oriented python development?

suhrob · 2022-12-18 16:44
My python workflow is strongly REPL oriented, i.e. interactively sending lines (including indented sublines) or blocks and defuns to the interpreter (i.e. I can't just eval the whole buffer or just rely on running unit tests). I used to use `elpy` which covers many of these functions, but it is not really maintained and includes parts that would conflict with lsp etc. Any tips? I'm at the moment testing `doom-emacs` and it doesn't really seem to have anything specific for this workflow either. The tips don't necessarily have to be doom-emacs related.
jcmkk3 · 2022-12-18 17:25
Regular python-mode should have most of the functionality that you want. Start a repl by running `M-x run-python`, then you can send code to the running repl with one of the following commands: - `python-shell-send-file` - `python-shell-send-defun` - `python-shell-send-buffer` - `python-shell-send-string` - `python-shell-send-statement`
bagtowneast · 2022-12-19 01:00
I don't have anything to offer other than to agree that elpy seems to be fading, and is too inflexible for all the permutations of modern python environments. I'm on the cusp of ripping it out in favor of building a python env from smaller components. At least, that will help expose the magic and increase my own understanding of my python env. Ymmv.
jcmkk3 · 2022-12-19 01:11
I've never used elpy, so I can't compare for you, but I feel like it is pretty easy to get a comfortable environment with python-mode. Install a python language server and use eglot or lsp-mode. I believe that python-mode is one of the modes that will be getting tree sitter support in emacs 29, which should add some additional enhancements. The only additional python specific package that I use is [comint-mime](https://github.com/astoff/comint-mime), since I mostly do data/visualization work.
bagtowneast · 2022-12-19 02:06
Yep. The nice thing about elpy is you get all the tools in one package: linting, formatting, test discovery, etc. But I have trouble making it all work well with my most common environment of make driven, container based development across half a dozen permutations of (python version, 3rd party frameworks). It's my intention to go this way of using python-mode directly and then adding in the bits that I want, with the ability to fully customize each extension without the complications of doing it within elpy's world view. I just need the time to make the switch.
klikklakvege · 2022-12-19 07:05
I don't have a perfect solution, but You want tips, yes? There are at least 3 dialects of lisp that compile to python and can interact perfectly with python libraries. Lisps are by design repl oriented. Python not so, the repl experience is ofc much better then most other languages, but lisps are in a different league on another planet. People have optimized(in the sense of found the optimum) the lisp repl workflow already decades ago. Tools for Repl oriented in python are not so in demand, because if someone wants to do repl based development one goes for lisps and dumps python. This is one of the main reasons to use lisp after all. The best repl experience in python i found with prompttoolkit/ptpyhton. But this is not emacs related at all
kkvi115 · 2022-12-19 09:37
Wow the comint-mime package is very useful!!
suhrob · 2022-12-21 07:08
Thanks - didn't know about `comint-mime` and always missed this feature!