Open q1999 opened 4 years ago
If you are using IPython, you can use the %autoreload
magic. But as the IPython documentation say:
Reloading Python modules in a reliable way is in general difficult, and unexpected things may occur.
What I generally do is restarting the shell (C-c C-k
for elpy-shell-kill
then C-c C-c
).
If you do that very often, it may worth having a keybinding for it:
(defun elpy-shell-restart-and-send-region-or-buffer ()
"Send the region of buffer after restarting the shell."
(interactive)
(elpy-shell-kill t)
(elpy-shell-send-region-or-buffer))
(define-key elpy-mode-map (kbd "C-c C-a")
'elpy-shell-restart-and-send-region-or-buffer)
Or using importlib.autoreload
, when my script takes a bit of time running.
If you are using IPython, you can use the
%autoreload
magic. But as the IPython documentation say:Reloading Python modules in a reliable way is in general difficult, and unexpected things may occur.
What I generally do is restarting the shell (
C-c C-k
forelpy-shell-kill
thenC-c C-c
). If you do that very often, it may worth having a keybinding for it:(defun elpy-shell-restart-and-send-region-or-buffer () "Send the region of buffer after restarting the shell." (interactive) (elpy-shell-kill t) (elpy-shell-send-region-or-buffer)) (define-key elpy-mode-map (kbd "C-c C-a") 'elpy-shell-restart-and-send-region-or-buffer)
Or using
importlib.autoreload
, when my script takes a bit of time running.
thanks galaunay for your answer and input. Might not even rebinding C-c C-c to your restart function be an option, instead of binding it to C-c C-a? Not sure. C-c C-c is a key combination used by both python mode and elpy mode. Anyway, I will give your code a try.
If you don't use the default C-c C-c
, there is nothing preventing you from rebinding elpy-shell-restart-and-send-region-or-buffer
to C-c C-c
.
Summary
To make code changes take effect, I need to restart python every time. For which there doesn't seem to be a default key combination, but that is beside the point except for that I think it points to an action that should not be a much used part of a workflow. Am I doing something wrong or is this "works as intended"?
Steps to reproduce
1) open file a.py that imports file b.py from same directory (a calling function in b, for instance to print something). 2) Activate Virtual Env, or not, makes no difference 3) C-c C-c to send buffer to python (args being either -i or -i -B) 4) change some existing code in b.py (for instance some string to be printed) 5) C-c C-c will print previous string from b.py, not the new string. 6) only after restarting python will C-c C-c print the new string.
My configuration
GNU Emacs 25.1.1 (x86_64-w64-mingw32) of 2016-09-17
OS
Windows 7 Service Pack 1
Result of
(elpy-config)
Elpy configuration in my init.el