ob-python: Fix async evaluation
* lisp/ob-python.el (org-babel-python-async-evaluate-session): Bind `python-shell-buffer-name' inside the temp buffer. * testing/lisp/test-ob-python.el (test-ob-python/async-local-python-shell): Add test.
This commit is contained in:
parent
c9b80f06d4
commit
5e31dcdd9a
|
@ -400,28 +400,31 @@ by `org-babel-comint-async-filter'."
|
||||||
session (current-buffer)
|
session (current-buffer)
|
||||||
"ob_comint_async_python_\\(.+\\)_\\(.+\\)"
|
"ob_comint_async_python_\\(.+\\)_\\(.+\\)"
|
||||||
'org-babel-chomp 'org-babel-python-async-value-callback)
|
'org-babel-chomp 'org-babel-python-async-value-callback)
|
||||||
(let ((python-shell-buffer-name (org-babel-python-without-earmuffs session)))
|
(pcase result-type
|
||||||
(pcase result-type
|
(`output
|
||||||
(`output
|
(let ((uuid (org-id-uuid)))
|
||||||
(let ((uuid (org-id-uuid)))
|
(with-temp-buffer
|
||||||
(with-temp-buffer
|
(insert (format org-babel-python-async-indicator "start" uuid))
|
||||||
(insert (format org-babel-python-async-indicator "start" uuid))
|
(insert "\n")
|
||||||
(insert "\n")
|
(insert body)
|
||||||
(insert body)
|
(insert "\n")
|
||||||
(insert "\n")
|
(insert (format org-babel-python-async-indicator "end" uuid))
|
||||||
(insert (format org-babel-python-async-indicator "end" uuid))
|
(let ((python-shell-buffer-name
|
||||||
(python-shell-send-buffer))
|
(org-babel-python-without-earmuffs session)))
|
||||||
uuid))
|
(python-shell-send-buffer)))
|
||||||
(`value
|
uuid))
|
||||||
(let ((tmp-results-file (org-babel-temp-file "python-"))
|
(`value
|
||||||
(tmp-src-file (org-babel-temp-file "python-")))
|
(let ((tmp-results-file (org-babel-temp-file "python-"))
|
||||||
(with-temp-file tmp-src-file (insert body))
|
(tmp-src-file (org-babel-temp-file "python-")))
|
||||||
(with-temp-buffer
|
(with-temp-file tmp-src-file (insert body))
|
||||||
(insert (org-babel-python-format-session-value tmp-src-file tmp-results-file result-params))
|
(with-temp-buffer
|
||||||
(insert "\n")
|
(insert (org-babel-python-format-session-value tmp-src-file tmp-results-file result-params))
|
||||||
(insert (format org-babel-python-async-indicator "file" tmp-results-file))
|
(insert "\n")
|
||||||
(python-shell-send-buffer))
|
(insert (format org-babel-python-async-indicator "file" tmp-results-file))
|
||||||
tmp-results-file)))))
|
(let ((python-shell-buffer-name
|
||||||
|
(org-babel-python-without-earmuffs session)))
|
||||||
|
(python-shell-send-buffer)))
|
||||||
|
tmp-results-file))))
|
||||||
|
|
||||||
(provide 'ob-python)
|
(provide 'ob-python)
|
||||||
|
|
||||||
|
|
|
@ -296,6 +296,20 @@ print(list(range(3)))
|
||||||
(string= (concat src-block result)
|
(string= (concat src-block result)
|
||||||
(buffer-string)))))))
|
(buffer-string)))))))
|
||||||
|
|
||||||
|
(ert-deftest test-ob-python/async-local-python-shell ()
|
||||||
|
;; Disable the test on older Emacs as built-in python.el sometimes
|
||||||
|
;; fail to initialize session.
|
||||||
|
(skip-unless (version<= "28" emacs-version))
|
||||||
|
(when-let ((buf (get-buffer "*Python*")))
|
||||||
|
(let (kill-buffer-query-functions)
|
||||||
|
(kill-buffer buf)))
|
||||||
|
(org-test-with-temp-text-in-file
|
||||||
|
"# -*- python-shell-buffer-name: \"Python 3\" -*-
|
||||||
|
<point>#+begin_src python :session \"*Python 3*\" :async yes
|
||||||
|
1
|
||||||
|
#+end_src"
|
||||||
|
(should (org-babel-execute-src-block))))
|
||||||
|
|
||||||
(provide 'test-ob-python)
|
(provide 'test-ob-python)
|
||||||
|
|
||||||
;;; test-ob-python.el ends here
|
;;; test-ob-python.el ends here
|
||||||
|
|
Loading…
Reference in New Issue