Use default-directory as :dir when executing a source block

`default-directory` is already set according to :dir when executing a
source block. This prevents `org-babel-expand-body:jupyter` from
attempting to re-expand the value of the :dir header argument.
See #302.
This commit is contained in:
Nathaniel Nicandro 2021-11-26 12:50:38 -06:00
parent db450a9f44
commit 113acb239d
2 changed files with 21 additions and 2 deletions

View file

@ -473,7 +473,15 @@ the PARAMS alist."
(jupyter-current-client (buffer-local-value 'jupyter-current-client buf))
(lang (jupyter-kernel-language jupyter-current-client))
(vars (org-babel-variable-assignments:jupyter params lang))
(code (org-babel-expand-body:jupyter body params vars lang)))
(code (progn
(when-let* ((dir (alist-get :dir params)))
;; `default-directory' is already set according
;; to :dir when executing a source block. Set
;; :dir to the absolute path so that
;; `org-babel-expand-body:jupyter' does not try
;; to re-expand the path. See #302.
(setf (alist-get :dir params) default-directory))
(org-babel-expand-body:jupyter body params vars lang))))
(pcase-let ((`(,req ,maybe-result)
(org-babel-jupyter--execute code async-p)))
;; KLUDGE: Remove the file result-parameter so that

View file

@ -2862,7 +2862,18 @@ os.path.abspath(os.getcwd())"
;; See #302
(jupyter-org-test-src-block
"print(r\"\\r\")"
": \\r\n")))))
": \\r\n")))
(ert-info ("Relative directory")
;; See #302
(let* ((temporary-file-directory jupyter-test-temporary-directory)
(dir (make-temp-file "dir-header-arg" t)))
;; FIXME: Don't use an internal function here.
(jupyter-org-test
(let ((default-directory (file-name-directory dir)))
(jupyter-org-test-src-block-1
"print(\"hi\")"
": hi\n" nil
`((:dir . ,(file-name-base dir))))))))))
(ert-deftest jupyter-org--find-mime-types ()
:tags '(org mime)