Merge branch 'maint'

This commit is contained in:
Kyle Meyer 2017-12-19 00:00:49 -05:00
commit 06b49cd837
2 changed files with 43 additions and 10 deletions

View File

@ -239,6 +239,15 @@ def main():
open('%s', 'w').write( pprint.pformat(main()) )") open('%s', 'w').write( pprint.pformat(main()) )")
(defconst org-babel-python--exec-tmpfile
(concat
"__org_babel_python_fname = '%s'; "
"__org_babel_python_fh = open(__org_babel_python_fname); "
"exec(compile("
"__org_babel_python_fh.read(), __org_babel_python_fname, 'exec'"
")); "
"__org_babel_python_fh.close()"))
(defun org-babel-python-evaluate (defun org-babel-python-evaluate
(session body &optional result-type result-params preamble) (session body &optional result-type result-params preamble)
"Evaluate BODY as Python code." "Evaluate BODY as Python code."
@ -306,16 +315,23 @@ last statement in BODY, as elisp."
(results (results
(pcase result-type (pcase result-type
(`output (`output
(mapconcat (let ((body (if (string-match-p ".\n+." body) ; Multiline
#'org-trim (let ((tmp-src-file (org-babel-temp-file
(butlast "python-")))
(org-babel-comint-with-output (with-temp-file tmp-src-file (insert body))
(session org-babel-python-eoe-indicator t body) (format org-babel-python--exec-tmpfile
(funcall input-body body) tmp-src-file))
(funcall send-wait) (funcall send-wait) body)))
(insert org-babel-python-eoe-indicator) (mapconcat
(funcall send-wait)) #'org-trim
2) "\n")) (butlast
(org-babel-comint-with-output
(session org-babel-python-eoe-indicator t body)
(funcall input-body body)
(funcall send-wait) (funcall send-wait)
(insert org-babel-python-eoe-indicator)
(funcall send-wait))
2) "\n")))
(`value (`value
(let ((tmp-file (org-babel-temp-file "python-"))) (let ((tmp-file (org-babel-temp-file "python-")))
(org-babel-comint-with-output (org-babel-comint-with-output

View File

@ -101,6 +101,23 @@ return x
(should (equal '(("col") ("a") ("b")) (should (equal '(("col") ("a") ("b"))
(org-babel-execute-src-block))))) (org-babel-execute-src-block)))))
(ert-deftest test-ob-python/session-multiline ()
;; FIXME workaround to prevent starting prompt leaking into output
(run-python)
(sleep-for 0 10)
(org-test-with-temp-text "
#+begin_src python :session :results output
foo = 0
for _ in range(10):
foo += 1
foo += 1
print(foo)
#+end_src"
(org-babel-next-src-block)
(should (equal "20" (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